<>拖入人物模型

在unity创建场景,建一个平面并把人物模型拖上去

<>加入跑步动画和移动代码

把跑步的动画加在人物模型上并挂上代码

为物体添加移动代码:本次使用的方式A、W、S、D键控制前后左右运动
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class yodong : MonoBehaviour { private Animator anim; void Start() { anim
= GetComponent<Animator>(); } //定义一个速度 void Update() { if (Input.GetKey(KeyCode.
W)) { transform.Translate(Vector3.forward * 10 * Time.deltaTime); anim.SetBool(
"mmm", true); //stransform.Rotate(0, speed * 20 * Input.GetAxis("Horizontal"),
0); } if (Input.GetKeyUp(KeyCode.W)) { anim.SetBool("mmm", false); } //控制物体的移动
if (Input.GetKey(KeyCode.A)) { transform.Translate(Vector3.left *10* Time.
deltaTime); anim.SetBool("mmm", true); } if (Input.GetKeyUp(KeyCode.A)) { anim.
SetBool("mmm", false); } if (Input.GetKey(KeyCode.D)) { transform.Translate(
Vector3.right *10* Time.deltaTime); anim.SetBool("mmm", true); } if (Input.
GetKeyUp(KeyCode.D)) { anim.SetBool("mmm", false); } //向前 //向后 if (Input.GetKey(
KeyCode.S)) { transform.Translate(Vector3.back *10* Time.deltaTime ); anim.
SetBool("mmm", true); } if (Input.GetKeyUp(KeyCode.S)) { anim.SetBool("mmm",
false); } if ((this.transform.eulerAngles.x > 90 && this.transform.eulerAngles.x
< 270) || (this.transform.eulerAngles.z > 90 && this.transform.eulerAngles.z <
270)) { transform.eulerAngles = new Vector3(0, 180, 0); } } }

技术
下载桌面版
GitHub
百度网盘(提取码:draw)
Gitee
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:766591547
关注微信