banner



How To Play An Animation Once In Unity

Objects with Multiple Moving Parts

Using Animation Events

You can increase the usefulness of Blitheness clips Blitheness data that tin can be used for blithe characters or simple animations. Information technology is a uncomplicated "unit" piece of movement, such as (1 specific instance of) "Idle", "Walk" or "Run". More info
Encounter in Glossary
by using Blitheness Events, which let you to telephone call functions in the object'southward script at specified points in the timeline.

The function called by an Blitheness Outcome also has the pick to have one parameter. The parameter can exist a float, string, int, or object reference, or an AnimationEvent object. The AnimationEvent object has member variables that permit a float, cord, integer and object reference to be passed into the office all at once, along with other information about the Event that triggered the role call.

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

To add together an Animation Upshot to a clip at the current playhead position, click the Issue button. To add an Animation event to whatever point in the Blitheness, double-click the Event line at the indicate where you want the Effect to be triggered. Once added, you can drag the mouse to reposition the Upshot. To delete an Event, select it and printing the Delete key, or right-click on information technology and select Delete Consequence.

Animation Events are shown in the Event Line. Add a new Animation Event by double-clicking the Event Line or by using the Event button.
Animation Events are shown in the Event Line. Add a new Blitheness Event by double-clicking the Result Line or by using the Event button.

When you add together an Event, the Inspector A Unity window that displays information virtually the currently selected GameObject, asset or project settings, assuasive y'all to audit and edit the values. More info
Run across in Glossary
Window displays several fields. These fields let you lot to specify the name of the function y'all want to call, and the value of the parameter you want to pass to it.

The Animation Event Inspector Window
The Blitheness Event Inspector Window

The Events added to a prune are shown every bit markers in the Result line. Hold the mouse over a mark to show a tooltip with the office name and parameter value.

Yous can select and dispense multiple Events in the timeline.

To select multiple Events in the timeline, agree the Shift key and select Outcome markers one by 1 to add together them to your option. You can also drag a selection box across them; click and drag within the Consequence marker surface area, like this:

Example

This example demonstrates how to add together Blitheness Events to a simple GameObject. When all the steps are followed, the Cube animates forwards and backwards along the ten-axis during Play mode, and the Issue bulletin is displayed in the console every 1 2d at the 0.8 second time.

The instance requires a small script with the function PrintEvent(). This function prints a debug message which includes a string ("chosen at:") and the fourth dimension:

          // This C# function tin can exist called by an Blitheness Upshot using UnityEngine; using Organization.Collections;   public class ExampleClass : MonoBehaviour  {     public void PrintEvent(string s)      {         Debug.Log("PrintEvent: " + south + " chosen at: " + Time.time);     } }                  

Create a script file with this example code and place information technology in your Project folder (right-click inside the Project window in Unity and select Create > C# Script, then copy and paste the higher up lawmaking example into the file and relieve it).

In Unity, create a Cube GameObject (card: GameObject The central object in Unity scenes, which can stand for characters, props, scenery, cameras, waypoints, and more than. A GameObject'due south functionality is defined by the Components attached to information technology. More than info
See in Glossary
> 3D Object A 3D GameObject such as a cube, terrain or ragdoll. More info
See in Glossary
> 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 then open up the Animation window (menu: Window > Blitheness > Animation or utilise ctrl+half dozen). Set a Position curve for the x coordinate.

Animation window
Blitheness window

Adjacent, gear up the animation for the x coordinate to increase to around 0.4 then back to naught over 1 second, and then create an Animation Event at approximately 0.viii seconds. Press Play to run the animation.


  • 2018–08–24 Page amended

Objects with Multiple Moving Parts

Source: https://docs.unity3d.com/Manual/script-AnimationWindowEvent.html

Posted by: hinesthestrand.blogspot.com

0 Response to "How To Play An Animation Once In Unity"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel