- Home /
Findout if an object that was hit by raycast is still being hit (30 object that are instantiated)
Hello,
I have a massive number gun objects that are doing RayCasting (let's say 10) and also a massive number of target objects that are subject to be hit by the ray cast (let's say 30 of them) which are all instantiated, so I attached the same raycast code to each gun object.
Using the following method (SendMessage) I can tell exactly which objects are being hit by the Physics.Raycast and the code is attached to each of the targets.
//send a message
hit.transform.SendMessage("HitHappened",hit.transform.gameObject,SendMessageOptions.DontRequireReceiver);
Is there any way that I can find out if each target object is still being hit by the Raycast? In other words, I want to assign a Boolean variable to each target (by default are FALSE) and if they are being hit by Raycast, I change its value to TRUE, and then, if the object is not being hit by Raycast anymore, I want to change them back to False.
Using the SendMessage function, you can only do the first one (since it only tells you when Raycast Hit happens and not when it is over), and you can never change it back to false.
Could you please help me find a way?
Thank.