如何将触摸输入转换为鼠标输入C#unity?

时间:2016-02-05 13:21:46

标签: c# input touch mouse

我也希望在鼠标输入模式下玩我的Unity游戏(我的脚本现在是Touch Input),每个人都可以帮助我将我的脚本转换为鼠标输入吗? 使用if unity_editor,endif:

#if UNITY_EDITOR

//some code for mouse input

#endif

我的脚本在这里:http://pastebin.com/HJwbEzy4

非常感谢你帮助我! :)

或在这里:

using UnityEngine;
using System.Collections;

public class Main_Menu_02 : MonoBehaviour
{
    public GameObject InstructionContainer;
    public GameObject Buttons;
    public GameObject AW;
    public GameObject Instruction;
    public GameObject Exit;
    public Texture Active;
    public Texture nonActive;



    public AudioClip SFX_select;

    // Update is called once per frame
    void Update ()
    {
        if (Input.touches.Length <=0)
        {
            this.guiTexture.texture = nonActive;
        }
        else
        {
            if(Input.touches.Length == 1)
            {
                if(this.guiTexture.HitTest(Input.GetTouch(0).position))
                {
                    if(Input.GetTouch(0).phase == TouchPhase.Began)
                    {
                        audio.PlayOneShot(SFX_select);
                        this.guiTexture.texture = Active;
                    }
                    if(Input.GetTouch(0).phase == TouchPhase.Ended)
                    {
                        if(this.gameObject == AW)
                            Application.LoadLevel("LoadingAW");
                        else if(this.gameObject == Instruction)
                        {
                            InstructionContainer.SetActive(true);
                            Buttons.SetActive(false);
                        }
                        else if (this.gameObject == Exit)
                        {
                            Application.Quit();
                        }
                    }
                }
            }
        }
    }
}

1 个答案:

答案 0 :(得分:3)

无需接触。您可以使用Input.GetMouseButton,同时适用于这两种方式。

Input.GetMouseButtonDown(0)触摸开始。

Input.GetMouseButtonUp(0)触摸结束。

Input.GetMouseButton(0)触摸开始和移动。

void Update(){
    if (Input.GetMouseButtonDown(0))
        print("Touch begin");
    // So on....

}

相关问题