59 lines
1.4 KiB
C#
59 lines
1.4 KiB
C#
using System.Collections;
|
|
using UnityEngine;
|
|
|
|
namespace Gaia
|
|
{
|
|
public class Growth : MonoBehaviour
|
|
{
|
|
[Range(0.1f, 2f)]
|
|
[Tooltip("The start size in the game.")]
|
|
public float m_startScale = 0.15f;
|
|
|
|
[Range(0.1f, 2f)]
|
|
[Tooltip("The end size in the game.")]
|
|
public float m_endScale = 1f;
|
|
|
|
[Range(0f, 2f)]
|
|
[Tooltip("Scale variance. Final scale is equal to end scale plus a a random value between 0 and this.")]
|
|
public float m_scaleVariance = 0.25f;
|
|
|
|
[Range(0.5f, 60f)]
|
|
[Tooltip("The time it takes to grow in seconds.")]
|
|
public float m_growthTime = 5f;
|
|
|
|
private float m_actualEndScale;
|
|
|
|
private void Start()
|
|
{
|
|
Initialise();
|
|
}
|
|
|
|
public virtual void Initialise()
|
|
{
|
|
m_actualEndScale = m_endScale + Random.Range(0f, m_scaleVariance);
|
|
StartCoroutine(Grow());
|
|
}
|
|
|
|
private IEnumerator Grow()
|
|
{
|
|
float realtimeSinceStartup = Time.realtimeSinceStartup;
|
|
float num = realtimeSinceStartup;
|
|
float deltaScale = m_actualEndScale - m_startScale;
|
|
float finishTime = realtimeSinceStartup + m_growthTime;
|
|
while (num < finishTime)
|
|
{
|
|
float num2 = 1f - (finishTime - num) / m_growthTime;
|
|
num2 = m_startScale + num2 * deltaScale;
|
|
base.gameObject.transform.localScale = Vector3.one * num2;
|
|
yield return null;
|
|
num = Time.realtimeSinceStartup;
|
|
}
|
|
}
|
|
|
|
public virtual void Die()
|
|
{
|
|
Object.Destroy(base.gameObject, 5f);
|
|
}
|
|
}
|
|
}
|