Hi, I have a click to move top down mobile project I’m working on, with some problems. You see I have a UI Background Canvas that holds my game background (UI image) to keep it in place (aspect ratio) for any mobile devices, I also have a UI pause button. I use Input.GetMouseButtonDown (0) to move my player around the game, however when I click on my pause button my player will move towards it striaght after I click resume. I thought of using IsPointerOverGameObject but It stops my player from moving around my game because my game background is an UI image. So is there a way of pausing my game without the player moving towards the pause button when I resume the game. Maybe like having IsPointerOverGameObject over a certain UI. Thank you,
This is my PlayerMovement script:
private Animator anim;
public static float speed = 5f;
public static Vector3 target;
public PlayerMovement playerMovementRef;
//public GameObject firstSelectedGameObject;
private bool touched;
void Start () {
target = transform.position;
anim = GetComponent<Animator> ();
}
public void Update () {
if (Input.GetMouseButtonDown (0)) {
if (!EventSystem.current.IsPointerOverGameObject ()) {
Vector3 mousePosition = Input.mousePosition;
mousePosition.z = 10; // distance from the camera
target = Camera.main.ScreenToWorldPoint (mousePosition);
target.z = transform.position.z;
}
}
transform.position = Vector3.MoveTowards (transform.position, target, speed * Time.fixedDeltaTime);
}