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 jaffy25 · May 12, 2014 at 01:08 AM · switchcamerasafter

Cannot switch cameras!!! Help ASAP!!!

Hi! I need to be able to switch between 4 cameras in my game. Here is my code:

 var cam1 : Camera;
 var cam2 : Camera;
 var cam3 : Camera;
 var cam4 : Camera;
 
 function Start () {
  cam1.enabled = true;
           cam2.enabled = false;
           cam3.enabled = false;
           cam4.enabled = false;      
 }
 
 
 
 function Update () {
  if(Input.GetKeyDown(KeyCode.A)){
           cam1.enabled = true;
           cam2.enabled = false;
           cam3.enabled = false;
           cam4.enabled = false;
           }
           
           if(Input.GetKeyDown(KeyCode.S)){
           cam1.enabled = false;
           cam2.enabled = true;
           cam3.enabled = false;
           cam4.enabled = false;
           }
           
           if(Input.GetKeyDown(KeyCode.D)){
           cam1.enabled = false;
           cam2.enabled = false;
           cam3.enabled = true;
           cam4.enabled = false;
           }
           
           if(Input.GetKeyDown(KeyCode.F)){
           cam1.enabled = false;
           cam2.enabled = false;
           cam3.enabled = false;
           cam4.enabled = true;
           }
 }

This does change the cameras, but after i stop playing the game! How can I have it so the change happens during the game? I have assigned the four cameras to the variables in the Unity GUI, but still nothing. The cameras are part of an object and are in the assets. I need help, my project is due Friday.

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 jacobschellenberg · May 12, 2014 at 01:26 AM 0
Share

After you stop playing the game? So you Play and press F, and nothing happens, but when you Unplay cam4 is suddenly the enabled one?

avatar image ninjapretzel · May 12, 2014 at 01:51 AM 0
Share

@jacobschellenberg The script seems to be working fine, and he even stated that it works when he's playing the game.

@jaffy25 If you are having questions about the editor's behaviour, and why a camera being enabled doesn't carry over when you stop the game, The editor automatically saves state of things when you hit play, when you stop the game, the editor will try to revert the state of everything to what it was when you hit play (position/rotation/scale, what objects exist where, what objects are attached to other objects as children, what behaviours are attached to those objects.)

When you hit stop, the Unity Editor is reseting the state of the cameras to what they were when play was hit.

avatar image SpaceSocks · May 12, 2014 at 01:54 AM 0
Share

I think hes saying in game the cameras are not changing while the game is playing.

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Bunny83 · May 12, 2014 at 02:26 AM

You have linked the camera instances of your prefab in those variables and you're probably instantiating that prefab at runtime. Now you enable / disable the cameras in your prefab but that won't change the actual game instance.

There are some ways:

  • Either have the object with the cameras already in the scene and link the for cameras to those instances

  • or if you need to instantiate the object at runtime, you have to setup the camera references manually through scripting.

  • Attach that script to the prefab itself so when the object is instantiated the prefab links are automatically "translated" to the new instances of the clone.

You can't reference the cameras on the prefan and expect that the cameras of an instance of that prefab would change at runtime since an instance is just a clone / copy of the prefab,

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

23 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

switch between multiple cameras based on distance to target 2 Answers

Multiple Camera Switching 1 Answer

Trouble switching cameras 1 Answer

cameras switch doesn't work 1 Answer

switch between cameras in javascript? 2 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