Jump to content
  • Advertisement
Sign in to follow this  
Line

Unity Can anyone tell me what code to use in Unity for touch buttons in Android?

This topic is 994 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Can anyone tell me what code to use in Unity for touch buttons in Android?

 

i have made a directional pad. 4 arrow buttons. Up, down, Right, Left.

 

i brought the 4 image arrows in as canvas image elements names UpImage, DownImage, RightImage and LeftImage. I put the target on them and applied a button component to them.. but i just don't know how to code them to work with touch on android to do the the same functions as the pc keys counterpart (if you were playing on pc ):

using UnityEngine;
using System.Collections;

public class Player : MonoBehaviour
{
    public float SPEED = 0.25f;
    void FixedUpdate()
    {
        var pos = transform.position;

        if (Input.GetKey(KeyCode.LeftArrow)) { pos.x -= SPEED; }
        if (Input.GetKey(KeyCode.RightArrow)) { pos.x += SPEED; }
        if (Input.GetKey(KeyCode.UpArrow)) { pos.y += SPEED; }
        if (Input.GetKey(KeyCode.DownArrow)) { pos.y -= SPEED; }

        transform.position = pos;
    }
}

Can you assist?

 

Thanks so much

 

-Line

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!