1. 程式人生 > >【Unity】通過AnimatorController更改其中某個動畫片斷的速度

【Unity】通過AnimatorController更改其中某個動畫片斷的速度

using UnityEngine;
using System.Collections;
using UnityEditor.Animations;

public class NewBehaviourScript : MonoBehaviour {

    public  AnimatorController AC; 
    private float speed = 2f;  
    void IfNeedChangeSpeed ()  
    {  
    	
        AC.layers [0].stateMachine.states [0].state.speed = 5;  
        for (int i = 0; i < AC.layers [0].stateMachine.states.Length; i++) {  
            Debug.Log (AC.layers [0].stateMachine.states [i].state.name == "指定的動畫名");  
            if (AC.layers [0].stateMachine.states [i].state.name == "指定的動畫名") {  
                AC.layers [0].stateMachine.states [i].state.speed = speed;  
            }  
        }  
    } 
}