Is it possible to send more than one parameter for calling a function when using send message?
By itself, SendMessage can acceppt one and only one object as a parameter to a function.
However, that object can be just about anything.
-
Example: you can send an array as a parameter, allowing (in theory) infinite parameters stored inside that array
-
Another Example: You can create a custom class that does nothing but hold the data you want to send as parameters
Exmaple of another example:
public class DamageParams
{
public var damage : float = 0.0;
public var type : int = 0;
public var source : NetworkPlayer = Network.player;
//constructor
function damageParams( damage : float, type : int, source : NetworkPlayer)
{ this.damage = damage; this.type = type; this.source = source; }
}
Elsewhere on a monobehaviour:
function dealDamage( other : GameObject )
{ other.SendMessage( "takeDamage", new DamagePrams(10, 2, Network.player) ); }
var FIRE_DAMAGE : int = 3
var FALL_DAMAGE : int = 2;
function takeDamage( params : DamageParams )
{
if(params.type != 3)
health -= params.damage;
}