Animator Scripting

Revisado con versión: 4.3

-

Dificultad: Principiante

Scripting is what allows us to really bring a model's animations to life. In this video you will learn how to utilize the animator class in code to control awesome animations.

Animator Scripting

Principiante Animation

EthanScript

Code snippet

using UnityEngine;
using System.Collections;

public class EthanScript : MonoBehaviour 
{
    Animator anim;
    int jumpHash = Animator.StringToHash("Jump");
    int runStateHash = Animator.StringToHash("Base Layer.Run");


    void Start ()
    {
        anim = GetComponent<Animator>();
    }


    void Update ()
    {
        float move = Input.GetAxis ("Vertical");
        anim.SetFloat("Speed", move);

        AnimatorStateInfo stateInfo = anim.GetCurrentAnimatorStateInfo(0);
        if(Input.GetKeyDown(KeyCode.Space) && stateInfo.nameHash == runStateHash)
        {
            anim.SetTrigger (jumpHash);
        }
    }
}
#pragma strict

var anim : Animator;
var jumpHash : int = Animator.StringToHash("Jump");
var runStateHash : int = Animator.StringToHash("Base Layer.Run");


function Start () 
{
    anim = GetComponent("Animator");
}


function Update () 
{
    var move : float = Input.GetAxis ("Vertical");
    anim.SetFloat("Speed", move);

    var stateInfo : AnimatorStateInfo = anim.GetCurrentAnimatorStateInfo(0);
    if(Input.GetKeyDown(KeyCode.Space) && stateInfo.nameHash == runStateHash)
    {
        anim.SetTrigger (jumpHash);
    }
}
import UnityEngine
import System.Collections


public class EthanScript(MonoBehaviour):

    private anim as Animator

    private jumpHash as int = Animator.StringToHash('Jump')

    private runStateHash as int = Animator.StringToHash('Base Layer.Run')

    
    
    private def Start():
        anim = GetComponent()

    
    
    private def Update():
        move as single = Input.GetAxis('Vertical')
        anim.SetFloat('Speed', move)
        
        stateInfo as AnimatorStateInfo = anim.GetCurrentAnimatorStateInfo(0)
        if Input.GetKeyDown(KeyCode.Space) and (stateInfo.nameHash == runStateHash):
            anim.SetTrigger(jumpHash)

Tutoriales relacionados

Documentación relacionada