unity3d 物体在Y轴上移动到设定位置时停止

unity3d 物体在Y轴上移动到设定位置时停止该如何实施?


慕田峪7331174
浏览 2409回答 1
1回答

慕田峪4524236

值只在按下的那一帧为true。还有就是Vector3.Lerp()这个函数的第三个参数的有效范围是0~1,不多说了,你懂得。 private bool sMove = false; private Vector3 endpos; private float process = 0; void Update() { if (Input.GetKeyDown(KeyCode.UpArrow)) { if (!sMove) { endpos = new Vector3(person.transform.position.x, person.transform.position.y + 10, 0); process = 0; sMove = true; } } if (sMove) { process += Time.deltaTime * 2; if (process < 1) person.transform.position = Vector3.Lerp(person.transform.position, endpos, process); else { sMove = false; } } }
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Unity 3D