コーン挙動焦げ追加
This commit is contained in:
parent
7f5087f462
commit
665351514b
|
|
@ -17,37 +17,51 @@ public class Corn : MonoBehaviour
|
|||
// コーン弾ける時間!
|
||||
private float cornPopTime;
|
||||
// コーンが停まってる時間(焦げる判定
|
||||
private float cornStopTime;
|
||||
private float maxCornStopTime = 5f;
|
||||
// コーンが動いている総時間
|
||||
|
||||
private float cornMovingTime => cornLifeTime - cornStopTime;
|
||||
// コーン誕生時間
|
||||
private float cornSpawnTime;
|
||||
private bool isPop;
|
||||
|
||||
// Start is called before the first frame update
|
||||
|
||||
private Rigidbody2D rigidbody2D;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
rigidbody2D = GetComponent<Rigidbody2D>();
|
||||
// GetComponent<SpriteRenderer>().sprite = cornSeedSprite;
|
||||
GetComponent<SpriteRenderer>().sprite = cornSeedSprite;
|
||||
cornSpawnTime = Time.time;
|
||||
var cornPopBasicTime = 5f;
|
||||
cornPopTime = cornPopBasicTime + Random.Range(0, 5f);
|
||||
rigidbody2D.position = new Vector2(0f, Random.value);
|
||||
|
||||
rigidbody2D.position = new Vector2(Random.value, Random.value);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
cornVelocity = rigidbody2D.velocity.magnitude;
|
||||
cornLifeTime = Time.time - cornSpawnTime;
|
||||
// if (!isPop && cornLifeTime >= cornPopTime)
|
||||
// {
|
||||
// CornPop();
|
||||
// isPop = true;
|
||||
// }
|
||||
if (cornVelocity <= 0.2f)
|
||||
{
|
||||
cornStopTime += Time.deltaTime;
|
||||
}
|
||||
|
||||
if (cornStopTime >= maxCornStopTime && isPop)
|
||||
{
|
||||
GetComponent<SpriteRenderer>().sprite = cornBurntSprite;
|
||||
}
|
||||
if (cornLifeTime >= cornPopTime)
|
||||
{
|
||||
CornPop();
|
||||
}
|
||||
}
|
||||
|
||||
private void CornPop()
|
||||
{
|
||||
if (isPop) return;
|
||||
isPop = true;
|
||||
var popVelocity = 20f;
|
||||
var popDirection = new Vector2(Random.value * 2 - 1, Random.value * 2 - 1);
|
||||
rigidbody2D.AddForce(popVelocity * popDirection, ForceMode2D.Impulse);
|
||||
|
|
|
|||
Loading…
Reference in New Issue