- Home /
How do I access "gameObject" in a named class?
I have created a named class and attached it to an gameObject, but I get compiler errors when I try to access things like "gameObject".
My goal is to use getters/setters with the gameObject script. When I use a default javascript script (unnamed), I get errors when I try to use getters/setters like this:
public function get loadErrorMsg():String{return _loadErrorMsg;}
public function set loadErrorMsg(value : String) { _loadErrorMsg = value; }
I read that it needs to be a named class as in "public class Loader {..." for getters/setters to work. However, when I make it a named class I get compiler errors when trying to access things like "gameObject" as in
_playerGameObject=gameObject;
How can I access "gameObject" and "name" in a named class attached to a gameObject?
List errors. Without more, I can only assume you didn't inherit from $$anonymous$$onoBehaviour.
Answer by davedev · Jan 20, 2012 at 05:58 PM
Formal answer so there is answer from Jessy's comment/suggestion. Change:
public class Loader {
to
public class Loader extends MonoBehaviour {
Your answer