【发布时间】:2020-06-21 00:35:58
【问题描述】:
所以我正在制作一个点击游戏,这是我的代码。我想问的是如何限制按钮点击,所以它不能被多次点击,因为如果我多次点击它,速度就会变得太快
public float downForce;
public float speed;
public int playerHp;
public Text healthText;
Rigidbody2D rb;
CharacterController controller;
void Awake()
{
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
healthText.text = playerHp.ToString();
if (Input.GetMouseButtonDown(0))
{
Jump();
}
if (playerHp < 0)
{
Destroy(this.gameObject);
SceneManager.LoadScene("GameOver");
}
}
public void Jump()
{
rb.AddForce(Vector2.up * downForce + Vector2.right * speed, ForceMode2D.Impulse);
rb.isKinematic = false;
}
【问题讨论】: