簡體   English   中英

按住按鈕時如何讓我的播放器連續移動?

[英]How can i make my player continuously move when a button gets held down?

我想讓我的播放器在按下按鈕時向左移動,但是當我統一測試我的腳本時,它只會移動他一次。 我想讓他不斷移動,有誰知道如何解決這個問題?

 public void LeftMove()//Gets called everytime my button is held down
{
    rb.AddForce(120 * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}

我會為此使用MonoBehaviorhttps : MonoBehavior = MonoBehavior

這不是您要查找的事件,因此如果按鍵被按下,您需要在每個周期檢查自己:

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    void Update()
    {
        if (Input.GetKey(KeyCode.DownArrow))
        {
            rb.AddForce(120 * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
        }
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM