- Home /
GUI script still shows GUI on different camera
private var enter : boolean;
var mySkin : GUISkin;
function OnGUI()
{
GUI.skin = mySkin;
if(enter)
{
GUI.Label(new Rect(Screen.width/2 - 75, Screen.height - 100, 200, 200), "TEXT");
}
}
function OnTriggerEnter (other : Collider)
{
if (other.gameObject.tag == "Player")
{
enter = true;
}
}
function OnTriggerExit (other : Collider)
{
if (other.gameObject.tag == "Player")
{
enter = false;
}
}
So I have this script which works pretty well, however, whenever I turn off my first person controller and switch to a different camera the GUI still shows on screen? How would I get it to not show on a different camera?
Remove the GUI layer from the other camera
http://docs.unity3d.com/Documentation/Components/class-GUILayer.html
The GUI layer has already been removed, but it still shows.
Answer by sacajawhoohoo · May 19, 2014 at 02:49 AM
Alright I managed to fix it by changing it to this: private var enter : boolean; var mySkin : GUISkin;
function OnGUI()
{
GUI.skin = mySkin;
if((enter) && (Camera.current.name == "Main Camera"))
{
GUI.Label(new Rect(Screen.width/2 - 75, Screen.height - 100, 200, 200), "TEXT");
}
}
function OnTriggerEnter (other : Collider)
{
if (other.gameObject.tag == "Player")
{
enter = true;
}
}
function OnTriggerExit (other : Collider)
{
if (other.gameObject.tag == "Player")
{
enter = false;
}
}
However now I get a error message: NullReferenceException: Object reference not set to an instance of an object TV.OnGUI () (at Assets/Standard Assets/Character Controllers/Sources/Scripts/TV.js:7)
Your answer
Follow this Question
Related Questions
A GUI error in script??? HELP,Please!! 1 Answer
2 Cameras layer wont render till i turn it off/on 0 Answers
C# camera script error 1 Answer
Error when changing fov to zoom? 0 Answers
Problem making a ruler 1 Answer