SendMessage ReceiveDamage has no receiver!
UnityEngine.Component:SendMessage (string,object)
Weapon:OnCollide (UnityEngine.Collider2D) (at Assets/Scripts/Weapon.cs:56)
Collidable:Update () (at Assets/Scripts/Collidable.cs:27)
Weapon:Update () (at Assets/Scripts/Weapon.cs:28)
[Error Image][1]
[Weapon Code Part 1][2]
[Weapon Code Part 2][3]
[Collide Code][4]
[1]: https://i.stack.imgur.com/fisCm.png
[2]: https://i.stack.imgur.com/V7HDO.png
[3]: https://i.stack.imgur.com/2nNHe.png
[4]: https://i.stack.imgur.com/3jr7U.png
I have tried using base . Update(); and just copy pasting the code but the error still shows up. I'm very new to game development and can't figure this out.
CodePudding user response:
This error means that no object is receiving the message you sent, because you are sending it through "coll", which is a Collider2D
. You have to send it through the GameObject like this:
coll.gameObject.SendMessage("ReceiveDamage", dmg);
For this to work, the collided GameObject (which in this case is a "Fighter") must have a script attached to it that also has a function called ReceiveDamage
.
You can learn more about this here: https://docs.unity3d.com/ScriptReference/GameObject.SendMessage.html
CodePudding user response:
I figured it out.... I had put the enemy script on both the enemy and the enemies hitbox, removing it from the hitbox fixed the issue.