- Home /
Scripting error
what im trying to do is make it so that when i click on the menu icon it displays or enables the 3d text. But when it's not selected the 3d text is disabled. Can anyone help with me with this code and tell me whats wrong.
P.S. Options is the 3D text name.
using UnityEngine;
using System.Collections;
public class GameTabs6 : MonoBehaviour {
GameObject Options;
void OnGUI(){
if (GUI.Button(new Rect(100,0,50,25), "Menu")){
GetComponent<GameaTabs5>().enabled = false;
GetComponent<GameTabs3>().enabled = false;
Options.renderer.enabled = true;
}
}
}
Answer by whydoidoit · Jun 14, 2012 at 11:00 PM
If you have the game object on which the text is located then this will do it:
gameObject.renderer.enabled = false; //or true
Its is just 3d text under gameobject moved to a part of the screen i want it to be at. when i used that script it said
There is no 'Renderer' attached to the "$$anonymous$$ain Camera" game object, but a script is trying to access it. You probably need to add a Renderer to the game object "$$anonymous$$ain Camera". Or your script needs to check if the component is attached before using it.
Ah - I thought you had a reference to the 3D text you wanted to hide.
You'll need one of them Define it at the class level and drag and drop your object onto it in the inspector.
var textObject : GameObject;
...
textObject.renderer.enabled = false; // or true
let me give you what i coded
gameObject.renderer().enabled = true;
P.S. Options is a 3d text for the side menu. I want it to be off when your clicking on something else but when you click on menu it's turned on.
thanks for responing so quickly aslo is that javascript or c#
@Will467: var textObject : GameObject
is a Javascript declaration. The C# equivalent is GameObject textObject;
.
Your answer
Follow this Question
Related Questions
enable disabled GameObjects 1 Answer
Gui.Enable transperancy 4 Answers
disable/enable Mouse Look(c#) with a script of js 7 Answers
Disabled colliders picked up by OnTriggerEnter 0 Answers
Disable gun if it is not mine? 1 Answer