x


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

more ▼

asked May 16 '12 at 04:43 PM

oliver-jones gravatar image

oliver-jones
2.5k 206 226 254

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

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);
more ▼

answered May 19 '12 at 09:14 PM

Eric5h5 gravatar image

Eric5h5
80.3k 42 132 521

(comments are locked)
10|3000 characters needed characters left

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).

more ▼

answered May 19 '12 at 08:19 PM

OrangeLightning gravatar image

OrangeLightning
5.4k 47 57 112

(comments are locked)
10|3000 characters needed characters left

Im not sure but i think you could send a List or an Array with SendMessage

more ▼

answered May 19 '12 at 09:04 PM

NiteFlamesInc gravatar image

NiteFlamesInc
42 3 7 10

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x294
x185
x45

asked: May 16 '12 at 04:43 PM

Seen: 830 times

Last Updated: May 19 '12 at 09:17 PM