Unity3DAnimator控制参数和添加事件

更新时间:2023-07-23 03:32:08 阅读: 评论:0

Unity3DAnimator控制参数和添加事件Animator控制参数和添加事件
using UnityEngine;
using System.Collections;
public class AniControl : MonoBehaviour {
public bool IsRolling = fal;
public bool IsDead = fal;
public bool IsJump = fal;
public float Direction = 0.5f;
public Animator Anitor;
public float Velocity = 0f;
public int IsRollingId =-1;
public int IsJumpId = -1;
public int IsDeadId = -1;
AnimatorOverrideController overrideController;
void Awake()
{
//获得哈希id
IsRollingId = Animator.StringToHash ("IsRolling");
IsDeadId = Animator.StringToHash ("IsDead");
IsJumpId = Animator.StringToHash ("IsJump");
//要动态修改Animator 需要给OverrideController
overrideController = new AnimatorOverrideController();
overrideController.runtimeAnimatorController  = Anitor.runtimeAnimatorController;
}
// U this for initialization
void Start () {
var runClip = overrideController["Run"];
Anitor.runtimeAnimatorController = overrideController;
//动态添加事件
AnimationEvent aEvent1 = new AnimationEvent();
pe系统进不去aEvent1.time          = runClip.length;
aEvent1.functionName  = "OnOpenComplete";隆肛蛙
aEvent1.stringParameter = runClip.length.ToString ();
runClip.AddEvent(aEvent1);
}
// Update is called once per frame
void Update () {
if (Input.GetKey (KeyCode.W)) {
Velocity = 1.0f;
水瓶座的明星} el {
Velocity = 0f;
}
if (Input.GetKey (KeyCode.Space)) {
IsJump = true;
} el {
IsJump = fal;
我的黄金时代
}
html按钮if (Input.GetKey (KeyCode.A)) {
Direction = 0;
} el if (Input.GetKey (KeyCode.D)) {
Direction = 1;
} el {
Direction = 0.5f;
}
Anitor.SetFloat ("Velocity",Velocity);
Anitor.SetBool (IsRollingId,IsRolling);
Anitor.SetBool (IsDeadId,IsDead);
Anitor.SetBool (IsJumpId,IsJump);
Anitor.SetFloat ("Direction",Direction);
闪烁的小星}
void OnOpenComplete(string str)
西晋灭亡
{
reverd
Debug.Log ("OnOpenComplete="+str); }
}

本文发布于:2023-07-23 03:32:08,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/1092824.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:添加   事件   控制参数   进不去   闪烁   系统
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图