- Home /
Physical Representations of a Class (Most likely simpler than it sounds)
Hi, all!
I have a class called Enemy, with just a few variables like HP, movement speed, etc.
I have a script that spawns enemies currently by simply Instantiate()-ing a supplied prefab (for testing purposes). Well, it is all time to tie that together, but now I am slightly confused.
How do I make it so that when I spawn a new instance of the Enemy class, it will spawn a physical enemy as well in the constructor that is connected to all of its variables and can be used as a reference to the new instance of that class? I have tried Instantiate, but as the script is just a container for a class, there is no gameObject to instantiate it :/
Thanks!- YA
Answer by cgcookie · Jan 07, 2013 at 01:10 AM
Hi YA, There is a number of scripts here on unity answers for enemy spawning, This one may be of use to you: http://answers.unity3d.com/questions/244772/first-game-game-manager-question-spawning-enemies.html
We also cover spawning objects/enemies several times in our tower defense series. http://cgcookie.com/unity/2012/06/04/unity-tower-defense-tutorial-part-02-sam-turret/
I hope this helps!
All though helpful, this isn't quite what I was looking for. In fact, my spawning script greatly resembles the one supplied all ready.
What I am wondering is how to spawn a physical enemy on the creation of a new object of a class
Your answer
![](https://koobas.hobune.stream/wayback/20220613090521im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
UnityScript equivalent to C# Action 1 Answer
Code compilation error 1 Answer
Best way to place a Line Renderer into scene... 1 Answer
How to fix code errors? 1 Answer
Play Audio While Button is Held Down 1 Answer