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

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));
}

Using Code Tags Properly

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

… 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/

1 Like