当前位置: 移动技术网 > IT编程>开发语言>c# > Unity实现鼠标或者手指点击模型播放动画

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

2020年03月09日  | 移动技术网IT编程  | 我要评论
本文实例为大家分享了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;
    }
 
 }
  
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网