Hello
Im using a fairly simple script, where when any enemy hits with a OnTriggerEnter the player (or the enemy) takes damage, however, the script is fixed to 10 damage always.
How can i make so that every enemy can deal its damage and not always a static 10.
I tought of using a public variable on each enemy, but i have no clue how to reference that variable, most tutorials or questions just allow for a -system- to damage a or be damaged, but not how to assign a different damage for every enemy.
I saw a solution to just try to put a public variable to reference the enemy, but that would be extremely heavy if i want to reference 50+ enemies i think.
This is the part of my playerhealth script where i take damage if enemyweapon collides with player.
You should have a script on the enemy for how much damage it deals. Then on the OnTriggerEnter, you can get that enemies script and pull that value to apply the damage.
Or, could have the enemy call a DealDamage method on the player and pass in the damage it is doing.
that’s exactly what i want to do but i dont know how to do it
i created the enemyStrength variable, but i have no idea how to make the playerhealth script read that variable value.
Something along those lines. Again, this is pretty common and should be easy to find better examples. This is from the player side, but you might have the weapon do a check if it hit the player and deals damage instead of having the player retrieve damage.
If you’re getting a null error on line 9, it means it’s not finding the EnemyAttack script on “other”. So you’ll need to make sure your components are properly attached, otherwise depending on how you have it setup you might have to use the other GetComponent calls.
Yay, thanks! i needed to use the GetComponentInParent (since the ontrigger was checking for the boxcollider on the attacker’s fist!)
Thank you man!!!