Reputation: 11
i want to play my Unity Game in Mouse Input mode too (my Script now is Touch Input), can everyone help me to convert my script to Mouse input?? using if unity_editor , endif:
#if UNITY_EDITOR
//some code for mouse input
#endif
my script in here : http://pastebin.com/HJwbEzy4
thanks you so much who help me!! :)
or here :
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();
}
}
}
}
}
}
}
Upvotes: 0
Views: 2726
Reputation: 1359
No need of touches. You can use Input.GetMouseButton
, will work on both.
Input.GetMouseButtonDown(0)
for touch begin.
Input.GetMouseButtonUp(0)
for touch ended.
Input.GetMouseButton(0)
for touch begin and move.
void Update(){
if (Input.GetMouseButtonDown(0))
print("Touch begin");
// So on....
}
Upvotes: 3