Ive wrote a simple code for example,im clicking at the spot with this code and transfrom cube is moving to spot, it works, but with a bug: when im clicking again at another spot2, while cube is moving to spot1,cube stops.Think problem is in logic of a code. Thanks for any help.
using UnityEngine;
using System.Collections;
public class PlanetMoveTest : MonoBehaviour
{
public Transform Cube;
public float speed = 10f;
bool isMoving = false;
// Use this for initialization
void Start ()
{
}
void OnMouseDown()
{
isMoving = true;
}
// Update is called once per frame
void Update ()
{
if(isMoving)
{
Cube.transform.position = Vector3.MoveTowards(Cube.transform.position,transform.position,Time.deltaTime * speed);
}
if(Cube.transform.position == transform.position)
{
isMoving = false;
}
}
}