Hello everyone. I am developing a 2D game in unity 5. In my game there is one quad (this is my player) and PlayerMove script attached to it.
What I want is when the player touch the right side of the screen, my object start moving to the right direction smoothly and when the user touch the left side of the screen the object start move to the left direction of the screen smoothly.
Need any kind of help
Here is my PlayerMove script but it doesn’t work as I want.
using UnityEngine;
using System.Collections;
public class MoveScript : MonoBehaviour {
public float PlayerMoveSpeed;
void Start () {
}
void FixedUpdate () {
for (int i =0; i<Input.touchCount; i++) {
Touch touch = Input.GetTouch(i);
if (touch.position.x < Screen.width/2)
{
transform.Translate(Vector3.left * Time.deltaTime * PlayerMoveSpeed);
}
if (touch.position.x > Screen.width/2)
{
transform.Translate(Vector3.right * Time.deltaTime * PlayerMoveSpeed);
}
}
}
}