2

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);




        }
    }
}
Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38
Ajay
  • 31
  • 4
  • hi Ajay, this is asked 100s of times - be sure to search first! cheers – Fattie May 06 '16 at 11:03
  • Hey @Joe Blow Thanks for the help! :) I'm only 13 and learning Unity. Thanks! – Ajay May 06 '16 at 12:24
  • hey buddy no problem. **come back here with any more questions** That is the perfect time to program, enjoy yourself. Old people are stupid - their brains move too slow to program computers. You have to be 12-13-14 years to have your brain work fast enough. Enjoy – Fattie May 06 '16 at 12:27

0 Answers0