コーン吐き出し処理を追加
This commit is contained in:
parent
51a2b9aec0
commit
b27b0337df
|
|
@ -1,3 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 126d56890a16475f8bb5bf49970a50c8
|
|
||||||
timeCreated: 1626851012
|
|
||||||
|
|
@ -1,13 +1,16 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using TMPro;
|
using TMPro;
|
||||||
using UniRx;
|
using UniRx;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using Random = UnityEngine.Random;
|
||||||
|
|
||||||
public class CornHarvester : MonoBehaviour
|
public class CornHarvester : MonoBehaviour
|
||||||
{
|
{
|
||||||
[SerializeField] private TextMeshPro cornCounter;
|
[SerializeField] private TextMeshPro cornCounter;
|
||||||
[SerializeField] private GameObject harvestedPrefab;
|
[SerializeField] private GameObject harvestedPrefab;
|
||||||
|
[SerializeField] private float thrust = 100f;
|
||||||
private float duration = .5f;
|
private float duration = .5f;
|
||||||
private string counterFormat = "{0}";
|
private string counterFormat = "{0}";
|
||||||
private Coroutine animationCoroutine;
|
private Coroutine animationCoroutine;
|
||||||
|
|
@ -25,14 +28,20 @@ public class CornHarvester : MonoBehaviour
|
||||||
cornCounter.text = string.Format(counterFormat, (int)Mathf.Lerp(x.Previous, x.Current, lerp));
|
cornCounter.text = string.Format(counterFormat, (int)Mathf.Lerp(x.Previous, x.Current, lerp));
|
||||||
});
|
});
|
||||||
|
|
||||||
for (int i = 0; i < x.Current; i++)
|
StartCoroutine(Harvested(x.Current - x.Previous));
|
||||||
{
|
|
||||||
var corn = Instantiate(harvestedPrefab, cornCounter.transform.position, Quaternion.identity);
|
|
||||||
corn.GetComponent<Rigidbody2D>().AddForce(Vector2.down * 20f, ForceMode2D.Impulse);
|
|
||||||
}
|
|
||||||
}).AddTo(this);
|
}).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)
|
public void AddCount(int value)
|
||||||
{
|
{
|
||||||
count.Value += value;
|
count.Value += value;
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 126d56890a16475f8bb5bf49970a50c8
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Loading…
Reference in New Issue