I just finished the survival shooter tutorial for Unity so I decided to add some items of my own, such as a grenade. But can anyone help me script the grenade to damage the enemies. I have already scripted it to spawn on throw and destroy after a couple of seconds, but I really need to know how to damage the enemies.
if you have the grenade landing then exploding. have wee read over
Physics.OverlapSphere
Looking at the documentation it appears to return a list of colliders that are within its radius. then if you know the gameobjects that are inside the collision sphere then you may be able to call the TakeDamage() function on the enemy.
worth a look to see if it does what your looking for, not used it myself tho so cant really say more sorry, but it may be a step in the right direction ![]()
EDIT: and after a coffee and reading again, it doesnt test the actual collider, but a bounding box approximation, but it does say in this forum post that if your already using sphere or box colliders it should work ok. heres the post for some more info
thanks for the help, it really means a lot for a beginner @OboShape
hey no worries, as we’ve all been there, and I’m not long started myself so I’m glad to give back to the community anything I’ve learned over the course ![]()