Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

how to refrence a variable from other script in c#

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;
    }
}
 
PREVIOUS NEXT
Tagged: #refrence #variable #script
ADD COMMENT
Topic
Name
9+7 =