Tag Info

New answers tagged


Put safe that in Unity the suggested/best way of managing collision is using Unity colliders. Let's follow your aproach. As the max numbers of enemies and bullets you may have at the same time and the dimension of your map grows, you may consider managing your enemies and bullets not in single list but in a Geometric hashing structure. Here you find a ...


Don't keep a list of enemies. Make your health script generic. So when bullet hits a gameobject tagged "enemy", you can call like: if(hittedCollider.gameObject.tag == "enemy") { hittedCollider.gameObject.GetComponent<HealthManager>().AddDamage(damageAmount); } (this is an example of course, names are up to your decision)


In my experience, the structure you use should always be the least abstract (most understandable) that you can come up with, in a way that is also efficient. Think hard about the physics behind what you're trying to achieve. What should the bullet know about it's environment? What does the enemy need to know? How does the interaction take place? Now there ...


or is there any other better ways of doing? What is your metric for "better"? Setting aside the comments on the question that "it isn't the Unity way", both of your approaches are just fine. Another option is to pass in IEnemyManager (an interface or superclass of EnemyManager) to each Bullet, which exposes some but not all features of EnemyManager. ...

Top 50 recent answers are included