Reputation: 478
In a Unity scene I want two objects to communicate via SendMessage so I don't have to do GetComponent at runtime.
Here is the SendMessage call:
hit.transform.gameObject.SendMessage("OnSelect", SendMessageOptions.RequireReceiver);
And on another object (called Button) I have a script with this function:
public void OnSelect()
{
dialogueManager.DisplayDialogue(this);
}
When I play the game the OnSelect function runs without any problem and does everything it needs to do, but the console gives me the error 'Failed to call function OnSelect of class Button; Calling function with no parameters but the function requires 1.'
Why does it say the function requires 1 parameter when it actually requires none? Am I missing something?
Upvotes: 1
Views: 1496
Reputation: 519
Two things:
Unity's button class does already contain a function named "OnSelect" which does take one parameter. You can rename your function to something different https://docs.unity3d.com/530/Documentation/ScriptReference/UI.Selectable.OnSelect.html
SendMessageOptions should be the third parameter not the second. So the syntax should be something like:
hit.transform.gameObject.SendMessage("OnCustomHit", null, SendMessageOptions.RequireReceiver);
https://docs.unity3d.com/ScriptReference/GameObject.SendMessage.html
Upvotes: 1