- Home /
Switch Camera On Button Press?
I have a sniper rifle which is a child object of the main camera on fps controller and then I have a camera which is a child object of the sniper rifle. What I want to do is when you click the right mouse button, you go from looking through the main camera to looking through the other camera, and when you click the right mouse button again you switch back to looking through the main camera. Can anyone help me with this?
Answer by syclamoth · Oct 28, 2011 at 12:40 PM
Twist answer- only have one camera!
Then, have two transforms which are managed separately- one on the scope, and one for the main character. Treat these transforms the same way you would use a camera in terms of movement etc., and then when you want to change camera, do this-
Camera.main.transform.parent = transformYouWantToChangeTo;
Camera.main.transform.localPosition = Vector3.zero;
Camera.main.transform.localRotation = Quaternion.identity;
Can you explain how you've been working with unity for any amount of time without knowing what a Transform is?
oh right I thought it was something else, sorry about that.
How do I add another transform? Please help
Only one transform per object, sorry. On the other hand, if you create a new 'empty' object, it comes with a Transform as a free bonus!
Answer by oxium · Oct 29, 2011 at 01:13 AM
use a lerp: http://unity3d.com/support/documentation/ScriptReference/Quaternion.Lerp.html
and assign the result quaternion to your camera
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Camera follow help? 1 Answer
you leave a question by pressing a button? 3 Answers
Play sound on button press? 1 Answer
Camera Following Rigidbody 0 Answers