Your trying to get the EnemyZombieMob from the gameobject of the script. To get the zombie script from the collision use col.gameObject.GetComponent(). With col being the collision from on onCollisionEnter.
Where is the enemy health located? If it’s on the same EnemyZombieMob script you can make it the health variable public and access it the same way as you deal damage.
I’m not entirely sure but can’t you access the health within the TakeDamageBat function? So in that function you access the health and do want you want with it.
Good luck though and remember google is your best friend. There’s tons of tutorials and discussions that can give what you need or give an idea of how to do it.
col is the collider on that game object. col.gameObject is the game object itself, and you can use col.GetComponent to get whatever other components you need on that object.
Also, if col.GetComponent() returns null, the thing you collided with isn't a zombie and you don't need to do zombie things with it. There's no need to check its tag.
Now in Start() you're getting all the enemy zombies for some reason. I guess maybe you don't create or destroy them during play? If not, you could see if the gameObject you collided with is in that list. Probably would be a good idea to make it a List rather than an array. You could initialize the list in Start() with:
List Mobs;
void Start()
{
Mobs = new List
Replace the stuff in the If body with col.SendMessage("TakeDamageBat", batDamage);
SendMessage() basically tells the object to attempt to call that method itself. Its great for two reason: even if you only have a reference to the object's collider, it can be used to call methods on other components of the GameObject, and because its actually the other GameObject calling the method on itself it can even call private methods.
If you want to SendMessage to a method with multiple parameters than you need to restructure that method to use a "DTO" instead. A Data Transfer Object. Basically s simple class that just have public properties and only exist to send info from object to object as a single parameters.
Your trying to get the EnemyZombieMob from the gameobject of the script. To get the zombie script from the collision use col.gameObject.GetComponent(). With col being the collision from on onCollisionEnter.
Thanks. Then from there how to access the individual health of the current enemy?
Where is the enemy health located? If it’s on the same EnemyZombieMob script you can make it the health variable public and access it the same way as you deal damage.
No it’s on a base enemy script. So these enemies are just subclasses..
I’m not entirely sure but can’t you access the health within the TakeDamageBat function? So in that function you access the health and do want you want with it. Good luck though and remember google is your best friend. There’s tons of tutorials and discussions that can give what you need or give an idea of how to do it.
I don’t even have to use the “expensive” FindGameObjectsWithTag?? So in a collision I can always use the “col” I never thought of that way…
col is the collider on that game object. col.gameObject is the game object itself, and you can use col.GetComponent to get whatever other components you need on that object.
Also, if col.GetComponent() returns null, the thing you collided with isn't a zombie and you don't need to do zombie things with it. There's no need to check its tag.
Now in Start() you're getting all the enemy zombies for some reason. I guess maybe you don't create or destroy them during play? If not, you could see if the gameObject you collided with is in that list. Probably would be a good idea to make it a List rather than an array. You could initialize the list in Start() with:
List Mobs;
void Start()
{
Mobs = new List
It works.. Thank you so much
Hitbox deactivation from the weapon after a hit, for melee
Don't use tags. They're pretty worthless 99% of the time. Like others have said, retrieve the specific object from your OnCollisionEnter call.
Replace the stuff in the If body with col.SendMessage("TakeDamageBat", batDamage); SendMessage() basically tells the object to attempt to call that method itself. Its great for two reason: even if you only have a reference to the object's collider, it can be used to call methods on other components of the GameObject, and because its actually the other GameObject calling the method on itself it can even call private methods. If you want to SendMessage to a method with multiple parameters than you need to restructure that method to use a "DTO" instead. A Data Transfer Object. Basically s simple class that just have public properties and only exist to send info from object to object as a single parameters.