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 RickHurd · Jan 11, 2014 at 06:52 AM · androidcameracontrols

Switching from 3rd person to 1st person (Android)

Hey all,

I was wondering if anyone had an idea for me to switch from 3rd person camera to 1st person camera and vice-versa. I'm using Android so my controls will be based on touch.

Something that I'm trying to keep in mind is that when the character is in 3rd person, the controls will be based on UI surrounding the character. In 1st person the UI controls will only be rotation on either side of the screen.

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
Best Answer

Answer by Nick4 · Jan 11, 2014 at 07:57 AM

 var fpsCamera : Camera;
 var thirdPersonCam : Camera;
 var switchEnabled : boolean = false;
 
 function Update(){
 
        if (Input.touches.Length > 0)
     {
             for(int i = 0; i<Input.touchCount; i++)
             {
                     if(this.guiTexture.HitTest(Input.getTouch(i).position))
                     {
                 
                           if (switchEnabled == false)
                           {
                               fpsCamera.enabled = false;
                               thirdPersonCam.enabled = true;
                               switchEnabled = true;
                           }
         
                           else
                           {
                               mainCamera.enabled = true;
                              thirdPersonCam.enabled = false;
                              switchEnabled = false;
                              }
                     }
             }
     }
 }

Attach this to the gui texture you want to switch cameras with and attach your cameras to these variables. That should do it. Not tested but let me know what's wrong if it doesn't work. Good luck.

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 Nick4 · Jan 11, 2014 at 08:02 AM 0
Share

And sorry about that weird look. This website's code input doesn't allow me to shape it properly.

avatar image RickHurd · Jan 17, 2014 at 04:43 AM 0
Share

This seems to not work.. I tried suiting it to my needs but I'm having an issue with this part.

 for(int i = 0; i<Input.touchCount; i++)
             {
                     if(this.guiTexture.HitTest(Input.getTouch(i).position))

Unity is having a trouble with (i),int,getTouch, and, Position. I'm a bit confused as to why to be honest.

avatar image RickHurd · Jan 19, 2014 at 05:00 AM 0
Share

Grrr having issues all over the place....

 #pragma strict
 
 
 var firstPerson : Camera;
 var thirdPerson : Camera;
 var Active : boolean = false;
  
         function Update()
         {
             if(Input.GetTouch == false)
                 {
    
            firstPerson.enabled == false;
            thirdPerson.enabled == true;
            Active == true;
                     }
         
             else if(Input.GetTouch == true)
                     {
                        firstPerson.enabled == true;
                        thirdPerson.enabled == false;
                        Active == false;
                                 }
 
 }

Not sure why unity is having an issue with my script, seems I'm either missing something or ... I'm not sure actually...

Assets/3rdto1st.js(14,37): BCE0034: Expressions in statements must only be executed for their side-effects.

Assets/3rdto1st.js(15,24): BCE0034: Expressions in statements must only be executed for their side-effects.

Assets/3rdto1st.js(21,61): BCE0034: Expressions in statements must only be executed for their side-effects.

Assets/3rdto1st.js(22,48): BCE0034: Expressions in statements must only be executed for their side-effects.

I left the HitTest because it was having an issue with int and (i) for some reason..

avatar image RickHurd · Jan 19, 2014 at 05:38 AM 0
Share

ok so i found out i was using == ins$$anonymous$$d of =. so there arent any errors, however the gui does nothing when i touch it on my tablet. any ideas?

avatar image RickHurd · Jan 24, 2014 at 02:33 AM 0
Share

$$anonymous$$y uncle helped me and we figured it out !!

Here is my script for anyone reading my questions.

 #pragma strict
 
 var firstPerson : Camera;
 var thirdPerson : Camera;
 var useThirdPerson = false;
 private var oldUseThirdPerson;
 private var touched = false;
 
 function UpdateCameras()
 {
      firstPerson.enabled = !useThirdPerson;
      thirdPerson.enabled = useThirdPerson;
 }
 
 function CheckTouch() {
   // Assume the screen is not touched
   touched = false;
 
   // Are any fingers on the screen
   if (Input.touchCount > 0) {
      touched = true;
   }
 }
 
 function Start()
 {
    UpdateCameras();
 }
 
 function OnGUI() {
    
     if (GUI.Button(Rect(1100, 40, 80, 80), "SwitchCam")) {
       useThirdPerson = !useThirdPerson;
     }
 
     // Only update if things have changed.
     if (useThirdPerson != oldUseThirdPerson)
     {
        oldUseThirdPerson = useThirdPerson;
        UpdateCameras();
     }
 }


Hope it helps you guys, Happy Unity'ing

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

19 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

Related Questions

Android H/w Camera Button 1 Answer

Control the camera with a half of the touch screen 0 Answers

Phone camera autofocus 0 Answers

Smooth Follow Camera Rotate on Z-Axis? 2 Answers

Movement object same distance as touch movement 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