- Home /
Is this how you enemy instance.
So, I am trying to make a 2d top down game but I am having a problem with gameobjects all deleting etc... Also there are different enemies but how do I make them seperate entities and only kill one at a time.
So I guess my main question is for static is it for individual gameobject only or is private?
If you want this question answered, you HAVE to rewrite it with better English and better description of your problem.
Answer by Kiwasi · Nov 08, 2014 at 04:09 AM
Best advice for beginners is don't use static. The main reason is pretty evident from your problem. There are other hidden evils of static variables.
There is no task in Unity that can't be done without static variables. Once you understand how to get a project complete without using any static variables, then you can consider how and where to implement them.
Answer by kburkhart84 · Nov 08, 2014 at 04:39 AM
Your problem is likely stemming from the use of "static" which can indeed be evil. As a quick description, it kind of forces there to be only one of something. For example, if you have a static variable in a class, and you have multiple instances of that class, there would only be one of that static variable, and in any instance in which you modify that variable it will be modified in all of the instances.
What you are looking for are prefabs. You can have a scene open, create your enemy, bullet, whatever, and then store it in a prefab. You can then take that prefab and duplicate it easily in all of your different scenes via the editor, and you can also call Instantiate() to create duplicates at run-time, useful for shooting bullets from your guns for example as the bullet would likely be a prefab.
Another very good benefit of prefabs is that as long as you don't break the connection(won't happen unless you force it to break), anytime you change the prefab(or an instance when you send the changes back to the prefab) will get sent to all of the copies of the prefab automatically.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Generating Game Objects on random positions (2D) 1 Answer
where to trigger which collision event? 1 Answer
How I make my enemy face the player or flip towards player (top-down game)? 0 Answers
GameObject with SpriteRenderer either on top of everything or not showing 0 Answers