|
This two lines are right after each other in the code. D_ReferenceCard is accessible in the following code.(not empty) The class PlayerCard they inherit from indirectly inherits from monobehaviour.
This works, but this:
throws the exception. What could I have done wrong?
(comments are locked)
|
|
What's the type of D_ReferenceCard? In your case it have to be of type PlayerCard and have to be attached to a GameObject (can be a prefab). Instantiate just clones the object. It returns the same type that you hand in. If you reference a component (what you have done), the whole containing GameObject gets cloned and the cloned reference of your component is returned. I can't say much more about that since I have no idea what is returned by getPlayerByID. A final hint: Components (like Monobehaviour) can only exist on GameObjects. It's not possible to create a standalone component. 1.a the type is PlayerCard aswell. 1.b if that is so, that might be the problem. The problem Ive got with this is, that clone doesnt work in unity. And Id happy to get rid of some of the monbehaviour things, but there are some functions I need to reference actual gameobjects that seem to only work out of a monobehaviour class. (this specially affects GetComponent, which seems to be unusable out if non mono, even though it is used via gameComponent.getComponent (which should be included in unity engine namespace)
May 09 '11 at 10:54 AM
T3PeS
http://imageshack.us/photo/my-images/31/unbenanntilc.jpg/ for the better understanding. I know this is against unity directive regarding monobehaviour but till this moment worked perfectly fine. (the parent object is actually attached to a gameobject to provide cascaded OnGUI()
May 09 '11 at 11:03 AM
T3PeS
GUIElements are organized in a tree. GUIElement and the classe inheriting from it contain a list of GUIElement thats OnGUI is called onGUI
May 09 '11 at 11:05 AM
T3PeS
That's not against Unity's directive ;). Subclasses are a major element of OOP but in Unity you can't create a monobehaviour with "new". You have to use AddComponent on a GameObject. I'll add a sample.
May 09 '11 at 11:47 AM
Bunny83
Another way would be to use a class that isn't derived from MonoBehaviour but provide a public method (interface) that is called from a MonoBehaviour's OnGUI. I do it that way in my node-based-editor. Greetings from sunny Germany ;)
May 09 '11 at 12:04 PM
Bunny83
(comments are locked)
|
