Hi
I am currently trying to work out how to move an object (player) to another object once a mouse button has been clicked.
Moving the player using the following script works when no mouse click detect is required.
using UnityEngine;
using System.Collections;
public class MoveToTarget : MonoBehaviour
{
public Transform target;
public float speed;
void Update()
{
float step = speed * Time.deltaTime;
transform.position = Vector3.MoveTowards (transform.position, target.position, step);
}
}
However when I add detecting mouse-click the player does move in the direction of the object but stops, waiting for another click before it moves again.
using UnityEngine;
using System.Collections;
public class MoveToTarget : MonoBehaviour
{
public Transform target;
public float speed;
void Update()
{
if (Input.GetMouseButtonDown(0))
{
float step = speed * Time.deltaTime;
transform.position = Vector3.MoveTowards (transform.position, target.position, step);
}
}
}
Should I be using something other than void update?
Can someone point me in the right direction with regards to seeing what options are available other than void update?
Thanks