- Home /
Question by
rockyourteeth · Feb 24, 2014 at 04:52 AM ·
sendmessagemethodargument
Error Using "0" as an argument in "SendMessage"
I have a method in "script_cameraControl" that looks something like this (this is just a simplified version. This is C# code):
void SetCameraTo(int camPreset)
{
print (camPreset);
}
Then another class, "script_positionReaderRemote" trying to use "SendMessage" to call it with the argument of the int "0", because there are 4 cameras, "0", "1", "2", "3":
GameObject.FindGameObjectWithTag("MainCamera").SendMessage("SetCameraTo", 0);
When I set the argument to 1, 2, or 3, I get no problems, but when I set it to 4, I get this error:
Calling function SetCameraTo with no parameters but the function requires 1. UnityEngine.GameObject:SendMessage(String, SendMessageOptions) script_positionReaderRemote:BlockHasBeenChosen() (at Assets/scripts/script_positionReaderRemote.cs:127) UnityEngine.GameObject:SendMessage(String) script_blockSelect:Update() (at Assets/scripts/script_blockSelect.cs:38) It appears to think that "0" is not an argument, even though I want to pass in the integer "0" as an argument. Any ideas on why this isn't working? Thanks!Failed to call function SetCameraTo of class script_cameraControl
Comment
Best Answer
Answer by whydoidoit · Feb 24, 2014 at 05:13 AM
I think it thinks you are trying to pass 0 as the SendMessageOptions - so be explicit.
GameObject.FindGameObjectWithTag("MainCamera").SendMessage("SetCameraTo", 0, SendMessageOptions.RequireReceiver);