How to access the bool variables from a other c#

hi i’m using this example :

i din’t really get the line 8 “myPlayer”

naturally i’v this error =

Assets/Home.cs(113,24): warning CS0219: The variable `myPlayer’ is assigned but its value is never used

need help, i just try to communicate with 2 different c# who are on different object

A lot of Unity tutorials are focused on the idea of attaching components, MonoBehaviours, stuff like that. The tutorial you linked is creating a Player class that doesn’t inherit from MonoBehaviour, and so doesn’t have to be attached to anything.

Line 8:

Player myPlayer = new Player();

We can split this into two lines, to explain it a little more clearly:

Player myPlayer; //declare a variable of type "Player" named "myPlayer"
myPlayer = new Player(); //instantiate a new Player, assign it to myPlayer

It’s important to distinguish between a class and object. A class is a sort of template or blueprint, and an object is an instance of that class. To create an object, you must call the constructor for the class, which is why the new keyword is there.

Since the tutorial leaves all of Player’s fields public, all you need to access them is a reference to a Player object. You have one: myPlayer.

It’s also important to distinguish between warnings and errors from the compiler. Warnings might be bad, and should usually be checked for correctness. Errors are definitely bad, and stop your program from working or running at all. In this case, you’re seeing a warning that says you’re creating a Player but never using or modifying it, which the compiler thinks is a little fishy.

Probably you can fix the warning by finishing the tutorial.

That’s not an error btw, the warning means you’ve declared a variable but not used it anywhere. Perhaps later in the script tut the variable myPlayer is actually used.

thx, very helpful

the problem not using MonoBehaviour, is that i can’t use animator = GetComponent();