- Home /
How to detect if camera is touching a gameobject ?
I want to detect and generate an event if the camera is touching a game object in first-person view. (for example, if I moved the camera and it hit cube) it should play audio.
Answer by TheTrueDuck · 3 days ago
Hi! Just put a box collider (or any type of collider really) onto your camera. Then you can put a script onto your camera which will test if it's intersecting other colliders.
void OnCollisionEnter(Collision collision) { if (collision.gameObject.name == "MyGameObjectName") { Debug.Log("Do something here"); } }
P.S depending on whether or not you want to allow you camera to go through objects, you may want to switch the camera collider to IsTrigger and check for OnTriggerEnter.
Your answer
Follow this Question
Related Questions
Collisions with CharacterController? 0 Answers
Collision problem Ignorecollision 2 Answers
Sequencing Spawning for Multiplayer 1 Answer
Allow one object to pass through another whilst keeping collisions. 1 Answer
Detecting a string of collisions 2 Answers