How may i get a variable from another script onto my wanted Script?

Hello Happy Helpers!

I totally would like to know how I could get a variable from one of my scripts and use it in another

I’m using C# Btw!

Well I know how to get a function from another script but I just cant get the knack to getting a variable from another script.

If anyone can help I’d Appreciate it! Yeah@!

First get the object where the script you are trying to acces is attached to, for example I will use Player as the object:

var Player = GameObject.Find ("Player"); 

Then get the script that you need, for example the script attached to the player is healthScript.
Put this Before you are loading the variable:

healthScript healthScript = Player.GetComponent<healthScript> ();

Then to acces the variable, for example my variable will be playerHealth:

healthScript.playerHealth = 10;

Now the health in healthScript is set to 10!

Good luck with it!

EDIT: I don’t know if this is the best way, but as a student this is the only way I am familiar with. Just trying to help!