From 665351514ba4fd1a45deb9a692f3323e26ef9656 Mon Sep 17 00:00:00 2001 From: kimura Date: Thu, 24 Jun 2021 12:32:59 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=B3=E3=83=BC=E3=83=B3=E6=8C=99=E5=8B=95?= =?UTF-8?q?=E7=84=A6=E3=81=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- popcorn/Assets/MyGame/Scenes/Main/Corn.cs | 34 ++++++++++++++++------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/popcorn/Assets/MyGame/Scenes/Main/Corn.cs b/popcorn/Assets/MyGame/Scenes/Main/Corn.cs index d483b5ba..d5fbccbe 100644 --- a/popcorn/Assets/MyGame/Scenes/Main/Corn.cs +++ b/popcorn/Assets/MyGame/Scenes/Main/Corn.cs @@ -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(); - // GetComponent().sprite = cornSeedSprite; + GetComponent().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().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);