I’ve been trying to get multiple arguments to work with SendMessage but keep getting an error. BCE0024: The type ‘DamageInfo’ does not have a visible constructor that matches the argument list ‘(int, String)’.
Not sure what I’m doing wrong.
My Class
class DamageInfo {
var damage : int = 0;
var spellType : String = "";
function damageInfo ( damage : int, spellType : String ) {
damage = damage;
spellType = spellType;
}
}
My SendMessage. Where the error is occurring.
SendMessage("damagePlayer", new DamageInfo(Random.Range(15,20), "melee"));
#pragma strict
public class TestScript2 extends MonoBehaviour
{
function Start()
{
var ts:TestClass2 = new TestClass2();
ts.i = 15;
ts.s = "my test string";
SendMessage("TestMethod", ts);
}
function TestMethod(ts:TestClass2)
{
Debug.Log(ts.i + " " + ts.s);
}
}
public class TestClass2
{
public var i:int;
public var s:String;
}
hmmm… good point. My line up there got rid of the error message you mentioned in the first post but then caused another error due to what you just said. Maybe using GetComponent would be easier and also allow you to send multiple arguments? Kind of like shown here: http://forum.unity3d.com/threads/180328-SendMessage?p=1234891&viewfull=1#post1234891
It looks like my constructor wasn’t named the same as my class and the variables needed to be a different name. Got it all working now. Thanks for the help!