How to trigger an event when camera collides with a gameobject or is near that gameobject ?
I am currently working with MRTK and I want to trigger an event (eg: play some sound) on when - the camera and game object (menu or button) are close enough - or when the camera transform is at the position of the game object I have attached a screenshot attached so you can get the idea When the cursor focuses on the button to click, there should be an event triggered, let's say play a sound until the camera and object transform are far away. I would really thank you guys for the help :)
Answer by jaca6767 · Jan 28 at 04:16 AM
If you want it to trigger once the object actually collides:
Add a collider to your camera, then use the function OnCollisionEnter in a script to trigger your actions. Set the collider size to your choice based on how far away you want it to trigger from.
If you want it based on a person focussing their sight on it:
Make a function to call a constant raycast. If a raycast hits an object, async call for a later function with a similar repeating raycast. If the raycast ever falls on another object during the timer countdown, recall the function and cancel the action. This is definitely more complex but easily achievable.
I can write code for either of these, just comment on the one that you want and I'll get right to it.
I would be very thankful if you can write the code for me, I've been stuck looking all over since I am inexperienced.
Answer by taimoor901 · Jan 28 at 10:03 PM
@jaca6767 Basically, I am trying to achieve a warning system in augmented reality, so it's like a marked area (danger zone) in which when a player (camera) enters or collides to its boundary it should trigger an event like showing a warning or playing a siren and similarly stop playing when it leaves the area. I will show you an example like the circle as a danger zone.
I am very glad to have a quick response from you and would really appreciate your help doing this. Thanks :)
Your answer

Follow this Question
Related Questions
CardBoard Project. Instatiate prefab don't interact with Player 0 Answers
gameObjects working in one scene, but none of the others? 1 Answer
How would I go about adding a tooltip to a Unity UI Image? 0 Answers
Adding a listener to bar's on a bargraph issue... 0 Answers
Animation won't stop (Solved) 2 Answers