给animator动态添加事件

using UnityEngine;
using System.Collections;

public class setAnimationEvent : MonoBehaviour {

    public RuntimeAnimatorController m_runtimeAnimatorController;

    // Use this for initialization
    void Start () {
        m_runtimeAnimatorController = this.GetComponent<Animator>().runtimeAnimatorController;
        AnimationEvent newEvent = new AnimationEvent();
        newEvent.functionName = "print";
        newEvent.time = 0.2f;
        m_runtimeAnimatorController.animationClips[0].AddEvent(newEvent);
        Debug.Log(m_runtimeAnimatorController.animationClips.Length.ToString()); 
        this.GetComponent<Animator>().Rebind();
    }
    
    // Update is called once per frame
    void Update () {
    
    }

    void print()
    {
        Debug.Log("ssss");
    }
}

 

posted @ 2015-11-06 11:08  softimagewht  阅读(1801)  评论(0编辑  收藏  举报