Unity实现鼠标或者手指点击模型播放动画
本文实例为大家分享了unity鼠标或者手指点击模型播放动的具体代码,供大家参考,具体内容如下
usingUnityEngine; usingSystem.Collections; publicclassClickPlayAnimation:MonoBehaviour{ //////实现功能为点击模型播放动画 ///使用方法,给模型添加碰撞,添加脚本 /// boolisPlayAnim=false; //Usethisforinitialization voidStart(){ } //Updateiscalledonceperframe voidUpdate(){ //animation.Play(); if(Application.platform==RuntimePlatform.IPhonePlayer||Application.platform==RuntimePlatform.Android) { foreach(TouchtouchinInput.touches) { if(Input.touchCount>0&&Input.GetTouch(0).phase==TouchPhase.Began||Input.GetTouch(0).phase==TouchPhase.Moved) { Rayray=Camera.main.ScreenPointToRay(newVector3(touch.position.x,touch.position.y,0)); RaycastHithit; if(Physics.Raycast(ray,outhit)) { //Debug.DrawLine(ray.origin,hit.point); if(hit.collider.gameObject.name==gameObject.name) { isPlayAnim=true; print("123"); } } } } } else { if(Input.GetMouseButtonDown(0)) { Rayray=Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHithit; if(Physics.Raycast(ray,outhit)) { Debug.DrawLine(ray.origin,hit.point); //print(hit.collider.gameObject.name); //curObject=hit.collider.gameObject; if(hit.collider.gameObject.name==gameObject.name) { isPlayAnim=true; print("123"); } //显示当前选中对象的名称 //print(hit.collider.gameObject); } } } if(isPlayAnim) { animation.Play(); isPlayAnim=false; } } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。