im trying to do this but i get a err. so is this correct
gameObject.BroadcastMessage ("ApplyDamage", 5.0 , 90);
function ApplyDamage (damage : float , TimeToHeal : float) {
print (damage);
print (TimeToHeal);
}
im trying to do this but i get a err. so is this correct
gameObject.BroadcastMessage ("ApplyDamage", 5.0 , 90);
function ApplyDamage (damage : float , TimeToHeal : float) {
print (damage);
print (TimeToHeal);
}
What’s the error?
Failed to call function ApplyDamage of class Player land
Calling function ApplyDamage with 1 parameter but the function requires 2.
UnityEngine.GameObject:BroadcastMessage(String, Object, SendMessageOptions)
Player land:Main() (at Assets/scrips/player/Player land.js:3)
It looks like you can only pass one object to the function using BroadcastMessage. Maybe use a Vector2 or array to pass the variables to ApplyDamage.
This isn’t pretty, but something like this should work:
gameObject.BroadcastMessage ("ApplyDamage", Vector2(5.0, 90));
function ApplyDamage (inputs : Vector2) {
Debug.Log("Damage: " + inputs.x);
print ("TimeToHeal: " + inputs.y);
}
i have done this be for but i cant remember how i did it. owell thanks for the help. ![]()
There may be another way. I tried using Vector2 it worked for me. Here’s a little test project I made: http://acceleroto.com/share/broadcast_test.zip
The BroadcastMessage is in GameController.js. The broadcast happens whenever you hit an arrow key.