- Home /
 
               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
              
 
               
              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.
thanks for your help. At first I tried solving ist by taking the position of the virtual joystick and using tht as input.
For Android, give up on Input manager and use the Touch methods.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                