Modifying script with another script...

Hi! I Have one script that have many variables declared public static and a guitext attached, summarizing, the code works this way:

C#
public static string Texto = null;

void Update()
{
   if(guiText.text != Texto)
   {
      guiText.text = Texto;
   }
}

But I am not able to change the string value using another script. The value just don’t change…

Why!? :face_with_spiral_eyes:

Here is how I do it in javascript, shouldnt be that much trouble to convert it to CS

//GUI.js assigned to Camera.current (the current active camera)
var Texto="";
function Update(){
guiText.text = Texto;
}


//player.js
function Update(){
PostText(transform.name + " is Active");
}

function PostText(str : string){
var CS = Camera.current.gameObject.GetComponent("GUI");
if(CS)CS.Texto=str;
}

Thanks, BigMisterB… This Cameta.current will be usefull.

But the problem was that Unity shut down while I was working, and the script did not stayed attached to the camera, and then do not started the method. dammit XD

Thanks, anyway.

Did you use GetComponent?

var other : ScriptName;
other = gameObject.GetComponent(“ScriptName”);
// Call the function DoSomething on the script
other.DoSomething ();

That is useful, but i will not need to discovery the name of the scripts, all things will already be there…

Just:

C#
void Start()
{
   OtherScript.MethodToPutStringsOnTheScreen(String);
}

Thanks, anyway. :wink:

You mean you don’t know the name of the other script? Even for a static you need the script name for another script:
// The static variable in a script named ‘TheScriptName.js’
static var someGlobal = 5;

// You can access it from inside the script like normal variables:
print(someGlobal);
someGlobal = 1;
To access it from another script you need to use the name of the script followed by a dot and the global variable name.print(TheScriptName.someGlobal);
TheScriptName.someGlobal = 10;