Unity入门操作_混合树_033

来源:互联网 发布:db2 删除表 关系 sql 编辑:程序博客网 时间:2024/05/18 16:57

混合树出现可以解决曲线运动时动画的改变:
首先我们先导入资源
这里写图片描述

这里写图片描述

如图所示默认是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 initializationvoid Start () {    anim = GetComponent<Animator>();}// Update is called once per framevoid 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);    } }

}

原创粉丝点击