Csharp/C#教程:Unity实现鼠标或者手指点击模型播放动画分享

本文实例为大家分享了unity鼠标或者手指点击模型播放动的具体代码,供大家参考,具体内容如下

usingUnityEngine; usingSystem.Collections; publicclassClickPlayAnimation:MonoBehaviour{ ///<summary> ///实现功能为点击模型播放动画 ///使用方法,给模型添加碰撞,添加脚本 ///</summary> 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; } } }

Unity实现鼠标或者手指点击模型播放动画

您可能感兴趣的文章:Unity代码实现序列帧动画播放器在Unity中实现动画的正反播放代码

标签: 动画 模型 ni

Unity实现人物旋转和移动效果

在mac上安装虚拟机搭载Windows服务的方法

上述就是C#学习教程:Unity实现鼠标或者手指点击模型播放动画分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/904109.html

(0)
上一篇 2021年10月21日
下一篇 2021年10月21日

精彩推荐