From ba55d302750dd776e834d9609c6bc603bb2c5d37 Mon Sep 17 00:00:00 2001 From: kimura Date: Tue, 20 Jul 2021 17:08:54 +0900 Subject: [PATCH] =?UTF-8?q?=E9=A3=9B=E3=81=B3=E5=87=BA=E3=81=97=E8=AA=BF?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MyGame/Scenes/Cooking/Scripts/Corn.cs | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/popcorn/Assets/MyGame/Scenes/Cooking/Scripts/Corn.cs b/popcorn/Assets/MyGame/Scenes/Cooking/Scripts/Corn.cs index a1c879a4..4d47ba60 100644 --- a/popcorn/Assets/MyGame/Scenes/Cooking/Scripts/Corn.cs +++ b/popcorn/Assets/MyGame/Scenes/Cooking/Scripts/Corn.cs @@ -55,18 +55,25 @@ public class Corn : MonoBehaviour private void Start() { - rigidbody.MovePosition(new Vector2(Random.value * 2 - 1, Random.value * 2 - 1)); - rigidbody.SetRotation(Random.value * 360); + rigidbody.MovePosition(Random.insideUnitCircle); + rigidbody.SetRotation(Random.rotation); cornSkin.ChangeSkin(condition.Value); // コーン飛び出し演出 this.ObserveEveryValueChanged(x => x.rigidbody.velocity.magnitude) .Where(x => x >= cornSpillSpeed) + .ThrottleFirstFrame(30) // 30フレーム間隔開ける + .Select(_ => Random.value < .2f) // 演出を出す確率 .FirstOrDefault() .Subscribe(_ => { spilled.Value = true; - CornSpilled(); + var clone = Instantiate(cornSkin); + clone.ChangeSkin(condition.Value); + var cloneRigidBody = clone.gameObject.AddComponent(); + cloneRigidBody.gravityScale = 0; + cloneRigidBody.AddForce(rigidbody.velocity.normalized * 20f, ForceMode2D.Impulse); + this.CallWaitForSeconds(2f, () => Destroy(clone.gameObject)); }).AddTo(this); condition.Pairwise().Subscribe(x => @@ -111,7 +118,7 @@ public class Corn : MonoBehaviour private void CornPop() { cornSkin.ChangeSkin(condition.Value); - rigidbody.AddForce(cornPopSpeed * new Vector2(Random.value * 2 - 1, Random.value * 2 - 1), ForceMode2D.Impulse); + rigidbody.AddForce(cornPopSpeed * Random.insideUnitCircle, ForceMode2D.Impulse); animator.SetTrigger(HashCornGrow); VibrationManager.Instance.PlayVibrationOnce(); } @@ -124,16 +131,6 @@ public class Corn : MonoBehaviour this.CallWaitForSeconds(.8f, () => Destroy(effect)); } - private void CornSpilled() - { - var clone = Instantiate(cornSkin); - clone.ChangeSkin(condition.Value); - var cloneRigidBody = clone.gameObject.AddComponent(); - cloneRigidBody.gravityScale = 0; - cloneRigidBody.AddForce(rigidbody.velocity.normalized * cornSpillSpeed, ForceMode2D.Impulse); - this.CallWaitForSeconds(2f, () => Destroy(clone.gameObject)); - } - public void SetCornProperty(float popTime, float burntDuration, float spillSpeed, float popSpeed) { cornPopTime = popTime;