Hey guys, currently I am making a game where you move a barrel to collect coins. I’m at the point of the game where I need to add in mobile input controls. I can move the player left and right using the keyboard but I am not sure how to do the same on mobile devices. I simply want my barrel to move when my player puts their finger on the barrel and moves it left and right to collect coins. I’ve looked up tutorials everywhere but can’t seem to find any that lets you follow the game object using your finger on the x axis.This is my first game, so I’m very new to touch controls.
I generally try to help out people who give me help by providing the script I’ve attempted. However, in this case I only have the keyboard controls script because I don’t know how to use touch for this problem.
using UnityEngine;
using System.Collections;
public class BarrelControlsScript : MonoBehaviour {
public float barrelspeed = 3f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
transform.Translate(Vector3.right * Time.deltaTime * Input.GetAxis("Horizontal") * barrelspeed);
}
}