如何转换触摸输入到鼠标输入C#统一?

问题描述:

我想在鼠标输入模式下玩我的Unity游戏(我的脚本现在是触摸输入),每个人都可以帮助我将脚本转换为鼠标输入? 使用if unity_editor,ENDIF:如何转换触摸输入到鼠标输入C#统一?

#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.... 

}

+0

感谢兄弟,我来试试:) – Blazingr