I’m trying to get a variable from object’s script into another object’s script. I tried anything I could find but none seems to work :\
This is the part of the “selection” object script (cameracontrol)
void OnGUI() {
GUI.Label (new Rect (20, 20, 100, 30), "Name: " + sel_name);
GUI.Label (new Rect (20, 40, 100, 70), GameObject.Find(sel_name).ToString());
if (GUILayout.Button("Click for data"))
{
if (sel_name == "Null")
Debug.Log ("No selection");
else
{
string thingyy = GameObject.Find (sel_name).GetComponent (defaultnpc).npcname;
Debug.Log (sel_name + " is selected, his name is " + thingyy);
}
}
}
And this is the selected object script (defaultnpc) with the variable
public string npcname;
public string npcclass;
void Start () {
if (npcname == null) npcname = "Pootman";
if (npcclass == null) npcclass = "Testthing";
}
Thanks for the help