I am creating a 2D Shooter and I have a function where if you CLICK somewhere on the screen the spaceship moves to the point on the screen, I also have a UI button on my screen which is for shooting (Since this is iOS game I cannot use keys), when I click on my UI button to shoot the spaceship moves to position of UI button. Is there anyway I can click on the button and make it SHOOT but make sure my spaceship does not move towards the button? I coded in C# in Unity.
This is my MOVEMENT script :
using UnityEngine;
using System.Collections;
public class Movement : MonoBehaviour {
public float depth;
public float depthRotate;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButton (0)) {
Rigidbody2D rigidbody = transform.GetComponent<Rigidbody2D>();
Vector3 mousePos = Input.mousePosition;
Vector3 wantedPos = Camera.main.ScreenToWorldPoint (new Vector3 (mousePos.x, mousePos.y, depth));
rigidbody.position = Vector3.Lerp(transform.position, wantedPos, depth * Time.deltaTime);
Vector3 diff = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
diff.Normalize();
float rot_z = Mathf.Atan2(diff.y, diff.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(0f, 0f, rot_z - 90), depthRotate * Time.deltaTime);
}
}
}