【发布时间】:2015-07-07 02:08:43
【问题描述】:
我目前正在做一个简单的棒球比赛。尝试做的是让玩家能够向后挥动球棒以“充电”能量,可以这么说,然后当释放按钮时,他将以与储存的能量相等的速度向前挥动球棒。
这一切都很好,但我的问题是当球棒到达 y 轴上的某个点时我需要停止球棒的运动,我有点不确定如何去做,因为我不能只是告诉它在设定的时间后停止旋转,因为由于每次挥杆可能具有的速度差异,蝙蝠每次都不会同时到达前点。
这里是我目前写的代码:
public int rotateSpeed = 50;
public float AmountOfPowerChargedUp = 0;
void Update()
{
if (Input.GetMouseButton(0))
{
AmountOfPowerChargedUp += 5f;
transform.Rotate(Vector3.up * rotateSpeed * Time.deltaTime);
Debug.Log(AmountOfPowerChargedUp);
}
if (!Input.GetMouseButton (0))
{
transform.Rotate(Vector3.down * AmountOfPowerChargedUp * Time.deltaTime);
// if(在y轴上达到266停止旋转)
}
}
private void OnGUI()
{
GUI.Label (new Rect (50, 15, 250, 25), "AmountOfPowerChargedUp: " + AmountOfPowerChargedUp); // Tallene er mål på størrelsen og placering
}
【问题讨论】: