- Home /
SendMessageUpwards - Send Multiple Parameters?
Hello,
I'm using the 'SendMessageUpwards', but the problem with that, is that I can only send one parameter to a function. Is there a way to send more than one?
Example:
hit.collider.SendMessageUpwards("ApplyDamage", (damage, weapon, angle), SendMessageOptions.DontRequireReceiver);
Thanks
Answer by Eric5h5 · May 19, 2012 at 09:14 PM
You can send an Object with SendMessage, and the object can be anything. I would advise not repurposing things like Vector3 for this, because that makes your code less understandable. (Even though it might be tempting to do that, take a minute and do it right instead; you will save much more than that later when you're not having to figure out what the heck x/y/z means in that context.)
class DamageInfo {
var damage : int;
var weapon : Weapon;
var angle : float;
function DamageInfo (damage : int, weapon : Weapon, angle : float) {
this.damage = damage;
this.weapon = weapon;
this.angle = angle;
}
}
...
SendMessageUpwards ("ApplyDamage", new DamageInfo(damage, weapon, angle), SendMessageOptions.DontRequireReceiver);
Answer by FLASHDENMARK · May 19, 2012 at 08:19 PM
Well, yes, to a certain degree that is.
You could just send a Vector3, like this:
var damage : float;
var weapon : float;
var angle : float;
hit.collider.SendMessageUpwards("ReceiveMessage", Vector3(damage, weapon, angle), SendMessageOptions.DontRequireReceiver);
And you would receive the message like this:
function ReceiveMessage (info : Vector3){
print("Damage = "+info.x+" Weapon = "+info.y+" Angle = "+info.z);
}
And of course you access the data just like you would with a normal Vector3(using its x, y and z values).
Answer by NiteFlamesInc · May 19, 2012 at 09:04 PM
Im not sure but i think you could send a List or an Array with SendMessage
Your answer
Follow this Question
Related Questions
SendMessage with multiple parameters 3 Answers
Handling multiple tags 1 Answer
SendMessage to multiple objects 2 Answers
UI Button multiple parameters 6 Answers