Unity实现鼠标或者手指点击模型播放动画
程序员文章站
2022-05-14 22:14:17
本文实例为大家分享了unity鼠标或者手指点击模型播放动的具体代码,供大家参考,具体内容如下
using unityengine;
using system.collect...
本文实例为大家分享了unity鼠标或者手指点击模型播放动的具体代码,供大家参考,具体内容如下
using unityengine; using system.collections; public class clickplayanimation : monobehaviour { /// <summary> /// 实现功能为点击模型播放动画 /// 使用方法,给模型添加碰撞,添加脚本 /// </summary> bool isplayanim = false; // use this for initialization void start () { } // update is called once per frame void update () { //animation.play(); if (application.platform == runtimeplatform.iphoneplayer || application.platform == runtimeplatform.android) { foreach (touch touch in input.touches) { if (input.touchcount > 0 && input.gettouch(0).phase == touchphase.began || input.gettouch(0).phase == touchphase.moved) { ray ray = camera.main.screenpointtoray(new vector3(touch.position.x, touch.position.y, 0)); raycasthit hit; if (physics.raycast(ray, out hit)) { // debug.drawline(ray.origin, hit.point); if (hit.collider.gameobject.name == gameobject.name) { isplayanim = true; print("123"); } } } } } else { if (input.getmousebuttondown(0)) { ray ray = camera.main.screenpointtoray(input.mouseposition); raycasthit hit; if (physics.raycast(ray, out hit)) { 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; } } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
上一篇: Unity3D Shader实现镜子效果