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 TheRedRabbit · Nov 19, 2014 at 09:34 AM · c#androidcontrols

Replace float v=Input.GetAxis("Vertical") with touch?

Hey community,

currently I´m working on a mobile Legend of Zelda clone and got the controls on the pc going. But I have trouble porting it to android. Please help!

Now I want to replace the w,a,s,d respectively the arrow keys with 4 virtual guiTexture buttons.

I got this code on the sprite of the main charater:

 public class playerController : MonoBehaviour { 
 
     public float Speed = 2;
     Animator anima;  
 
     void Start () { 
         anima = GetComponent<Animator>();
         Label.SetActive(false);
     } 
 
     void Update () { 
         float v = Input.GetAxis("Vertical"); 
         float h = Input.GetAxis("Horizontal");
         float s = Input.GetAxis("Space");
         ManageMovement(h, v, s);
     } 
 
     void ManageMovement(float horizontal,float vertical,float fight) { 
         if (horizontal != 0f || vertical != 0f) { 
             anima.SetBool ("moving", true); 
             animateWalk (horizontal, vertical);
         } 
         else {
             anima.SetBool ("moving", false);
         }
 
         if (fight != 0f) {
             anima.SetBool ("fighting", true);
             animateFight (horizontal, vertical);
         }
         else {
             anima.SetBool ("fighting", false);
         }
 
         Vector3 movement = new Vector3 (horizontal,vertical, 0); 
         rigidbody2D.velocity = movement * Speed; 
     } 
 
     void animateWalk(float h,float v) { 
         if(anima){ if ((v > 0)&&(v>h)) { 
                 anima.SetInteger ("Direction", 1);
 
             } 
         if ((h > 0)&&(v<h)) { 
                 anima.SetInteger ("Direction", 2); 
             }
         if ((v < 0)&&(v<h)) { 
                 anima.SetInteger ("Direction", 3); 
             } 
         if ((h < 0 )&&(v>h)) { 
                 anima.SetInteger ("Direction", 4); 
             }
         } 
     }
 
     void animateFight(float h,float v) {
         if(anima){ if ((v > 0)&&(v>h)) { 
                 anima.SetInteger ("Direction", 1);
                 
             } 
             if ((h > 0)&&(v<h)) { 
                 anima.SetInteger ("Direction", 2); 
             }
             if ((v < 0)&&(v<h)) { 
                 anima.SetInteger ("Direction", 3); 
             } 
             if ((h < 0 )&&(v>h)) { 
                 anima.SetInteger ("Direction", 4); 
             }
         } 
     }
 } 

Thanks very much for your time, answers and help!

Comment
Add comment · Show 3
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 koray1396 · Nov 19, 2014 at 12:18 PM 0
Share

for start;

 if(Input.touches.Length > 0)//or == 1? that's your call.
     for(int i = 0; i < Input.touches.Length; i++){
         if(GUITexture.HitTest(Input.GetTouch(i).position){
              //your methods...
         }
     }
 }

you can also check touchphase to see if it began or ended, and tweak actions.

avatar image TheRedRabbit · Nov 19, 2014 at 12:48 PM 0
Share

thanks for your help. At first I tried solving ist by taking the position of the virtual joystick and using tht as input.

avatar image meat5000 ♦ · Nov 19, 2014 at 01:16 PM 0
Share

For Android, give up on Input manager and use the Touch methods.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Jittery movement of sprite on device 1 Answer

How to make a menu like ironpants 0 Answers

What is the best way to understand code in a project with null documentation? 2 Answers

how to make high quality textures with low size of downlaod 1 Answer

Distribute terrain in zones 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