Unable to Call Instantiate in Class Member Function

Posted by onguarde on Game Development See other posts from Game Development or by onguarde
Published on 2012-11-05T00:15:32Z Indexed on 2012/11/05 5:14 UTC
Read the original article Hit count: 251

Filed under:

The following javascript is attached to a gameObject.

var instance : GameObject;

class eg_class   {   
    function eg_func(){    
       var thePrefab : GameObject;
        instance = Instantiate(thePrefab);
    }
}

Error,

Unknown identifier: 'instance'.
Unknown identifier: 'Instantiate'.

Questions,

1) Why is it that "instance" cannot be accessed within a class? Isn't it supposed to be a public variable?
2) "Instantiate" function works in Start()/Update() root functions. Is there a way to make it work from within member functions?

Thanks in advance!

© Game Development or respective owner

Related posts about unity