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

作者:liang_704959721 时间:2023-11-30 23:06:01 

本文实例为大家分享了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;
   }

}

}

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

来源:https://blog.csdn.net/liang_704959721/article/details/45830953

标签:unity,鼠标,播放
0
投稿

猜你喜欢

  • Lombok基本注解之@SneakyThrows的作用

    2021-12-24 15:30:47
  • flutter 中监听滑动事件

    2021-10-05 11:39:00
  • 详解java基础--提示对话框的使用

    2023-01-31 12:11:46
  • Java判断所给年份是平年还是闰年

    2023-10-21 17:48:59
  • Android线程的优先级设置方法技巧

    2022-04-27 13:14:02
  • C#中四步轻松使用log4net记录本地日志的方法

    2021-12-22 02:23:16
  • Android入门之AlertDialog用法实例分析

    2023-12-16 02:27:02
  • Android 偷拍功能实现(手机关闭依然拍照)详解及实例代码

    2023-01-08 00:23:19
  • Android优雅地处理按钮重复点击的几种方法

    2021-11-23 05:09:14
  • Java 前台加后台精品图书管理系统的实现

    2023-10-23 04:06:47
  • 解决IDEA和CMD中java命令提示错误: 找不到或无法加载主类的问题

    2023-09-19 02:31:16
  • C#打包应用程序,与.NETFramework介绍

    2022-03-29 15:29:20
  • Android中让按钮拥有返回键功能的方法及重写返回键功能

    2021-08-08 10:33:56
  • SpringBoot 整合jdbc和mybatis的方法

    2023-08-10 12:51:09
  • Android 8.0系统中应用图标的适配微技巧

    2022-09-29 00:22:26
  • IDEA中Mybatis的MGB使用逆向工程配置的详细教程

    2022-01-04 17:19:50
  • Android开发使用HttpURLConnection进行网络编程详解【附源码下载】

    2022-01-11 23:27:37
  • C语言指针的图文详解

    2021-07-26 11:26:25
  • SpringBoot框架集成ElasticSearch实现过程示例详解

    2023-02-02 08:44:05
  • Android Gradle 三方依赖管理详解

    2023-02-27 21:11:53
  • asp之家 软件编程 m.aspxhome.com