corn sprite設定
This commit is contained in:
parent
a1c12b6e33
commit
b6dec2d6a3
|
|
@ -7,8 +7,9 @@ using Random = UnityEngine.Random;
|
||||||
[RequireComponent(typeof(Rigidbody2D))]
|
[RequireComponent(typeof(Rigidbody2D))]
|
||||||
public class Corn : MonoBehaviour
|
public class Corn : MonoBehaviour
|
||||||
{
|
{
|
||||||
// [SerializeField] private List<Sprite> cornSprites;
|
[SerializeField] private Sprite cornSeedSprite;
|
||||||
[SerializeField] private Sprite cornSimpleSprite;
|
[SerializeField] private Sprite cornSimpleSprite;
|
||||||
|
[SerializeField] private Sprite cornBurntSprite;
|
||||||
// コーン速度
|
// コーン速度
|
||||||
[SerializeField] private float cornVelocity;
|
[SerializeField] private float cornVelocity;
|
||||||
// コーンがスポーンしてからの時間
|
// コーンがスポーンしてからの時間
|
||||||
|
|
@ -27,27 +28,28 @@ public class Corn : MonoBehaviour
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
rigidbody2D = GetComponent<Rigidbody2D>();
|
rigidbody2D = GetComponent<Rigidbody2D>();
|
||||||
|
// GetComponent<SpriteRenderer>().sprite = cornSeedSprite;
|
||||||
cornSpawnTime = Time.time;
|
cornSpawnTime = Time.time;
|
||||||
var cornPopBasicTime = 5f;
|
var cornPopBasicTime = 5f;
|
||||||
cornPopTime = cornPopBasicTime + Random.Range(0, 5f);
|
cornPopTime = cornPopBasicTime + Random.Range(0, 5f);
|
||||||
|
rigidbody2D.position = new Vector2(0f, Random.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
cornVelocity = rigidbody2D.velocity.magnitude;
|
cornVelocity = rigidbody2D.velocity.magnitude;
|
||||||
cornLifeTime = Time.time - cornSpawnTime;
|
cornLifeTime = Time.time - cornSpawnTime;
|
||||||
if (!isPop && cornLifeTime >= cornPopTime)
|
// if (!isPop && cornLifeTime >= cornPopTime)
|
||||||
{
|
// {
|
||||||
CornPop();
|
// CornPop();
|
||||||
isPop = true;
|
// isPop = true;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CornPop()
|
private void CornPop()
|
||||||
{
|
{
|
||||||
var popVelocity = 20f;
|
var popVelocity = 20f;
|
||||||
var popDirection = new Vector2(Random.value * 2 - 1, Random.value * 2 - 1);
|
var popDirection = new Vector2(Random.value * 2 - 1, Random.value * 2 - 1);
|
||||||
Debug.Log(popDirection);
|
|
||||||
rigidbody2D.AddForce(popVelocity * popDirection, ForceMode2D.Impulse);
|
rigidbody2D.AddForce(popVelocity * popDirection, ForceMode2D.Impulse);
|
||||||
GetComponent<SpriteRenderer>().sprite = cornSimpleSprite;
|
GetComponent<SpriteRenderer>().sprite = cornSimpleSprite;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,9 @@ MonoBehaviour:
|
||||||
m_Script: {fileID: 11500000, guid: 175dce409df2f4d3aa1941a08822e03e, type: 3}
|
m_Script: {fileID: 11500000, guid: 175dce409df2f4d3aa1941a08822e03e, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
cornSimpleSprite: {fileID: 21300000, guid: 97ac0328246620745b8881e07f709ce7, type: 3}
|
cornSeedSprite: {fileID: 21300000, guid: 97ac0328246620745b8881e07f709ce7, type: 3}
|
||||||
|
cornSimpleSprite: {fileID: 21300000, guid: 041ad2539ff56d945ab2da4be6a02f04, type: 3}
|
||||||
|
cornBurntSprite: {fileID: 21300000, guid: a9d669186411b2b4da1511f59a91b4c9, type: 3}
|
||||||
cornVelocity: 0
|
cornVelocity: 0
|
||||||
cornLifeTime: 0
|
cornLifeTime: 0
|
||||||
--- !u!212 &1324329073609281163
|
--- !u!212 &1324329073609281163
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue