I am trying to figure out how to implement touchscreen for android. I want to be able to tap the left hand of the screen to go left while achieving the same type of movement I currently have and tap the right side of the screen to go right with the same type of movement I currently have.
The code I am using for player movement is:
using UnityEngine;
using System.Collections;
public class movement : MonoBehaviour
{
public Vector2 leftForce = new Vector2(-5, 5);
public Vector2 rightForce = new Vector2(5, 5);
// Update is called once per frame
void Update()
{
// Jump Left
if (Input.GetKeyDown("a"))
{
GetComponent<Rigidbody2D>().AddForce(leftForce, ForceMode2D.Impulse);
}
//Jump Right
if (Input.GetKeyDown("d"))
{
GetComponent<Rigidbody2D>().AddForce(rightForce, ForceMode2D.Impulse);
}
The code I have for movement is very simple, but I haven’t been able to find the right tutorial that explains how to add touch functionality that uses this same type of code.
Thank you all for your time!