diff --git a/popcorn/Assets/MyGame/Scenes/Cooking/Cooking.unity b/popcorn/Assets/MyGame/Scenes/Cooking/Cooking.unity index 501eb75c..d81e466b 100644 --- a/popcorn/Assets/MyGame/Scenes/Cooking/Cooking.unity +++ b/popcorn/Assets/MyGame/Scenes/Cooking/Cooking.unity @@ -2720,7 +2720,7 @@ GameObject: m_Component: - component: {fileID: 1448897407} m_Layer: 0 - m_Name: ' cooking' + m_Name: cooking m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 diff --git a/popcorn/Assets/MyGame/Scenes/Cooking/Scripts/Corn.cs b/popcorn/Assets/MyGame/Scenes/Cooking/Scripts/Corn.cs index d2b3c0fb..a32a0a74 100644 --- a/popcorn/Assets/MyGame/Scenes/Cooking/Scripts/Corn.cs +++ b/popcorn/Assets/MyGame/Scenes/Cooking/Scripts/Corn.cs @@ -35,6 +35,8 @@ public class Corn : MonoBehaviour private float cornGrowSpeed; private float cornSpillSpeed; private float cornPopSpeed; + + private float worldWidth; public IReadOnlyReactiveProperty Condition => condition; private readonly ReactiveProperty condition = new ReactiveProperty(CornCondition.Seed); @@ -52,6 +54,9 @@ public class Corn : MonoBehaviour spriteTransform = spriteRenderer.transform; rotationResolverTransform = spriteTransform.parent.parent; + + var rightTop = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height, 0)); + worldWidth = rightTop.x; } private void Start() @@ -67,9 +72,9 @@ public class Corn : MonoBehaviour condition.Value = CornCondition.Spilled; }).AddTo(this); - condition.Subscribe(x => + condition.Pairwise().Subscribe(x => { - switch (x) + switch (x.Current) { case CornCondition.Seed: break; @@ -80,7 +85,7 @@ public class Corn : MonoBehaviour CornBurnt(); break; case CornCondition.Spilled: - CornSpilled(); + CornSpilled(x.Previous); break; default: throw new ArgumentOutOfRangeException(nameof(x), x, null); @@ -129,9 +134,36 @@ public class Corn : MonoBehaviour Instantiate(effectBurnt, transform); } - private void CornSpilled() + private void CornSpilled(CornCondition prevCondition) { GetComponent().enabled = false; + // フライパンに追従しないようにparent解除 + transform.parent = null; + + Observable.Timer(TimeSpan.FromSeconds(Random.Range(.5f, .9f))).Subscribe(_ => + { + Destroy(gameObject); + switch (prevCondition) + { + case CornCondition.Seed: + VibrationManager.Instance.PlayVibrationOnce(); + break; + case CornCondition.Simple: + case CornCondition.Burnt: + // 画面KO再生(同時飛び出し時ランダム) + var animation = Instantiate(spilledCornAnimationPrefab, new Vector2(Random.value * worldWidth * 2 - worldWidth, Random.value * 2 * 2 - 2), Quaternion.identity); + VibrationManager.Instance.PlayVibrationOnce(); + Observable.Timer(TimeSpan.FromSeconds(1.5f)).Subscribe(__ => + { + Destroy(animation); + }); + break; + case CornCondition.Spilled: + break; + default: + throw new ArgumentOutOfRangeException(nameof(prevCondition), prevCondition, null); + } + }).AddTo(this); } public void SetCornProperty(float popTime, float burntDuration, float spillSpeed, float popSpeed)