Hello i have 2 sript, scrPlayerGame and scrLoose. And 2 scene ScGame(scrPlayerGame) and ScLoose(scrLoose). In scrPlayerGame i have a string variable Loose and i want to print this variable in scrLoose, but i have problem with my code:
var x;
function Start ()
{
x=GameObject.Find(“LooseHira”).GetComponent(scrPlayerGame);
}
function OnGUI ()
{
GUI.Label (Rect(10, 10, 350, 20), x); // Here i want to print text
if (GUI.Button(Rect(100,100,150,30),“Main Menu”))
{
Application.LoadLevel(“sceneMainMenu”);
}
}
error is
How can i print my variable?
the “x” var is a script, but you must to write a string for GUI.Label, if the var you want to print is a string, then you can code:
let´s suppose that your var´s name is “myName” and this is a string
x = GameObject.Find("LooseHira").GetComponent("otherScriptName");
function OnGUI (){
GUI.Label ( Rect ( 10, 10, 350, 20), x.myName ) );
that should create a label with myName´s string var text … meaning: if the “myName” var is “Rederin”, then the GUI.Label will be called “Rederin”…
that will print on console the var myName from another script. but it must to be string .