- Home /
Grenade Damage in Radius
Hello, I've hit a bit of a wall with the game I'm making. I'm trying to add a grenade but my code doesn't work. Unity just tells me"BroadcastMessage BombDamage has no receiver" and I can't figure out the problem. Here's the codes: //This is on the bomb's Explosion prefab after it's been thrown and detonated
Bomb:
function Update () {
Die();
}
function Die () {
yield WaitForSeconds(2.0);
Destroy(gameObject);
}
function OnTriggerEnter(other: Collider) {
other.BroadcastMessage("BombDamage");
}
//And here's the Important bit from the enemy's script:
function BombDamage () {
health -= 100;
}
The BroadcastMessage should send to the enemy's script through the explosion's collider(which is just a retextured, animated sphere)
Help would be appreciated! Thanks!
Answer by timsk · Oct 10, 2011 at 07:12 PM
try this:
function OnTriggerEnter(other: Collider)
{
other.BroadcastMessage("BombDamage", 100);
}
function BombDamage(damage : float)
{
health -= damage;
}
let me know how it goes! :)
also, as a comment. You seem to being calling function Die every frame?
Yeah, oops about the Die function. But the BombDamage wouldn't be Broadcasted if it destroyed itself too soon, but then I wouldn't even get an error, so that can't be the problem. Also, the code didn't work, but thanks for trying. I really do want to figure this out though.
:O just found your comment, sorry i assumed it was fixed.
What exactly isn't working with my code? Any compiler errors? is nothing happening at all? is the wrong thing happening?
Your answer
Follow this Question
Related Questions
How do I destroy all enemy game objects with a bomb? 2 Answers
C# Grenade Explosion in Radius 1 Answer
Need to Find the Radius of an Object? 2 Answers