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 /
  • Help Room /
avatar image
0
Question by ChristianBlandford · May 05, 2014 at 04:56 PM · javascriptarrow-keys

Switching camera code not working

I have a code to switch cameras when you press the arrow left, it takes you to camera 2, and when you press the right again, it takes you to camera 1.

it doesn't work when you press the right arrow? why??

 var Camera1 : GameObject;
 var Camera2 : GameObject;
 
 function Start(){
     Camera1.active = true;
      Camera2.active = false;
 }
 
 function Update(){
       if ( Input.GetKey(KeyCode.LeftArrow)){
     Camera1.active = false;
     Camera2.active = true;
        if ( Input.GetKey(KeyCode.RightArrow)){
       Camera1.active = true;
        Camera2.active = false;
         }
     }
 }
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

4 Replies

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

Answer by ChristianBlandford · Dec 30, 2015 at 01:54 PM

Turns Out Unity Didn't like The Actual number 1 in the variable, so i had to do it like "CameraOne"

Doh

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 Godnonot · May 06, 2014 at 06:45 PM

Try

 Camera1.gameObject.active = true;
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 Swaggre · May 06, 2014 at 07:06 PM

Do

 Camera1.SetActive(true);

And so on

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 ChristianBlandford · May 06, 2014 at 07:45 PM 0
Share

no, it still doesn't work when i press the right arrow

avatar image
0

Answer by KelvinWright · Dec 30, 2015 at 03:36 PM

 var Camera1 : GameObject;
 var Camera2 : GameObject;
 var CamSwitch  = false;
 
 function Update()
 {
     if(Input.GetKey(KeyCode.LeftArrow))
     {
         CamSwitch = true;
     }
     if(Input.GetKey(KeyCode.RightArrow))
     {
         CamSwitch = false;
     }
     if(CamSwitch  == true)
     {
         Camera1.SetActive(false);
         Camera2.SetActive(true);
     }
     if(CamSwitch == false)
     {
         Camera1.SetActive(true);
         Camera2.SetActive(false);
     }
 
 }


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

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

Related Questions

Speed Increase Power up 1 Answer

what does this error mean? javascript 0 Answers

Tree Chopping/Harvesting cooldown 0 Answers

Any way to use UI on a screen renderer? 0 Answers

Please help me with my mouse pointer 0 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