How To Delete An Object After An Animation Unity
Objects with Multiple Moving Parts
Using Animation Events
You tin can increment the usefulness of Blitheness clips by using using Animation Events, which allow you to call functions in the object'due south script at specified points in the timeline.
The role called by an Animation Effect likewise has the option to accept one parameter. The parameter can exist a bladder, string, int, or object reference, or an AnimationEvent object. The AnimationEvent object has fellow member variables that allow a bladder, string, integer and object reference to exist passed into the role all at once, forth with other information nigh the Event that triggered the function call.
// This C# function tin be called past an Animation Event public void PrintFloat (float theValue) { Debug.Log ("PrintFloat is called with a value of " + theValue); } To add an Blitheness Outcome to a clip at the current playhead position, click the Event button. To add an Animation result to any signal in the Blitheness. double-click the Consequence line at the betoken where yous want the Event to be triggered. In one case added, you can elevate the mouse to reposition the Event. To delete an Event, select it and press the Delete cardinal, or right-click on it and select Delete Effect.
When y'all add an Effect, the Inspector Window displays several fields. These fields let you to specify the name of the function y'all want to call, and the value of the parameter yous want to pass to it.
The Events added to a prune are shown every bit markers in the Event line. Concord the mouse over a mark to show a tooltip with the part proper noun and parameter value.
Y'all can select and dispense multiple Events in the timeline.
To select multiple Events in the timeline, hold the Shift key and select Event markers one by one to add together them to your choice. Yous can also elevate a pick box across them; click and elevate within the Event marker expanse, like this:
Case
This example demonstrates how to add Animation Events to a simple GameObject. When all the steps are followed, the Cube animates forwards and backwards forth the x-axis during Play mode, and the Event message is displayed in the panel every one second at the 0.8 second time.
The case requires a small script with the function PrintEvent(). This function prints a debug message which includes a string ("called at:") and the time:
// This C# function tin can be called by an Animation Event using UnityEngine; using Organization.Collections; public grade ExampleClass : MonoBehaviour { public void PrintEvent(string s) { Debug.Log("PrintEvent: " + s + " chosen at: " + Time.time); } } Create a script file with this example code and place it in your Projection folder (correct-click inside the Project window in Unity and select Create > C# Script, then copy and paste the above code case into the file and salvage it).
In Unity, create a Cube GameObject (carte: GameObject > 3D Object > Cube). To add your new script file to it, drag and drop it from the Project window into the Inspector window.
Select the Cube and and then open the Animation window (carte: Window > Animation). Set up a Position curve for the x coordinate.
Next, gear up the animation for the x coordinate to increment to around 0.four and so dorsum to zero over ane second, then create an Animation Result at approximately 0.eight seconds. Press Play to run the animation.
Objects with Multiple Moving Parts
Source: https://docs.unity3d.com/560/Documentation/Manual/animeditor-AnimationEvents.html
Posted by: clementsmadmily.blogspot.com

0 Response to "How To Delete An Object After An Animation Unity"
Post a Comment