Animation Events | Event Functions | Animator Events | C# | Unity Game Engine


AnimationEventsDemo.cs
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
43
44
45
using UnityEngine;
 
public class AnimationEventsDemo : MonoBehaviour
{
    //no parameter
    public void TriggerEvent()
    {
        Debug.Log("event triggered");
    }
 
    //float parameter
    public void ScaleDownEvent(float scale)
    {
        transform.localScale = new Vector3(scale, scale, scale);
    }
 
    //int parameter
    public void ScaleUpEvent(int scale)
    {
        transform.localScale = new Vector3(scale, scale, scale);
    }
 
    //string parameter
    public void PrintLogEvent(string str)
    {
        Debug.Log(str);
    }
 
    //Object parameter
    public void SpawnObjectEvent(Object gameObject)
    {
        if (gameObject != null)
            Instantiate(gameObject);
    }
 
    //multiple parameters(float,int,string,object)
    public void MultiParamEvent(AnimationEvent e)
    {
        Debug.Log(e.floatParameter + "," + e.intParameter + "," + e.stringParameter);
        if (e.objectReferenceParameter != null)
        {
            Instantiate(e.objectReferenceParameter);
        }
    }
}