how to take a variable from one script to other in unity code example
Example 1: unity variable from another script
public class PlayerScript: MonoBehaviour {
public float Health = 100.0f;
}
public class Accessor : MonoBehaviour {
void Start()
{
GameObject thePlayer = GameObject.Find("ThePlayer");
PlayerScript playerScript = thePlayer.GetComponent<PlayerScript>();
playerScript.Health -= 10.0f;
}
}
Example 2: get variable from other scriptin unity c#
public ScriptB = scriptB;
void Start()
{
scriptB.myFloat = 3.542f;
}
public float myFloat;