コーン吐き出し処理を追加

This commit is contained in:
kimura 2021-07-27 10:57:24 +09:00
parent 51a2b9aec0
commit b27b0337df
3 changed files with 25 additions and 8 deletions

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 126d56890a16475f8bb5bf49970a50c8
timeCreated: 1626851012

View File

@ -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<Rigidbody2D>().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<Rigidbody2D>().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;

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 126d56890a16475f8bb5bf49970a50c8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: