I’m creating a mobile game that the user has to tap the screen to move the object/character. Right now I’m using mouse input to test the game play and haven’t gotten far in development, just getting the input down but I can’t seem to figure it out. When I press play then click on the screen, the object moves to the clicked position but leaves a trail of self clones and it continues to do it every time I click. Help is greatly appreciated.
public class PlayerInput : MonoBehaviour
{
private Vector3 target;
public float speed = 1.5f;
// Use this for initialization
void Start ()
{
target = transform.position;
}
// Update is called once per frame
void Update ()
{
if (Input.GetMouseButtonDown(0))
{
target = Camera.main.ScreenToWorldPoint(Input.mousePosition);
target.z = transform.position.z;
//Debug.Log("TAP!!!");
}
gameObject.transform.position = Vector3.MoveTowards(transform.position, target, speed * Time.deltaTime);
}
}