Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by FlammingFart · Dec 29, 2012 at 12:53 PM · cameracamera.main

how to switch camera

im thinking of 2 cameras on my player.. the main camera and the camera itself. then the main camera is of course on the head, facing front. and the other camera is right at the top, facing the top view of the player.

how to switch camera when the player dies.. does it requires to be in script? if it requires a script, where do i put the script?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Fattie · Dec 29, 2012 at 01:35 PM 0
Share

FYI the simple answer is:

DISABLE ONE CA$$anonymous$$ERA, ENABLE THE OTHER CA$$anonymous$$ERA.

That's how you swap cameras in Unity.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by save · Dec 29, 2012 at 01:34 PM

Yes you would need a script to switch between cameras. The most convenient way of using a switch is to keep the objects you're switching between in an array. This also makes it easier if you want to be able to switch cameras at any point. This example switches when the player presses C and a quick example of how to use it on death and respawn:

 #pragma strict
 
 var cameras : Camera[]; //Assign your cameras here in Inspector
 private var audioListeners : AudioListener[];
 private var currentCamera : int = 0;
 
 function Start () {
     audioListeners = new AudioListener[cameras.Length];
     for (var i = 0; i<cameras.Length; i++)
         audioListeners[i] = cameras[i].GetComponent(AudioListener);
     SwitchCamera(0, true);
 }
 
 function Update () {
     if (Input.GetKeyDown(KeyCode.C)) SwitchCamera(1, false);
 }
 
 function SwitchCamera (num : int, direct : boolean) {
     if (direct) currentCamera = num; else currentCamera=(currentCamera+num)%cameras.Length;
     for (var i = 0; i<cameras.Length; i++) {
         cameras[i].enabled = (i==currentCamera);
         audioListeners[i].enabled = (i==currentCamera);
     }
 }
 
 
 //Death function, for instance called when player's health reaches 0. Switches to camera 2
 function OnDeath () {
     SwitchCamera(1, true);
 }
 
 //Respawn function. Switches to camera 1
 function OnRespawn () {
     SwitchCamera(0, true);
 }

You could remove the toggle switch inside update and instead only use direct switches, if you have more cameras in your scene that should be triggered by certain events.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Piflik · Dec 29, 2012 at 01:09 PM

You can either use the depth value of a camera to control which one is seen (the camera with the highest depth value will override all others, because it is drawn last), but this will have a detrimental effect on your framerate, because everything will be rendered twice. Only use it if you need both cameras to be active at the same time.

The better option would be to deactivate all cameras except the one you want to use right now. (gameObject.SetActive(false);)

And yes, you would need a script for that. Put a script on the player with references to both cameras, and when he dies, you deactivate one and activate the other. For an even better effect, you could put the second camera to the same position/orientation as the first, and move it up slowly.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Keep character inside camera bounds 1 Answer

Having camera attack upon spawning player? 1 Answer

Camera zooming in and out 1 Answer

How do you force a player to look at something? 4 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges