- Home /
Trying to send message with 2 variables, but getting error.
So I am sending this message.
SendMessage ("Event", Player , 0);
To this function.
function Event ( Player : Transform, Direction : int)
And getting this error
Failed to call function Event of class EventControllerBasic Calling function Event with 1 parameter but the function requires 2. UnityEngine.Component:SendMessage(String, Object, SendMessageOptions) EventCollider:Update() (at Assets/BlaBla)
Answer by Huacanacha · Mar 31, 2015 at 12:16 AM
http://docs.unity3d.com/ScriptReference/GameObject.SendMessage.html
SendMessage doesn't support calling methods with more than 1 parameter. If you need two variables wrap them in a class or struct that you can pass as a single parameter.
Did this work for you? Here is an example:
public class PlayerDirection {
public Transform transform;
public int direction;
public PlayerDirection(Transform t, int d) {
transform = t;
direction = d;
}
}
...
Send$$anonymous$$essage("Event", new PlayerDirection(Player, 0));
...
public void Event(PlayerDirection playerDirection) {
...
This is C# rather than Unityscript but the concept is the same for both.
Your answer
Follow this Question
Related Questions
Similar scripts but error on one and not the other 1 Answer
Script is causing immense lag, and I don't know what's causing it. 2 Answers
Assets/Editor/UpdateTreeColors.js(13,17): BCE0031: Language feature not implemented: UnityEditor. 1 Answer
[SOLVED] Help with PlayerPrefs.SetInt 1 Answer
Trouble making money system 1 Answer