- Home /
Send Message Not sending
I have my 2 scripts. 1 sends a message Apply Damage when it collides with the trigger. but the goblin I'm fighting does not receive any damage.
attack script
function OnTriggerEnter(other : Collider)
{
SendMessage("ApplyDamage", Dammage, SendMessageOptions.DontRequireReceiver);
Debug.Log("HI");
}
Enemy Script
function ApplyDamage()
{
animation.Play("block_hit");
animation.Stop("attack1");
chasing = false;
Hurt = 2;
Health -= Wscript.Dammage;
Debug.Log("Enemey Hit");
yield WaitForSeconds(DammageDelay);
Hurt = 1;
}
Answer by WilliamLeu · Jul 22, 2014 at 07:29 PM
Like sethuraj said, the function template doesn't match. Either get rid of the Dammage (typo?) in SendMessage, or add a damage float parameter for ApplyDamage().
Also, the attack script is sending the message to itself. You probably meant to call other.SendMessage so that the Enemy script gets the message and not the attack script.
Its perfectly acceptable to send parameters that are not received in Send$$anonymous$$essage. Check out the documentation.
The receiving method can choose to ignore the argument by having zero parameters.
Answer by Kiwasi · Jul 23, 2014 at 04:16 AM
The key here is you are calling the message on the current GameObject, not the enemy. Try the following:
other.gameObject.SendMessage("ApplyDamage", Dammage, SendMessageOptions.DontRequireReceiver);
Your answer
Follow this Question
Related Questions
Repeating Damage sendMessage 1 Answer
on collision damage 1 Answer
Gameobject not registering collisions 1 Answer
Melee Damage script by collision 2 Answers