您的位置:首页 > 其它

鼠标双击

2016-06-13 13:37 197 查看
<pre name="code" class="csharp">using System;
using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class donghuaxianshi : MonoBehaviour {
public GameObject manyoudonghua;
public GameObject shipin;
public RawImage texture;
public Animator animator;
MovieTexture movTexture;
private bool mouseDownStatus;
private int mouseDownCount;
private float lastTime;
private float currentTime;
private Action clickCallback;
private Action doubleCallback;

// Use this for initialization
void Start () {
GameObject.Find("A").GetComponent<Animator>().speed = 0;
}

// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0))
{
if (!this.mouseDownStatus)
{
this.mouseDownStatus = true;
//Debug.Log("Click !");
if (this.clickCallback != null) this.clickCallback();

// 如果按住数量为 0
if (this.mouseDownCount == 0)
{
// 记录最后时间
this.lastTime = Time.realtimeSinceStartup;
}
this.mouseDownCount++;
}
}

if (Input.GetMouseButtonUp(0))
{
//Debug.Log("Up !");
this.mouseDownStatus = false;
}

if (this.mouseDownStatus)
{
//Debug.Log("Hold !");
if (this.mouseDownCount >= 2)
{

this.currentTime = Time.realtimeSinceStartup;
if (this.currentTime - this.lastTime < 0.1f)
{
this.lastTime = this.currentTime;
this.mouseDownCount = 0;
//Debug.Log("Double Click");
if (this.doubleCallback != null) this.doubleCallback();

Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
if (hit.transform.tag == "电脑")
{
manyoudonghua.SetActive(true);
manyoudonghua.transform.position = new Vector2(Input.mousePosition.x + 120, Input.mousePosition.y);

}
}
}
else
{
// 记录最后时间
this.lastTime = Time.realtimeSinceStartup;
this.mouseDownCount = 1;
}

}
}
}
public void donghua()
{
print("wanglijuan");
GameObject.Find("A").GetComponent<Animator>().Play("Take 001", 0, 0);
GameObject.Find("A").GetComponent<Animator>().speed = 1;
}

public void _shipin()
{
shipin.SetActive(true);
texture.texture = (Texture)Resources.Load("A");
movTexture = (MovieTexture)Resources.Load("A");
movTexture.loop = true;
movTexture.Play();
}

public void _shipinbofang()
{
movTexture.Play();
}

public void _shipinzanting()
{
movTexture.Stop();
}

public void manyoudonghuaguanbi()
{
manyoudonghua.SetActive(false);
shipin.SetActive(false);

}
}



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: