using System.Collections;
using UnityEngine;
public class ScaleAnimationController : MonoBehaviour
{
public Vector3 targetScale = new Vector3(2f, 2f, 2f);
public float animationDuration = 1f;
private Vector3 initialScale;
private void Start()
{
initialScale = transform.localScale;
}
public void StartScaleInAnimation()
{
StartCoroutine(ScaleInAnimation());
}
public void StartScaleOutAnimation()
{
StartCoroutine(ScaleOutAnimation());
}
private IEnumerator ScaleInAnimation()
{
float timer = 0f;
while (timer < animationDuration)
{
timer += Time.deltaTime;
float progress = Mathf.Clamp01(timer / animationDuration);
transform.localScale = Vector3.Lerp(initialScale, targetScale, progress);
yield return null;
}
}
private IEnumerator ScaleOutAnimation()
{
float timer = 0f;
Vector3 targetScale = transform.localScale;
while (timer < animationDuration)
{
timer += Time.deltaTime;
float progress = Mathf.Clamp01(timer / animationDuration);
transform.localScale = Vector3.Lerp(targetScale, initialScale, progress);
yield return null;
}
}
}