2D Diablo style movement

Hello everybody!

I’m using the following script grabbed from here: http://wiki.unity3d.com/index.php/Click_To_Move_C
This basically gives a very nice click to move control to my game, but I’ve got a problem with it. I’m making a 2D game for mobile, and for some reason it doesn’t work if I try to use it in a “2D environment” (I tried the script with perspective camera in 3d and it worked!).

I’ve been struggling for hours and since I’m beginner I don’t know how to modify this script to make it work. I basically have an ortographic camera, and a sprite on my scene which I attached the script onto. What else do I miss?

Thank you in advance!!!

Try using this script as your player controller. This works in my 2d game. I found it in the following tutorial Click To Move in Unity 5. The example he creates in the tut is for 3d but it worked for my 2d game. Good luck and hope this helps!

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[DisallowMultipleComponent]
public class ClickToMove : MonoBehaviour 
{

	[SerializeField] [Range(1,20)]
	private float moveSpeed = 5;

	private Vector3 targetPosition;
	private bool isMoving;


	// Use this for initialization
	void Start () 
	{
		targetPosition = transform.position;
		isMoving = false;
	}
	
	// Update is called once per frame
	void Update () 
	{
		if(Input.GetMouseButton(0))
		{
			SetTargetPosition ();
		}

		if(isMoving)
		{
			MovePlayer ();
		}

	}

	void SetTargetPosition()
	{
		targetPosition = Camera.main.ScreenToWorldPoint (Input.mousePosition);
		targetPosition.z = transform.position.z;
		isMoving = true;
	}

	void MovePlayer()
	{
		transform.rotation = Quaternion.LookRotation (Vector3.forward, targetPosition - transform.position);
		transform.position = Vector3.MoveTowards (transform.position, targetPosition, moveSpeed * Time.deltaTime);
		if(transform.position == targetPosition)
		{
			isMoving = false;
		}

	}
}