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 ardizzle · Oct 25, 2014 at 11:30 PM · c#cameraenabled

camera.enabled = true not working?

I have a game where the play switches between many cameras. When the player presses an arrow key the script is suppose to disable all cameras and then enable the one the player wanted to go to. The problem is that the cameras are all staying kinda disabled. They don't become active during game play, so the player is just starting at a blank screen. But the code says the camera is enabled. I know this because I have it print the camera the player is on which is checked by the if(camB4.enabled == true) print(camB4.name); So what is going on?

The code is quite long and complex so I will just post where i think the problem lies and if you need more let me know. The code is in C#. This swaps the camera:

 void changeCamera(Camera cam)
     {
         camA3.enabled = false;
         camA4.enabled = false;
         camB2.enabled = false;
         camB3.enabled = false;
         camB4.enabled = false;
         camB5.enabled = false;
         camC1.enabled = false;
         camC2.enabled = false;
         camC3.enabled = false;
         camC4.enabled = false;
         camC5.enabled = false;
         camC6.enabled = false;
         camD1.enabled = false;
         camD2.enabled = false;
         camD3.enabled = false;
         camD4.enabled = false;
         camD5.enabled = false;
         camD6.enabled = false;
         camE2.enabled = false;
         camE3.enabled = false;
         camE4.enabled = false;
         camE5.enabled = false;
         camF3.enabled = false;
         camF4.enabled = false;
         mainCam.enabled = false;
 
         cam.enabled = true;
         print("Your current camera is: " + cam.name);
     }

And this is what happens when a player hits an arrow key. I am just showing one interlocked if statement. There are many.

 void moveCamera(string direction)
     {
         //Changes current camera
         if(camA3.enabled == true)
         {
             if(direction == up)
             {
                 print("invalid move");
             }
             else if(direction == down)
             {
                 if(A3B3 == false)
                 {
                     A3B3 = true;
                     changeCamera(camB3);
                 }
                 else
                 {
                     print("That wall has been used already");
                 }
             }
             else if(direction == left)
             {
                 print("invalid move");
             }
             else if(direction == right)
             {
                 if(A3A4 == false)
                 {
                     A3A4 = true;
                     changeCamera(camA4);
                 }
                 else
                 {
                     print("That wall has been used already");
                 }
             }
         }//END A3
 }

Thanks for the help!

Comment
Add comment · Show 5
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 MrSoad · Oct 26, 2014 at 12:35 AM 0
Share

Do you need all these cameras? What I mean is if I want lots of camera positions I line up my camera, create a correctly orientated empty at this position, then do this for all my positions, then simply switch where the camera is placed. If you want these positions to move you have the empty move via parenting/code and when you switch the camera position you parent it to the empty and set rotation and position to be the same as the empty's. ???

avatar image ardizzle · Oct 26, 2014 at 02:16 AM 0
Share

The person asking me to write it wants all the cameras. But I figured out what I needed to do. I just changed all the cam.enables to cam.gameObject.SetActive(true);

avatar image bubzy · Oct 26, 2014 at 07:47 AM 1
Share

you need to learn about arrays.

avatar image fafase · Oct 26, 2014 at 07:59 AM 0
Share

As mentioned above, here is what it would look like with array:

 [SerializeField] private Camera[]camArray;
 private Camera activeCam;
 void ChangeCamera(Camera cam)
 {
     foreach(Camera c in camArray){
         c.enabled = false;
     }
     Camera c = Array.Find(camArray, p => p == cam);
     c.enabled = true;
     activeCam = c;
 }
avatar image ardizzle · Oct 26, 2014 at 10:18 AM 0
Share

Thanks for the advice.

0 Replies

· Add your reply
  • Sort: 

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

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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Why isnt renderer.isVisible not working? 1 Answer

How can I display text so that it can be see on the Vive Headset? 0 Answers

Camera issue (storing temp variable C# problem) 3 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