[英]the character moves immediately when the scene starts
在更新中(每幀都有效),您的代碼檢查 position 是否等於 smth,如果不等於則向游戲對象添加速度。
如果您希望在按下按鈕時發生這種情況,最好使用 Input.getkeydown 事件。
例如:
void Update()
{
if (Input.GetKeyDown(KeyCode.RightArrow))
{
run = 1f;
}else
if (Input.GetKeyDown(KeyCode.LeftArrow))
{
run = -1f;
}
else
{
run = 0f;
}
rb.velocity = new Vector2(run, transform.position.y);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.