您的位置:首页 > 移动开发 > Unity3D

Unity入门操作_混合树_033

2017-09-01 17:39 483 查看
混合树出现可以解决曲线运动时动画的改变:

首先我们先导入资源





如图所示默认是Run动画,此时运行我们可以看到下图,



如图所示我们需要把Apply Root Motion取消勾选,现象如下图



双击Controller进入下图



此时我们创建一个如下图所示



创建成功后会自动生成一个下图



双击所建立的



进入下图(注意此时进入了Blend Tree层)



我们点击它并为他修改模式



添加Motion



添加完成后如下图





此时我们需要将Automate Threshold取消勾选才能对其初始数值进行修改



此时我们对混合树的操作就告一段落了,我们就可以返回上一层并对动画执行流程进行修改,操作如下:





操作完成后我们就可以写脚本用按键实现前进时不同的动画了,



脚本如下

using UnityEngine;

using System.Collections;

public class playtest : MonoBehaviour {

private Animator anim;
private float horizontal;
private float vertical;
public float speed;
public float rotateSpeed;
// Use this for initialization
void Start () {
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
horizontal = Input.GetAxis("Horizontal");
vertical = Input.GetAxis("Vertical");
if (Input.GetKey(KeyCode.W)||Input.GetKey(KeyCode.UpArrow))
{
anim.SetBool("run", true);transform.Translate(Vector3.forward*Time.deltaTime*speed,Space.Self);
if (vertical!=0)
{
anim.SetFloat("RunValue",horizontal);
transform.Translate(Vector3.forward * Time.deltaTime * speed*Mathf.Abs(horizontal), Space.Self);
transform.Rotate(Vector3.up * rotateSpeed * Time.deltaTime * horizontal);
}
}
if (Input.GetKeyUp(KeyCode.W) || Input.GetKeyUp(KeyCode.UpArrow))
{
anim.SetBool("run", false);
}
}


}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  动画 unity