dimanche 21 novembre 2021

Calling protected variable from another class

I need to call a protected variable from a public class into an if statement in a private method of another public class I am programing a video game in unity and I need to use a bool variable (that shows if the character is out of stamina) in an if statement to determine whether or not the character can run This is what my code looks like excluding everything unrelated to the problem

Public class CharacterStats : MonoBehaviour
{
[SerialzeField] protected bool Tired;
}

Public class PlayerMovement : MonoBehaviour
{
Private void HandleRunning()
 {
 If (Input.GetKeyDown(KeyCode.LeftShift) && X != True) 
  {
 Speed = RunSpeed;
  }
 }
}
X is where I want the Tired variable to be.   

Aucun commentaire:

Enregistrer un commentaire