x


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;

}
}
}
more ▼

asked Jun 14 '12 at 10:58 PM

Robomaster gravatar image

Robomaster
92 8 19 32

(comments are locked)
10|3000 characters needed characters left

1 answer: sort oldest

If you have the game object on which the text is located then this will do it:

gameObject.renderer.enabled = false; //or true
more ▼

answered Jun 14 '12 at 11:00 PM

whydoidoit gravatar image

whydoidoit
32.9k 11 23 98

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 "Main Camera" game object, but a script is trying to access it. You probably need to add a Renderer to the game object "Main Camera". Or your script needs to check if the component is attached before using it.

Jun 16 '12 at 01:06 AM Robomaster

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
Jun 16 '12 at 01:09 AM whydoidoit

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.

Jun 16 '12 at 01:15 AM Robomaster

thanks for responing so quickly aslo is that javascript or c#

Jun 16 '12 at 02:01 AM Robomaster

@Will467: var textObject : GameObject is a Javascript declaration. The C# equivalent is GameObject textObject;.

Jun 16 '12 at 04:24 AM Mizuho
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x133
x44
x19
x14

asked: Jun 14 '12 at 10:58 PM

Seen: 591 times

Last Updated: Jun 17 '12 at 01:36 AM