다수의 움직이는 부분이 있는 오브젝트
애니메이터 컨트롤러

Using Animation Events

세부 정보

The power of animation clips can be increased by using Animation Events, which allow you to call functions in the object’s script at specified points in the timeline.

The function called by an animation event can optionally take one parameter. The parameter can be a float, string, int, object reference or an AnimationEvent object. The AnimationEvent object has member variables that allow a float, string, integer and object reference to be passed into the function all at once, along with other information about the event that triggered the function call.

// This C# function can be called by an Animation Event
public void PrintFloat (float theValue) {
    Debug.Log ("PrintFloat is called with a value of " + theValue);
}


You can add an animation event to a clip at the current playhead position by clicking the Event button or at any point in the animation by double-clicking the Event Line at the point where you want the event to be triggered. Once added, an event can be repositioned by dragging with the mouse. You can delete an event by selecting it and pressing Delete, or by right-clicking on it and selecting Delete Event from the contextual menu.

Event Line__에 Animation Events__가 표시됩니다. Event Line__을 더블 클릭하거나 Event 버튼__으로 새로운 __Animation Event__를 추가합니다.
Event Line__에 Animation Events__가 표시됩니다. Event Line__을 더블 클릭하거나 Event 버튼__으로 새로운 __Animation Event__를 추가합니다.

When you add an event, a dialog box will appear to prompt you for the name of the function and the value of the parameter you want to pass to it.

The Animation Event popup dialog lets you specify which function to call with which parameter value.
The Animation Event popup dialog lets you specify which function to call with which parameter value.

The events added to a clip are shown as markers in the event line. Holding the mouse over a marker will show a tooltip with the function name and parameter value.

Holding the mouse cursor over an Animation Event marker will show which function it calls as well as the parameter value.
Holding the mouse cursor over an Animation Event marker will show which function it calls as well as the parameter value.

예제

This example is very simple. Add a small script with just a simple function, PrintEvent(), that prints a debug message including a string and the time:

// This C# function can be called by an Animation Event
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    public void PrintEvent(string s) {
        Debug.Log("PrintEvent: " + s + " called at: " + Time.time);
    }
}

In Unity create a Cube object and add the ExampleClass script code. Select the cube and then open the Animation window. Set a Position curve for the x coordinate.

애니메이션 창
애니메이션 창

Next set the animation for the x coordinate to increase to around 0.4 and back to zero over 1 second. Next create an animation event at approximately 0.8 seconds. Press the Play button and the cube animates forwards and backwards along the x-axis. The event message is displayed in the console every 1 second at the 0.8 second time. This example shows a simple way to add animation events to a simple GameObject.

다수의 움직이는 부분이 있는 오브젝트
애니메이터 컨트롤러