我目前正在Unity的遊戲中工作,無法完成任務。我需要它,當輸入按x次(近戰攻擊)時,角色停止工作,直到你按下另一個按鈕x次,即10次。玩家應該能夠攻擊3次,但是當他這樣做時,角色進入「假死」狀態,在那裏他不能再與玩家走路或近身攻擊。那時候玩家應該再次擊中另一個關鍵,然後玩家將能夠再次走近近戰攻擊。我認爲我可以通過一個簡單的if和else語句來實現這一點,但迄今爲止還沒有得到它的效果。出於某種原因,我的其他部分立即執行,而不是使用近戰攻擊5次。當輸入被按下x次時
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MeleeCounter : MonoBehaviour {
public int attackNumber = 0;
public GameObject meleeHitbox;
// Update is called once per frame
void Update() {
if (attackNumber < 5 && Input.GetButtonDown ("Fire3"))
{
attackNumber++; // increment the counter
meleeHitbox.gameObject.SetActive (true);
Debug.Log ("Attack");
}
if (Input.GetButtonUp ("Fire3")) {
meleeHitbox.gameObject.SetActive (false);
}
else
{
GetComponent<PlayerController>().enabled = false;
Debug.Log ("Too many attacks");
// Here should come a script that if i.e. Fire4 is pressed 10 times reset attackNumer to 0; and set PlayerController to true.
}
}
}