今天学习了 Unity 5.x 的创建人物
主要学习了Mecanim系统 Unity 4.x以后引入的新动画系统。
另外Animator 视图的使用
关于几个动作的切换 先必须要将要使用的状态导入Animation文件夹中后, 在创建Animator 视图里操作 Animator Controller。
然后学会控制了摄像机的第三人称追随 代码如下
using UnityEngine;
using System.Collections;
public class ThirdPersonCam :MonoBehaviour
{
//摄像机的跟随对象
public Transform follow;
//摄像机在水平方向与对象的距离
public float distanceAway;
//摄像机在垂直方向与对象的距离
public float distanceUp;
//过渡速度
public float smooth;
//摄像机的目标速度
private Vector3 targetPostion;
//在 LateUpdate 中执行摄像机操作,确保在对象操作完成以后
void LateUpdate()
{
//计算目标位置‘
targetPosition =follow.positon+Vector3.up*distanceUp-follow.forward *distanceAway;
//对当前位置进行插值运算
transform.position=Vector.lerp(transform.position,targetPosition,Time.deltaTime*smooth);
//使摄像机观察对象
transform.Lookat(follow);
}
}
在窗体中的参数进行如下设置
Follow :设置为游戏对象
Distance Away :5
Distance Up :2
Smooth :3
动作混合控制
在run的基础上点击 create new bendtree in state 然后添加 runleft run 和runright
并在parameter参数一栏设置 direction
通过input ,GetAxis() 返回axis 也就是控制轴的值
Animator.setFloat() 设置Animator 的float 参数