Skip to main content
added 15 characters in body
Source Link
Emad
  • 1.1k
  • 2
  • 14
  • 22

You can achieve this by adding colliders to your object and camera.

  • preferably set the camera collider isTrigger on if the object is a rigid body.
  • You can use tags, layers and game object name to filter which object you want to operate on.

Here is the code:

[RequireComponent(typeof(Collider))] public class FrustomColliderDetector : MonoBehaviour { //Gets called when it enters the camera collider private void OnCollisionEnter(Collision other) { if(other.gameObject.tag == "object-tag") other.gameObject.SetActive(true); } //Gets called when it leaves the camera collider private void OnCollisionExit(Collision other) { if(other.gameObject.tag == "object-tag") other.gameObject.SetActive(false); } } 

You can achieve this by adding colliders to your object and camera.

  • preferably set the camera collider isTrigger on if the object is a rigid body.
  • You can use tags, layers and game object name to filter which object you want to operate on.

Here is the code:

[RequireComponent(typeof(Collider))] public class FrustomColliderDetector { //Gets called when it enters the camera collider private void OnCollisionEnter(Collision other) { if(other.gameObject.tag == "object-tag") other.gameObject.SetActive(true); } //Gets called when it leaves the camera collider private void OnCollisionExit(Collision other) { if(other.gameObject.tag == "object-tag") other.gameObject.SetActive(false); } } 

You can achieve this by adding colliders to your object and camera.

  • preferably set the camera collider isTrigger on if the object is a rigid body.
  • You can use tags, layers and game object name to filter which object you want to operate on.

Here is the code:

[RequireComponent(typeof(Collider))] public class FrustomColliderDetector : MonoBehaviour { //Gets called when it enters the camera collider private void OnCollisionEnter(Collision other) { if(other.gameObject.tag == "object-tag") other.gameObject.SetActive(true); } //Gets called when it leaves the camera collider private void OnCollisionExit(Collision other) { if(other.gameObject.tag == "object-tag") other.gameObject.SetActive(false); } } 
Source Link
Emad
  • 1.1k
  • 2
  • 14
  • 22

You can achieve this by adding colliders to your object and camera.

  • preferably set the camera collider isTrigger on if the object is a rigid body.
  • You can use tags, layers and game object name to filter which object you want to operate on.

Here is the code:

[RequireComponent(typeof(Collider))] public class FrustomColliderDetector { //Gets called when it enters the camera collider private void OnCollisionEnter(Collision other) { if(other.gameObject.tag == "object-tag") other.gameObject.SetActive(true); } //Gets called when it leaves the camera collider private void OnCollisionExit(Collision other) { if(other.gameObject.tag == "object-tag") other.gameObject.SetActive(false); } }