Send Message (27423)

//weapon script code
function OnCollisionEnter(other : Collision) { if (other.relativeVelocity.magnitude > 2) SendMessage("GetTotalDmg",Damage); }

what the above code does is send info about the weapon to the monster that is being struck.
I’m a bit unsure if I am doing this right, as it doesn’t really work so I assume I’m having issues sending the message properly(since all the functions work properly, tested wit variables).
Any help would be appreciated.

2 Answers

2

It sounds like you are messaging the wrong object. If this script is on your weapon, then you want to call this:

//weapon script code
function OnCollisionEnter(other : Collision)
{
    if (other.relativeVelocity.magnitude > 2)
    other.collider.SendMessage("GetTotalDmg",Damage);
}

I've tried that. It calls an error saying that send message isn't a part of collision. this.SendMessage() works, but still, no result seems to show up, the function doesn't even get called.

Fixed it.

What do you mean Fixed it?

@emeraldreamer: He has edited his answer because his code example was wrong and now it's right ;)

Or you try

other.gameObject.SendMessage("GetTotalDmg", Damage);

I’m pretty sure an object of type Collision does not have any means of receiving or calling the SendMessage function.

Tried that Also. doesn't work -_- Blah I'm at a total loss. I'mma start at the basics. Tyvm.