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 IanElinon · Mar 21, 2013 at 10:17 AM · cameramouseclickthird person shooter

Change Camera on (Right) Mouse Click

Hello, I need help on this one. I'm trying to make a TPS. One of the basic features is if you hold RMB, the camera is switched to another camera. Now, I'm very bad at coding so I'll need your help. Would you kindly...?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Freaking-Pingo · Mar 21, 2013 at 01:26 PM

Could this code be useful?

 public Camera camera1;
 public Camera camera2;
     
 void Update(){
     if (Input.GetMouseButtonDown(1)){ 
          camera1.gameObject.active = false;
          camera2.gameObject.active = true;
     } else 
     {
          camera1.gameObject.active = true;
          camera2.gameObject.active = false;
     }
 }

Then you just have to assign camera1 and camera2 in the inspector on the object you assign this script on.

Comment
Add comment · Show 5 · 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 IanElinon · Mar 21, 2013 at 02:30 PM 0
Share

It was useful, but where do I apply the script? I applied it to both cameras and set the same components. the game launches fine but when i click R$$anonymous$$B, it turns to camera 2 for a split second, then back to camera 1.

avatar image VivekD · Mar 21, 2013 at 02:41 PM 0
Share

That's because the Input.Get$$anonymous$$ouseButtonDown(1) only returns true if the right mouse button is held down constantly. Try this :

 if(Input.Get$$anonymous$$ouseButtonDown(1)){ 
 camera1.gameObject.active = false;
 camera2.gameObject.active = true;
 } else if(Input.Get$$anonymous$$ouseButtonDown(0))
 {
 camera1.gameObject.active = true;
 camera2.gameObject.active = false;
 }

Edit : Now that I look at your question the code by @Freaking-Pingo is actually correct. You said that you wanted the camera to shift only on holding down the R$$anonymous$$B.

avatar image IanElinon · Mar 21, 2013 at 02:51 PM 0
Share

Thanks for the help, guys, I appreciate it a lot. Though, a final question, what gameobject do I put the script to? I hope I'm not being a bother.

avatar image VivekD · Mar 21, 2013 at 03:13 PM 0
Share

Add the script for both cameras. Also use this code for initializing the camera objects :

 camera1 = GameObject.Find(<Insert Camera 1 Gameobject Name>).GetComponent<Camera>();
 camera2 = GameObject.Find(<Insert Camera 2 Gameobject Name>).GetComponent<Camera>();
avatar image Freaking-Pingo · Mar 21, 2013 at 03:32 PM 0
Share

It is not necessary to do what @VivekD mentioned, if you just assign the values in the inspector.

1: Attach your script to any gameobject on the scene 2: Select the game object you attached your script to 3: To the right in the inspector, you can see your script. Underneath that script you can see two grey boxes, with a little circle on the right. Click this circle and select your cameras, or you can simply drag and drop your cameras from the scene on top of those grey boxes.

alt text

unavngivet.png (4.8 kB)

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

12 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

Related Questions

Switching cameras with the click of the mouse 1 Answer

Camera Orbit on Left Click problem 0 Answers

Strange Camera Behavior on iOS - Runs perfect in Unity 0 Answers

Can't shoot towards mouse click point 1 Answer

Right Mouse Click in Android 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