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 Damich123 · May 20, 2013 at 08:11 PM · camerarotatetoggle

How to change camera when mouse button is clicked?

I have multiple camera attached to separate empty game objects that surround the player. I want the camera to switch in order when the user presses the middle mouse button. However unity is not recognizing any of the objects in my scene. I'm guess I am forgetting to call something. Any help would be great!

 //Player is the gameObject which holds the camera
 Player.camera.active = false;
 var CameraNum : int;
 CameraNum = 0;
  
 
 function Update ()
 {
   if(Input.GetMouseButtonDown(2))
       {
             CameraNum+=1;
             Debug.Log ("You hit middle mouse button");
       }
   if(CameraNum == 1)
       {
           //CameraOne is an empty game object that is paired with a camera
           CameraOne.camera.active = true;
           Debug.Log ("Camera One active");
       }
   if(CameraNum == 2)
       {
           //CameraTwo is an empty game object that is paired with a camera
           CameraOne.camera.active = false;
           CameraTwo.camera.active = true;
           Debug.Log ("Camera Two active");
           
       }
   if(CameraNum == 3)
       {
           //CameraThree is an empty game object that is paired with a camera
           CameraTwo.camera.active = false;
           CameraThree.camera.active = true;
           Debug.Log ("Camera Three active");
       }
 }
Comment
Add comment · Show 4
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 ExTheSea · May 20, 2013 at 08:18 PM 0
Share

Change the camera.active to camera.enabled

avatar image Damich123 · May 21, 2013 at 01:59 PM 0
Share

That was much easier, thank you.

avatar image TheRichardGamer · May 21, 2013 at 02:27 PM 0
Share
 Here, this should work:
 
     
     //Player is the gameObject which holds the camera
         
             //This is a list of all the cameras
             var CameraOne : Camera;
             var CameraTwo : Camera;
         var CameraThree : Camera;
             var PlayerCamera : Camera;
             //This defines the PlayerCamera (to define player camera, find the player's camera under the Player(First Person Controller or third) and drag the camera into the object holding the script )
             PlayerCamera.enabled = false;
             var CameraNum : int;
             CameraNum = 0;
          
          
             function Update ()
             {
               if(Input.GetButtonDown("<your_key_here>"))
            {
                  CameraNum ++ 1;
                 Debug.Log ("You hit middle mouse button");
         }
             if(CameraNum == 1)
                 {
                  //$$anonymous$$ake a camera called CameraOne, same for Two and Three
                  CameraOne.camera.enabled = true;
                  Debug.Log ("Camera One active");
                 }
           if(CameraNum == 2)
             {
                  //$$anonymous$$ake a camera called CameraTwo, same for One and Three
              CameraOne.camera.enabled = false;
              CameraTwo.camera.enabled = true;
                  Debug.Log ("Camera Two active");
          
             }
               if(CameraNum == 3)
                 {
                  //$$anonymous$$ake a camera called CameraThree, same for One and Two
              CameraTwo.camera.enabled = false;
         CameraThree.camera.enabled = true;
          Debug.Log ("Camera Three active");
             }
     
          if(CameraNum > 3){
             //This resets the camera number variable every time the variable is greater than 3
             CameraNum == 1;
     
     
     
         }
     
     
         }
     
 
 
avatar image ExTheSea · May 21, 2013 at 04:09 PM 0
Share

@TheRichardGamer: I already said the thing with enabled and active.

@Damich123: Is your problem solved now because if that's the case i would convert my comment to an answer so that you can accept it to mark the question as solved.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Mannis · May 20, 2013 at 08:51 PM

Have you considered using a single camera, and applying new positions/rotations on each MMB click?

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 TheRichardGamer · May 21, 2013 at 02:15 PM

Modify your inputs to be for example "MiddleMouse" to be the middle mouse button by going into Edit > Project Settings > Input, and then modify all your inputs. Then once you have done that you can just replace if(Input.GetMouseButtonDown(2)) to if(Input.GetButtonDown("")) That would make things a bit easier. And also change the active term to enabled = true or = false depending on what you would like to activate/deactivate. I hope this helps :)

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

18 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

Related Questions

Move character in direction its facing 1 Answer

Make camera rotate don't stop 1 Answer

How to make the camera rotate only when right click is held down on the mouse? 1 Answer

Camera rotate - point and click game 1 Answer

Global Fog, rotating the camera by itself 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