x


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?

more ▼

asked Oct 28 '11 at 12:21 PM

Dreave gravatar image

Dreave
122 82 94 96

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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;
more ▼

answered Oct 28 '11 at 12:40 PM

syclamoth gravatar image

syclamoth
14.8k 7 15 80

can you explain what a transform is please?

Oct 28 '11 at 01:17 PM Dreave

Can you explain how you've been working with unity for any amount of time without knowing what a Transform is?

Oct 28 '11 at 11:48 PM syclamoth

oh right I thought it was something else, sorry about that.

How do I add another transform? Please help

Oct 29 '11 at 09:15 AM Dreave

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!

Oct 30 '11 at 02:44 AM syclamoth
(comments are locked)
10|3000 characters needed characters left

use a lerp: http://unity3d.com/support/documentation/ScriptReference/Quaternion.Lerp.html

and assign the result quaternion to your camera

more ▼

answered Oct 29 '11 at 01:13 AM

oxium gravatar image

oxium
181 6 8 10

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5081
x3738
x3003
x788
x40

asked: Oct 28 '11 at 12:21 PM

Seen: 1498 times

Last Updated: Oct 30 '11 at 02:44 AM