- Home /
How do I assign a renderer to a game object?
I'm trying to control visibility of a game object with the following script...
var Arch = GameObject.FindWithTag("Architectural");
Arch.renderer.enabled = false;
But i'm getting the error 'There is no renderer attached to (my game object)...". How do I attach one? Thanks.
Answer by Sundar · Sep 26, 2012 at 03:55 PM
Try this
Arch.GetComponent("MeshRenderer").enabled = false;
I get this error...
"'Assets/UserInterface.cs(33,51): error CS1061: Type `UnityEngine.Component' does not contain a definition for `enabled' and no extension method `enabled' of type `UnityEngine.Component' could be found (are you missing a using directive or an assembly reference?
Are there any librarys other than
using UnityEngine; using System.Collections;
I think you're using C# but the answer is in UnityScript. Try Arch.GetComponent<$$anonymous$$eshRenderer>().enabled = false;`
Now i'm getting this error...
'Object reference not set to an instance of an object'
On that line in the script. Here is what I have...
void Example() {
var Arch = GameObject.FindWithTag("Architectural"); Arch.GetComponent<$$anonymous$$eshRenderer>().enabled = false; }
Correction: that does work on object created in Unity. But not FBX files I've brought in. I get the 'Object reference not set to an instance of an object' error. Is there a way to fix this? Thanks.