Search Unity

Can someone convert this code for touch ? I want to do the exact thing but in touch for android

Discussion in 'Scripting' started by dungen_aditya, Jan 24, 2018.

  1. dungen_aditya

    dungen_aditya

    Joined:
    Jan 23, 2018
    Posts:
    3
    using UnityEngine;
    using System.Collections;

    public class test : MonoBehaviour {

    public float speed=4f;
    public Rigidbody2D rb;
    private float movement=0f;
    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update()
    {
    movement=Input.GetAxis ("Horizontal")*speed;
    }

    void FixedUpdate()
    {
    rb.MovePosition (rb.position + new Vector2 (movement, 0f));
    }
     
  2. Dave-Carlile

    Dave-Carlile

    Joined:
    Sep 16, 2012
    Posts:
    967
  3. TaleOf4Gamers

    TaleOf4Gamers

    Joined:
    Nov 15, 2013
    Posts:
    825
    We are not here to write code for you. Here is a link to the docs which may help you.
    https://docs.unity3d.com/ScriptReference/Input.GetTouch.html
    https://docs.unity3d.com/ScriptReference/Touch.html
     
  4. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    ... and even if we were, you've not provided enough information. The code you've posted depends on a keyboard or controller input, which doesn't exist in touch, so how did you want it to work? swipes, on screen keypad, tap to move... loads of ways of making movement scripts for touch. Have a think about what it is you are trying to do, have a google around to look at touch movement scripts (loads of example code out there already), if you get stuck, we can help with specific issues you have in your attempt.

    If scripting isn't your thing and you want someone else to do the scripting, there is always the unity connect: https://connect.unity.com/
     
    TaleOf4Gamers likes this.