get variable from another script unity
//Make Health public
public class PlayerScript: MonoBehaviour {
public float Health = 100.0f;
}
//Access it.
public class Accessor : MonoBehaviour {
void Start()
{
GameObject thePlayer = GameObject.Find("ThePlayer");
PlayerScript playerScript = thePlayer.GetComponent<PlayerScript>();
playerScript.Health -= 10.0f;
}
}public class Script1 : MonoBehavior
{
public static int Script1Int;
}
//Another script:
public class Script2 : MonoBehavior
{
public static int Script2Int;
void Start()
{
Script2Int = Script1.Script1Int;
}
}
Also in C#:
- unity drawline
- unity resources load
- move file from one folder to another c#
- unity create primitive
- same click event diffrenet buttonms c#
- 2d object look at object
- how to trigger event when a com device is connected in c#
- entity framework update child records
- list c#
- how to go to other forms in C#
- c# max sequence contains no elements
- unity rigidbody constraints
- how to convert iformfile to byte array c#
- disable mouse unity
- call stored proc c#
- c# number suffixes
- unity round vector 3 to nearest integer
- how to load the active scene unity
- How to solve error in ExecuteNonQuery() in asp.net
- unity connect to firebase
- c# double question mark
- c# asp.net hover tooltip
- c# get today's date
- unity make a int arry with preset values