- Home /
Cameras not activating/deactivating
This is actually just an edit of my older question because I realized this is what was wrong with it. I have my movement script change to be relative to a certain camera depending what trigger it is in. However when I try to apply a similar effect to my camera to deactivate my third person camera and activate my first person camera it doesn't work. This is attached to just my third person camera:
var cameraInUse = "big"; //Private me!
var activatedCamera: Camera; //Private me!
var camera1 : Camera;
var camera2 : Camera;
function OnTriggerEnter (trigger : Collider) {
if (trigger.tag == "SmallCameraTrigger1"){
cameraInUse = "small";
Debug.Log("Small camera activated");
camera1.enabled = false;
camera2.enabled = true;
activatedCamera = camera2;
}
}
function OnTriggerExit (trigger2 : Collider) {
if (trigger2.tag == "SmallCameraTrigger1"){
cameraInUse = "big";
Debug.Log("Big camera activated");
camera1.enabled = true;
camera2.enabled = false;
activatedCamera = camera1;
}
}
Any insight will be appreciated, thanks!
Answer by Sundar · Sep 13, 2012 at 03:30 PM
Try this
var cameraInUse = "big"; //Private me!
//var activatedCamera: Camera; //Private me!
var camera1 : Camera;
var camera2 : Camera;
function OnTriggerEnter (other : Collider) {
Print( "Entered trigger" );
if (other.name == "Ball"){
cameraInUse = "small";
Debug.Log("Small camera activated");
camera1.gameObject.active = false;
camera2.gameObject.active = true;
//activatedCamera = camera2;
}
}
function OnTriggerExit (other : Collider) {
Print( "Exited trigger" );
if (other.name == "Ball"){
cameraInUse = "big";
Debug.Log("Big camera activated");
camera1.gameObject.active = true;
camera2.gameObject.active = false;
//activatedCamera = camera1;
}
}
Thanks, but sadly it doesnt work; the same as before happens which is nothing, neither camera activates or deactivates on entry or exit of the trigger. The trigger is tagged "SmallCameraTrigger1" and the two cameras are assigned correctly in the editor
Do you get debug message "Small camera actvated" and "Big camera activated" in console when you move in and out of trigger?
Nope, I did notice that previously but I cant see any reason why they shouldn't. Screen cap of trigger properties: http://img542.imageshack.us/img542/2871/74477248.jpg
and this is my movement switching, which does work:
function OnTriggerEnter (trigger : Collider) {
if (trigger.tag == "SmallCameraTrigger1"){
activeCamera = "small";
}
}
function OnTriggerExit (trigger2 : Collider) {
if (trigger2.tag == "SmallCameraTrigger1"){
activeCamera = "big";
}
}
function Update(){
if(Input.Get$$anonymous$$ey($$anonymous$$eyCode.UpArrow) && activeCamera == "big"){
rigidbody.AddTorque(large_camera.transform.right * 2);
}
else{
if(Input.Get$$anonymous$$ey($$anonymous$$eyCode.UpArrow) && activeCamera == "small"){
rigidbody.AddTorque(small_camera.transform.right * 2);
}
}
//-------------------------------------------------------------
if(Input.Get$$anonymous$$ey($$anonymous$$eyCode.DownArrow) && activeCamera == "big"){
rigidbody.AddTorque(large_camera.transform.right * -2);
}
else{
if(Input.Get$$anonymous$$ey($$anonymous$$eyCode.DownArrow) && activeCamera == "small"){
rigidbody.AddTorque(small_camera.transform.right * -2);
}
}
I have edited my code check and see it works, if not - post console window snap shot. - tell me where you attach this script. - remove one audio listener from a camera - also check out how to use triggers from http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$onoBehaviour.OnTriggerEnter.html
Runtime console log; as you can see there is nothing on there at all :S http://img823.imageshack.us/img823/7167/40440768.jpg
If you could suggest a better way to do it I could completely overhaul my code >_< EDIT: sorry I was proving a friend wrong and posted the wrong link ^^'
Your answer
Follow this Question
Related Questions
How does Clear Flags on cameras work? 2 Answers
Can't see a flare from above? 0 Answers
Game view always 2x size of Screen? 1 Answer
Sprite prefab instances only render when camera is selected? 0 Answers
transformDirection goes to zero as I look upwards. 0 Answers