0
\$\begingroup\$

So, I need to switch/ move/ animate camera from point X (not point A,as I don't know where the camera is at that momemnt) to point B (place where you want your camera to move).

This is for cinematics...like when you press a button in game which does something (opens doors maybe) but you can't see where nor what did you activate, so you show the player with the camera where and what happened.

  1. I tried to animate camera to position, camera just goes crazy.
  2. Then I tried to make an empty object placed at the position where the camera should be and move camera with code to that objects position.
  3. I tried enabling Camera 2 and disabeling Camera 1 but it just doesn't work.

Enable/ Disable Code:

public var door: DoorAnim;

public var triggered : boolean = false;

function OnTriggerEnter() { triggered= true; }
function OnTriggerExit()  { triggered= false;}

function Update(){
    if (triggered && Input.GetKeyDown(KeyCode.JoystickButton1)){
            Debug.Log("Door 1 built");
            camera1 = GameObject.Find("Camera1");
            camera1.enable = false;
            camera2 = GameObject.Find("Camera2");
            camera2.enable = true;
            door= GameObject.Find("door1");
            door.animation.Play();

    }
\$\endgroup\$
  • \$\begingroup\$ "camera just goes crazy" means you didn't do it right. Not that the solution doesn't work. I'd use one camera only, and first apply a look at towards the door or whatever, then lerp the camera towards the position( if path finding isn't needed to get there, otherwise it could be a bit trickier ). Are you having trouble with the math? \$\endgroup\$ – Ben Sep 13 '14 at 15:00
  • \$\begingroup\$ I assume this is 3D game, right? \$\endgroup\$ – wondra Sep 13 '14 at 15:02
  • \$\begingroup\$ It is 3d game. I only need to switch the cameras...no need to show the player the path to it. Math is not the problem. The best way would be to enable/ disable camera. Please take a look on the code (I'll edit my question). \$\endgroup\$ – Samurai Fox Sep 13 '14 at 17:59
  • \$\begingroup\$ @Ben is right you should not 2 cameras for this. Are you getting some error or? have you tried disabling camera in the approach you mentioned using this docs.unity3d.com/ScriptReference/GameObject.SetActive.html ? \$\endgroup\$ – 2600th Sep 13 '14 at 19:41
  • \$\begingroup\$ @2600th Thanks! That worked. Write it as answer so I can mark it as correct ;) \$\endgroup\$ – Samurai Fox Sep 13 '14 at 20:23
0
\$\begingroup\$

In the approach you want to follow that is disabling other camera use GameObject.SetActive.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.