- Home /
Instantiate a class
Hi,
I really don't get it. I have a GameObject with 10 childs. Each Child has the same script (name: Bar) attached (the childs are prefabs). The parent has the script Foo attached.
Foo -> parent script Bar -> Child script
Now I want to instantiate Foo within Bar so I can "pass" events like OnMouseDown(); from the child to the parent.
But how? How? ...
Does Unity really create a GameObejct for every little thing? Why the heck does it create a GameObject for scripts? I mean, it's a nice feature that you can attach it and all that but why am I being forced to use it?
There must be a way to just link scripts together without dynamically create gameObject all the time and blast your code.
So, what's the most basic way to instantiate a class which extends MonoBehaviour?
And why do the docs explain what inheritance is but not how it works in Unity? Or am I blind? Oh and I don't want sound rude, I'm just wondering.
Thanks
Your answer
Follow this Question
Related Questions
Behind the scenes voodoo w/ Instantiate 2 Answers
The type 'myclass' does not have a visible constructor that matches the argument list 1 Answer
Can I call a class's method which inherit monobehaviour by a normal class? 0 Answers
Different sons of inheritance or a different parameter in construction 1 Answer
Instantiating a class 1 Answer