Buttons switch cameras
I have 2 cameras and 2 buttons(for each cameras)
I had moved the First cam for a distance.
If i clicked the Second cam Button now, the First cam should reset and go to its original position.
The same vice versa for the other cam. If i clicked the First cam Button, the Second cam should reset and go to its original position.
Answer by OrbitGames · May 19, 2016 at 01:17 PM
You need two Transform varibles, which contain the default position of the cameras. You could set those in the start function. Then, if you click button 1, enable camera 1, disable camera 2 and set its transform to the one you saved earlier. If you click button 2, do the opposite.
Hope this helps
Thanks @OrbitGames. I got theoritically cleared. But i lack coding knowledge. That part i missed to mention. Could you provide me script for that?
Here are some code snippets: First we'll need some variables
public Camera cam1;
public Camera cam2
Transform cam1Pos;
Transform cam2Pos;
you need to set the first cameras in the inspector. you can set the default positions in your start function:
cam1pos = cam1.transform;
cam2pos = cam2.transfrom;
After that, you need it to work with the cameras. So we need to create two functions, which you need to hook up to your buttons onClick in the inspector.
public void activateCam1(){
cam1.active = true;
cam2.active = false;
cam1.transform = cam1pos;
}
public void activateCam2(){
cam2.active = true;
cam1.active = false;
cam2.transform = cam2pos;
}
I'm not sure which camera you want to reset to the starting position, but you should be able to change the two lines of code by yourself. Code is untested, but should work In case you don't know where to put the code, and you haven't started a script yet, you can create a new one, and put it on an empty gameobject.
Thanks @OrbitGames. I will Implement your code to my program.
Your answer
Follow this Question
Related Questions
Rotate Camera around fixed point in specified increments (Bonus: How could I lerp this?) 0 Answers
Custom geometry image hover 0 Answers
My lights don't work with On Click() when I click the button. 1 Answer
Following an old touch tutorial, having errors with deprecated code 1 Answer
How to make button rotate when another button is pressed? 0 Answers