Hi, all! I have a GUI.Label that I would like to be visible while a variable in another script is true, and invisible while it is false. Is this possible?
Thanks! - YA
Hi, all! I have a GUI.Label that I would like to be visible while a variable in another script is true, and invisible while it is false. Is this possible?
Thanks! - YA
yes it is, is the other script attached to the same gameobject? if so you need:
Javascript:
var visible = gameObject.getComponent("scriptName").variableName;
C#
bool visible = gameObject.getComponent<"scriptName">().variableName;
if it is not attached to the same Game Object simply call GameObject.Find before you try to get the component.
Cheers
hmmm…
Where exactly would I put it in my script?
var Skin : GUISkin;
var resolution_ratio_x : float;
var resolution_ratio_y : float;
var actual_height : float;
var actual_width : float;
var native_height : float = 768;
var native_width : float = 1024;
function OnGUI(){
if(Skin){
GUI.skin = Skin;
}
else{
Debug.Log("You forgot to add a skin!");
}
//set up scaling
actual_height = Screen.height;
actual_width = Screen.width;
resolution_ratio_y = actual_height / native_height;
resolution_ratio_x = actual_width / native_width;
//set up scaling matrix
GUI.matrix = Matrix4x4.TRS (Vector3(0, 0, 0), Quaternion.identity, Vector3 (resolution_ratio_x, resolution_ratio_y, 1));
// The Rest
GUI.Label(Rect(0,0,150,80),"Points:");
GUI.Label(Rect(0,60,150,80),(" " + HitPlayerWhite.points));
// Respawn message. Would like this to disappear when the variable 'status' in another script == "alive"
GUI.Label(Rect(10,20,300,400),"Press R to respawn");
}
what is the scriptname of the other script where the variable for the status is contained in? also what is the variable name there?
Is it attached to the same game object like the script you have posted here?
If it is another game object it will be something like that:
if(GameObject.Find("otherObject").getComponent("otherScript").status == "alive")
{
// Respawn message. Would like this to disappear when the variable 'status' in another script == "alive"
GUI.Label(Rect(10,20,300,400),"Press R to respawn");
}
Oh! Alright! That works quite well! I’ll implement it and see what happens.
enjoy! ![]()
I seem to have gotten a Null Reference Exception. Any Ideas?
var Skin : GUISkin;
var resolution_ratio_x : float;
var resolution_ratio_y : float;
var actual_height : float;
var actual_width : float;
var native_height : float = 768;
var native_width : float = 1024;
function OnGUI(){
if(Skin){
GUI.skin = Skin;
}
else{
Debug.Log("You forgot to add a skin!");
}
//set up scaling
actual_height = Screen.height;
actual_width = Screen.width;
resolution_ratio_y = actual_height / native_height;
resolution_ratio_x = actual_width / native_width;
//set up scaling matrix
GUI.matrix = Matrix4x4.TRS (Vector3(0, 0, 0), Quaternion.identity, Vector3 (resolution_ratio_x, resolution_ratio_y, 1));
// The Rest
GUI.Label(Rect(0,0,150,80),"Points:");
GUI.Label(Rect(0,60,150,80),(" " + HitPlayerWhite.points));
[COLOR="red"] if(GameObject.Find("Player").GetComponent ("PlayerControl").status == "alive"){
GUI.Label(Rect(10,20,300,400),"Press R to respawn");[/COLOR]
}
}
Null Reference Exception:

it says that there is no component “PlayerControl”, is the script named PlayerControl?
Yep.
and the GameObject is also named “Player” as well as the variable is called status? ensure that the variable is public.
Figured it out! You don’t have to do all of that searching. You just say:
PlayerControl.status == “alive”
Thanks for the help, man!
-YA
great! ![]()