blob: 4cd8dd758c39f07a902ee29f15616c725479e193 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
using System.Collections;
using UnityEngine;
public class ScaleAnimation : OneShotAnimationBase
{
public AnimationCurve curve;
public float duration = 0.75f;
public float targetScale;
public Transform transformToAnimate;
private float initialScale = 1f;
private void Start()
{
initialScale = transformToAnimate.localScale.x;
}
private IEnumerator Animate()
{
transformToAnimate.localScale = Vector3.one * initialScale;
float timer = 0f;
while (timer < duration)
{
transformToAnimate.localScale = Vector3.one * Mathf.Lerp(initialScale, targetScale, curve.Evaluate(timer / duration));
timer += Time.deltaTime;
yield return null;
}
transformToAnimate.localScale = Vector3.one * Mathf.Lerp(initialScale, targetScale, curve.Evaluate(timer / duration));
}
public override void Trigger()
{
if (base.gameObject.activeInHierarchy)
{
StopAllCoroutines();
StartCoroutine(Animate());
}
}
}
|