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
1
Question by rd42 · Jun 30, 2010 at 06:19 PM · cameratagsswitchlabel

Two cameras and switching

How do I set up a scene with two cameras that I will switch between and how do I reference them?

GameObject -> Create Other -> Camera -> then name the camera something like camera2.

Do I tag it too? and what do I tag it as? and how do I access it?

I've seen the following for accessing the main camera

Camera.main.enabled = false

If I create a new camera an name it camera2 can I just:

Camera.camera2.enabled = true

Thanks for any help!

Comment
Add comment · Show 3
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 rd42 · Jun 30, 2010 at 06:25 PM 0
Share

I found this: http://www.unifycommunity.com/wiki/index.php?title=SwitchCamera

but I'm not that clear on how Unity knows which is camera1 and which is camera2.

avatar image rd42 · Jun 30, 2010 at 06:29 PM 0
Share

Ok, in the inspector you can choose which GO camera goes with which var in the script that controls the cameras.

avatar image Ashkan_gc · Jun 30, 2010 at 06:43 PM 0
Share

you can answer your question yourself and even choose it as the best answer. you just can not vote for it.

2 Replies

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

Answer by Ashkan_gc · Jun 30, 2010 at 06:42 PM

first of all i should say enabling/disabling any component is possible by the enabled property. if you want to make objects (GameObjects) enabled/disabled use their active property instead. for referencing any object you can do different things:

  • use public variables and set them up in inspector
  • use GameObject.Find or Object.FindObjectsOfType. there are many different methods in these two classes that they do what you want in different ways(using tags, components or names).
  • set the variables of the manager object inside the objects that you want to reference. for example you can define a static list and tell each camera to add itself to the list in it's Awake function.
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 user-11096 (google) · Apr 21, 2011 at 02:10 AM

Well here is something that is really simple to do, to switch between cameras, this can also be used for aiming. Here it is, i can explain how it works at end of the code.

var camera1 : Camera;

var camera2 : Camera; private var startCamera : int = 1;

function Start () { camera1.enabled = true; camera2.enabled = false; startCamera = 1; }

function Update () { if(Input.GetKeyDown("f") && (startCamera == 1)) { startCamera = 2; camera1.enabled = false; camera2.enabled = true; } else if (Input.GetKeyDown("c") && (startCamera == 2)) { startCamera = 1; camera1.enabled = true; camera2.enabled = false; } }

ok the var camera1 = Camera; variable forces the slot to be a camera object the if and else if statements were checking if the key was pressed (you can change the key to anything you want), the && (startCamera == 2) (or startCamera ==1) makes the startCamera the second Camera. So thats why there is the camera_.enabled = true; (or) = false; there. You can keep this repettion when you play your game without needing to copy the gunction over and over again.

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

No one has followed this question yet.

Related Questions

Character movement when I switch cameras. 0 Answers

Switching cameras (JavaScript) 0 Answers

How to make camera position relative to a specific target. 1 Answer

Add multiple cameras problems 1 Answer

About Camera Change & switch GamePlay 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