Answers for "get int from another script unity"

19

unity variable from another script

//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;
    }
}
Posted by: Guest on April-20-2020
-1

get int from another script unity

public SriptName MyScript;  void Start() { MyScript = GameObject.Find(“NameOfObjectWithScript”).GetComponent<ScriptName>(); }  void Update() { Debug.Log(MyScript.MyInt); }
Posted by: Guest on June-01-2021

Code answers related to "get int from another script unity"

Browse Popular Code Answers by Language