单击UIButton而不注册鼠标单击 - Unity

时间:2016-05-06 10:03:19

标签: c# ios unity3d click

我正在创建一个2D射击游戏,我有一个功能,如果你点击屏幕上的某个地方,宇宙飞船移动到屏幕上的点,我的屏幕上还有一个用于拍摄的UI按钮(因为这是iOS)游戏我不能使用键),当我点击我的UI按钮拍摄飞船移动到UI按钮的位置。无论如何我可以点击按钮让它拍摄,但要确保我的太空船不会向按钮移动?我用Unity编写了C#。

这是我的MOVEMENT脚本:

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




        }
    }
}

0 个答案:

没有答案