- Home /
SendMessage handled by one method in different components
Hi,
I've problem with SendMessage and I'm trying to find best solution:
I've one script AnimateScript.cs which contains both sending and receiving methods: SendMessage("Animate"); and void Animate() {}
The problem is that the same script is attached to many GameObjects so many times Animate() is being called. In theory. In practice only one time Animate() is being called from the same instance of script which is sending message. What may I do to be able to trigger the same method, which is in one script attached to different GameObjects simultaneously ?
How do you decide to call the Send$$anonymous$$essage? Is it a collision?
No collision. Just when object moves to position X, Y, Z I'm sending message. Only the same component, which sends this messages responses (however this script is attached to other components too).
Answer by lighting · Aug 20, 2012 at 11:54 AM
No, it's not collision. I've moving object on screen. Thus I've condition:
if (newPosition.x >= x_end && newPosition.z >= z_end) { Debug.LogWarning("SENT: "+transform.name); SendMessage("AnimFinished", transform.name, SendMessageOptions.DontRequireReceiver); }
and later: void AnimFinished(string previousName) { Debug.LogWarning("RECEIVED: "+transform.name); }
This is being attached to different GameObjects on screen. SENT and RECEIVED is logged only once.