Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
1
Question by Chrifoldus · Apr 04, 2010 at 12:41 AM · cameraswitchkeymain

Main Camera Switch?

Hi Everyone, I've lately Been making an FPS Game, and There are two Cameras, One Camera is FPS and one is Third Person, I've seen Collider changes on other questions and I'm like What? So Is there a Way I Can Trigger a Camera Switch through a Binded Key?

Thanks everyone

Comment
Add comment
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

3 Replies

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

Answer by Jason_DB · Apr 04, 2010 at 01:09 AM

You can activate and deactivate cameras if you can get a hold of the object that holds them.

//cameraObject is the gameObject which holds the camera

cameraObject.camera.active = false;

So If you had a script which kept track of all the cameras in your scene then you could switch cameras easily. For example here is a function which would go through an array of camera objects and turn a certain one on (based on the index sent to it).

var cameras : GameObject[];

function SelectCamera (index : int) { for (var i : int=0 ;i<wcameras.length; i++) { // Activate the selected camera if (i == index){ cameras[i].camera.active = true; // Deactivate all other cameras }else{ cameras[i].camera.active = false; }

}

You could use this function by calling it with a message

BroadcastMessage ("SelectCamera", 1);

or by outright calling it

SelectCamera(1);

You just need to get hold of the instance of the script it's in

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
1

Answer by Narven · May 02, 2010 at 06:40 AM

You can use something like

public Camera backCamera;
public Camera topDownCamera;

in the update...

if (Input.GetKey(KeyCode.Alpha1)) { driverCamera.camera.active = false; topDownCamera.camera.active = true; }

 if (Input.GetKey(KeyCode.Alpha2))
 {
     topDownCamera.camera.active = false;
     backCamera.camera.active = true;
 }

}

Comment
Add comment · Show 1 · 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 Chistabo · Dec 18, 2014 at 04:02 PM 0
Share

Using this answer brought a loud smile on my face (that is, I vote Up, but can not - reputation issue). using UnityEngine; using System.Collections;

 public class Fader : $$anonymous$$onoBehaviour {
     public GameObject extraCamera;
     void Start() {
         Rect currentRes = new Rect(-Screen.width * 0.5f, -Screen.height * 0.5f, Screen.width, Screen.height);
         guiTexture.pixelInset = currentRes;
         extraCamera.camera.enabled = false;
     }
 }
 

Then I simply 'attached' (drag&drop) my secondary camera ($$anonymous$$$$anonymous$$ap) from Hierarchy to Inspector of 'Fader' GameObject.

ThumbsUp

Simon

avatar image
0

Answer by Sebas · Apr 04, 2010 at 01:08 AM

Sure you can. The search function is your friend. See this Answer

If you combine this with pressing a key, you should be all set. If you want it to be more fancy and smoothly transition between both cameras, see this forum thread.

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

1 Person is following this question.

avatar image

Related Questions

How to set main camera? 3 Answers

object collision attatched to camera 1 Answer

Swapping Cameras Disables Keyboard Input 3 Answers

Cycle weapons with only ONE key press (spacebar) 2 Answers

Rotate Camera Around Player Key PresS 1 Answer


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