鼠标双击
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); } }
相关文章推荐
- myeclipse快捷键
- CountDownTimer 解决 Cancel无效的问题
- 转:java中时间戳各种实现方式获取效率
- 归并排序
- 深入Java集合:ArrayList实现原理
- 什么是编解码器codec
- 第十。十一周项目3 - 警察和厨师——1
- 希尔排序
- 关于gcc中string的sizeof
- 第15周程序阅读1
- 折半(二分)插入排序
- 常用命令
- 第十、十一周实践项目2 - 存储班长信息的学生类
- Apache Mina 入门实例
- Unity3d--摄像机视野远近的控制
- java 文件操作
- ubuntu php imageMagick
- 直接插入排序
- 第十、十一周项目1 - 点-圆-圆柱类族的设计(3)
- 关于CodeMirror组件间互相影响的缺陷问题