C# is a bit more strict with how you are supposed to do things than JS -- It wants your functions to be clearly defined as iterator blocks, and it wants you to strictly call them using StartCoroutine.
To see how this should be done, replace your Attack() method with this:
public void Attack()
{
StartCoroutine(Attack_Coroutine());
}
private IEnumerator Attack_Coroutine()
{
if (Input.GetButtonDown("Fire1"))
{
_isAttacking = true;
yield return new WaitForSeconds(5);
_isAttacking = false;
}
}
From a code clarity standpoint, I recommend checking Input.GetButtonDown("Fire1"), and THEN calling Attack() if that returns true -- but that's purely methodology, and not required :)
Good luck!
↧