- Home /
Accessing non static members in a static function argument??
I want to create a function, that receives the name of the gameObject, and disable the renderer on all childs in this gameobject, but when I compile the script the debbuger says:
Assets/Scripts/calidad-rendimiento/lods/lods.js(8,11): BCE0020: An instance of type 'UnityEngine.Component' is required to access non static member 'gameObject'.
Here is my code:
static function disable_hab (name_hab : String){
var hab = gameObject.Find(name_hab).GetComponentsInChildren( Renderer );
for (var child : Renderer in hab) { child.renderer.enabled = false; } }
Thanks and sorry for my English ;)
Answer by duck · Jan 01, 2010 at 07:07 PM
I think you just need to change that for a capital 'G' in GameObject there:
var hab = GameObject.Find(name_hab).GetComponentsInChildren( Renderer );
This is because you don't call the 'Find' function on any particular gameObject instance - because it's a static function, you call it on the GameObject Class itself.
Wow, thanks a lot, It works. I underestand it now.