一、导入模型
1、下载地址 <https://pan.baidu.com/s/1AUmhOzCLNijvVDzyhGOspQ>
2、拖入DefaultAvatar
3、解决贴图丢失问题
t:skinnedmeshrenderer
若牙齿、舌头被皮肤遮盖,可将皮肤Mesh Renderer取消勾选,显示出牙齿等
贴图一般在Textures(纹理)文件夹
二、骨骼映射
1、第一个模型创建自己的骨骼映射,其他相同骨骼的模型都使用他的骨骼映射(不同的自己创建骨骼映射)
选中其他模型,Rig—Avatar Definition—Copy From Other
Avatar,相同骨骼的拖入第一个Perfab模型的Avatar
思路:骨骼映射(映射后unity才能通过控制骨骼来控制人物运动)—状态机控制动画播放
三、1、给人物创建Animator Controller,赋值默认Idle(共用DefaultAvatar@Idle_Neutral角色Idle动画)
2、让人物能够行走、奔跑
创建Animation Clip:切割WalkForward动画,限制不必要的方向运动(Bake Into
Pose),创建合适片段并添加进状态机,同理创建跑步状态动画
三、通过代码控制人物行走:
按W、S、下上键,人物前行—添加float型参数Speed,动画切换条件通过检测参数数值,决定是否播放动画
using UnityEngine; public class Player : MonoBehaviour { private Animator
anim; // Use this for initialization void Start () { anim =
GetComponent<Animator>(); } // Update is called once per frame void Update () {
anim.SetFloat("Speed", Input.GetAxis("Vertical")); } } using UnityEngine;
public class Player : MonoBehaviour { private Animator anim; private int
speedID = Animator.StringToHash("Speed"); // Use this for initialization void
Start () { anim = GetComponent<Animator>(); } // Update is called once per
frame void Update () { anim.SetFloat(speedID, Input.GetAxis("Vertical"));
//speedID仅代替Speed, } }
四、控制人物奔跑
策略:检测是否按下shift,并按住w,确定才可奔跑
unity设置Bool参数isSpeedup
using UnityEngine; public class Player : MonoBehaviour { private Animator
anim; private int speedID = Animator.StringToHash("Speed"); private int
isSpeedupID = Animator.StringToHash("isSpeedup"); // Use this for
initialization void Start () { anim = GetComponent<Animator>(); } // Update is
called once per frame void Update () { anim.SetFloat(speedID,
Input.GetAxis("Vertical")); //speedID仅代替Speed if
(Input.GetKeyDown(KeyCode.LeftShift)) { anim.SetBool(isSpeedupID, true); }
if(Input.GetKeyUp(KeyCode.LeftShift)) // 不可是else,判断不全 {
anim.SetBool(isSpeedupID, false); } } }
热门工具 换一换