我的播放器在Y轴上移动,但有时它不会上升而是卡在一个地方,脚本就像在摇摆的直升机中,当你触摸它旋转到另一侧但它在X轴上时,我接受并在Y轴上制作它轴,但它不能正常工作,播放器有时不转身上升或后退请帮忙,抱歉英语不好
void MovePlayerOnYAxis()
{
foreach (Touch touch in Input.touches)
{
moveL = !moveL;
if (moveL)
{
transform.localScale = new Vector3(1, -1, 1);
}
else
{
transform.localScale = new Vector3(1, 1, 1);
}
huongbay = transform.localScale.x;
}
transform.root.Translate(Vector3.up * speed * huongbay * Time.deltaTime);
}
从@PompeyPaul预先修复但是玩家仍然没有下降,现在它只是向上。
void MovePlayerOnYAxis()
{
foreach (Touch touch in Input.touches)
{
WasTouched = !WasTouched;
if (WasTouched)
{
if (Input.touchCount == 0)
{
WasTouched = false;
transform.localScale = new Vector3(1, 1, 1);
}
}
else
{
if (Input.touchCount > 0)
{
WasTouched = true;
transform.localScale = new Vector3(1,-1, 1);
}
}
huongbay = transform.localScale.y;
}
transform.root.Translate(Vector3.up * speed * huongbay * Time.deltaTime);
}
答案 0 :(得分:0)
请尝试以下选项之一:
transform.Translate(Vector3.up * speed * huongbay * Time.deltaTime)
或
transform.root.position = transform.position + (Vector3.up * speed * huongbay * Time.deltaTime)
或
transform.position = transform.position + (Vector3.up * speed * huongbay * Time.deltaTime)