欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 艺术 > [Unity3D]胡闹厨房复刻笔记

[Unity3D]胡闹厨房复刻笔记

2024/10/24 4:47:08 来源:https://blog.csdn.net/kokool/article/details/141890343  浏览:    关键词:[Unity3D]胡闹厨房复刻笔记

完整笔记内容点击https://kokoollife.github.io/查看。

部分内容

02 简陋实现

001 玩家控制器

[1]简单移动
a:逻辑与动画分离

在这里插入图片描述

b:新建脚本Player.cs
using UnityEngine;public class Player : MonoBehaviour
{//私有就保证不被其他脚本修改该变量,序列化保证我们可以方便在检查器中调节这个变量。[SerializeField] private float moveSpeed = 7f;private void Update() {//实现上下左右移动,有效的是三维坐标(x,0,z)Vector2 inputVector = new Vector2(0, 0);if (Input.GetKey(KeyCode.W)) {inputVector.y = +1;}if (Input.GetKey(KeyCode.S)) {inputVector.y = -1;}if (Input.GetKey(KeyCode.A)) {inputVector.x = -1;}if (Input.GetKey(KeyCode.D)) {inputVector.x = +1;}//归一化,解决对角线移动速度过快问题inputVector = inputVector.normalized;Vector3 moveDir = new Vector3(inputVector.x, 0, inputVector.y);//要考虑帧率对游戏的影响和速度transform.position += moveDir * moveSpeed * Time.deltaTime;Debug.Log(Time.deltaTime);}
}

FPS:

在这里插入图片描述

帧率其实也可以通过Time.deltaTime来反映

在这里插入图片描述
效果展示
在这里插入图片描述

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com