簡體   English   中英

如何將觸摸輸入轉換為鼠標輸入C#的單位?

[英]HOW to CONVERT Touch Input To Mouse Input C# unity?

我也想在鼠標輸入模式下玩我的Unity游戲(我的腳本現在是觸摸輸入),每個人都可以幫助我將腳本轉換為鼠標輸入嗎? 使用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();
                        }
                    }
                }
            }
        }
    }
}

無需接觸。 您可以使用Input.GetMouseButton ,這兩者都可以使用。

用於觸摸開始的Input.GetMouseButtonDown(0)

Input.GetMouseButtonUp(0)結束觸摸。

用於觸摸開始和移動的Input.GetMouseButton(0)

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

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM