hii
In my game i have been added some cameras to get extra effect,but i dont know
how to make the camera function automatically when the player comes near to it.
help me…
THANKING YOU.
1 Answer
1The easiest way is to add a trigger volume to each camera, and use OnTriggerEnter to activate the camera and OnTriggerExit to deactivate it: click the camera and add a spherical collider to it (menu Component/Physics/Sphere Collider), then in the Inspector / Sphere Collider set Is Trigger and adjust the Radius to cover the volume you want. Finally, attach this script to the camera:
function Start(){
camera.enabled = false;
}
function OnTriggerEnter(other: Collider){
if (other.CompareTag("Player")){ // remember to tag the player as "Player"
camera.enabled = true; // enable camera
}
}
function OnTriggerExit(other: Collider){
if (other.CompareTag("Player")){
camera.enabled = false; // player out of range - disable camera
}
}
If there are overlapping regions, more than one extra camera may be active at the same time; you may use each camera’s Depth value to define a “priority”: the camera with higher Depth will be rendered over the others (default Depth = 0).
I tryed it but its not working... is there any other option.
– Dee_VaThank you very much aldonaletto,it's working
– Dee_Va