I am trying to call a method of a script attached to a different object. I have the following code, and I've attached the object to the localPlayerObject variable in the inspector, but I am still getting an error saying there is no receiver.
I tried Debug.Log(localPlayerObject.name); and it gave me the correct name, so I know I am referencing it correctly. And yes, StartSending is declared in the other script:
asked Apr 13 '10 at 08:57 PM
The only way I can see that wouldn't work is if the object you dragged onto the
answered Apr 13 '10 at 09:11 PM
This probably is no necessary any more but here is what I found, having the same problem.
Theory: To send a message you receiver should be in the game object as the one you are sending it. It would look useless but the whole idea is to add scripts to an object without bothering about references, so different script doing different things having a function with the same name can be attached and remove to the same object on different times during runtime. Component.SendMessage
The problem: Since you are just sending a message but your receiver is in another game object, its impossible for the message to be receive across game objects.
of course this could lead to calling all the functions with that name
hope this help anyone,
As far as I can see, what you have - as written - should work. This means the problem must be somewhere else, presumably in how you have your objects and scripts set up in the hierarchy.
Hm, I've just seen Eric5h5's answer and he's probably right! :-)
answered Apr 13 '10 at 09:15 PM