diff --git a/popcorn/Assets/MyGame/Scenes/Cooking/Scripts/CornHarvester.cs.meta b/popcorn/Assets/MyGame/Scenes/Cooking/Scripts/CornHarvester.cs.meta deleted file mode 100644 index a0f835df..00000000 --- a/popcorn/Assets/MyGame/Scenes/Cooking/Scripts/CornHarvester.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 126d56890a16475f8bb5bf49970a50c8 -timeCreated: 1626851012 \ No newline at end of file diff --git a/popcorn/Assets/MyGame/Scenes/Cooking/Scripts/CornHarvester.cs b/popcorn/Assets/MyGame/Scenes/CornField/Scripts/CornHarvester.cs similarity index 63% rename from popcorn/Assets/MyGame/Scenes/Cooking/Scripts/CornHarvester.cs rename to popcorn/Assets/MyGame/Scenes/CornField/Scripts/CornHarvester.cs index 03b99862..c5d55db2 100644 --- a/popcorn/Assets/MyGame/Scenes/Cooking/Scripts/CornHarvester.cs +++ b/popcorn/Assets/MyGame/Scenes/CornField/Scripts/CornHarvester.cs @@ -1,13 +1,16 @@ using System; +using System.Collections; using System.Linq; using TMPro; using UniRx; using UnityEngine; +using Random = UnityEngine.Random; public class CornHarvester : MonoBehaviour { [SerializeField] private TextMeshPro cornCounter; [SerializeField] private GameObject harvestedPrefab; + [SerializeField] private float thrust = 100f; private float duration = .5f; private string counterFormat = "{0}"; private Coroutine animationCoroutine; @@ -25,14 +28,20 @@ public class CornHarvester : MonoBehaviour cornCounter.text = string.Format(counterFormat, (int)Mathf.Lerp(x.Previous, x.Current, lerp)); }); - for (int i = 0; i < x.Current; i++) - { - var corn = Instantiate(harvestedPrefab, cornCounter.transform.position, Quaternion.identity); - corn.GetComponent().AddForce(Vector2.down * 20f, ForceMode2D.Impulse); - } + StartCoroutine(Harvested(x.Current - x.Previous)); }).AddTo(this); } + private IEnumerator Harvested(int cnt) + { + for (int i = 0; i < cnt; i++) + { + var corn = Instantiate(harvestedPrefab, cornCounter.transform.position, Quaternion.identity); + corn.GetComponent().AddForce(new Vector2(Random.Range(-0.3f, 0.3f), -1).normalized * thrust, ForceMode2D.Impulse); + yield return null; + } + } + public void AddCount(int value) { count.Value += value; diff --git a/popcorn/Assets/MyGame/Scenes/CornField/Scripts/CornHarvester.cs.meta b/popcorn/Assets/MyGame/Scenes/CornField/Scripts/CornHarvester.cs.meta new file mode 100644 index 00000000..52883a1b --- /dev/null +++ b/popcorn/Assets/MyGame/Scenes/CornField/Scripts/CornHarvester.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 126d56890a16475f8bb5bf49970a50c8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: