Need help with this please.

So I’m trying to access a variable from one class inside the script of another.

In this particular case I want to get a return of a bool variable named attacking from player

so for example

public player plyr;

plyr = gameObject.getComponent();

if(player.attacking){

}

I tried returning the bool variable in a function, but I’m having just as hard of a time getting a class to call another class’ functions. So if anyone can tel me how to do this, that’ll be awesome. Cause the documentation doesn’t seem to help me much in this regard. Thanks!

To access instance variables, you have to use an instance of the class, which in this case is referred to by the variable “plyr”. You only use the class name to access static variables.

public player plyr;

plyr = gameObject.getComponent<InsertTypeOfObjectHere>();

if(plyr.attacking){ ... }