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;
}
}
}
来源:https://blog.csdn.net/liang_704959721/article/details/45830953
标签:unity,鼠标,播放
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Lombok基本注解之@SneakyThrows的作用
2021-12-24 15:30:47
![](https://img.aspxhome.com/file/2023/0/77340_0s.png)
flutter 中监听滑动事件
2021-10-05 11:39:00
详解java基础--提示对话框的使用
2023-01-31 12:11:46
![](https://img.aspxhome.com/file/2023/2/80902_0s.jpg)
Java判断所给年份是平年还是闰年
2023-10-21 17:48:59
Android线程的优先级设置方法技巧
2022-04-27 13:14:02
![](https://img.aspxhome.com/file/2023/5/139305_0s.png)
C#中四步轻松使用log4net记录本地日志的方法
2021-12-22 02:23:16
![](https://img.aspxhome.com/file/2023/0/106450_0s.png)
Android入门之AlertDialog用法实例分析
2023-12-16 02:27:02
![](https://img.aspxhome.com/file/2023/3/111683_0s.jpg)
Android 偷拍功能实现(手机关闭依然拍照)详解及实例代码
2023-01-08 00:23:19
![](https://img.aspxhome.com/file/2023/9/114289_0s.png)
Android优雅地处理按钮重复点击的几种方法
2021-11-23 05:09:14
![](https://img.aspxhome.com/file/2023/7/138767_0s.jpg)
Java 前台加后台精品图书管理系统的实现
2023-10-23 04:06:47
![](https://img.aspxhome.com/file/2023/3/79863_0s.png)
解决IDEA和CMD中java命令提示错误: 找不到或无法加载主类的问题
2023-09-19 02:31:16
![](https://img.aspxhome.com/file/2023/2/101922_0s.png)
C#打包应用程序,与.NETFramework介绍
2022-03-29 15:29:20
Android中让按钮拥有返回键功能的方法及重写返回键功能
2021-08-08 10:33:56
SpringBoot 整合jdbc和mybatis的方法
2023-08-10 12:51:09
![](https://img.aspxhome.com/file/2023/8/58158_0s.png)
Android 8.0系统中应用图标的适配微技巧
2022-09-29 00:22:26
![](https://img.aspxhome.com/file/2023/0/138200_0s.jpg)
IDEA中Mybatis的MGB使用逆向工程配置的详细教程
2022-01-04 17:19:50
![](https://img.aspxhome.com/file/2023/3/88583_0s.png)
Android开发使用HttpURLConnection进行网络编程详解【附源码下载】
2022-01-11 23:27:37
C语言指针的图文详解
2021-07-26 11:26:25
![](https://img.aspxhome.com/file/2023/9/125909_0s.png)
SpringBoot框架集成ElasticSearch实现过程示例详解
2023-02-02 08:44:05
![](https://img.aspxhome.com/file/2023/7/70487_0s.png)
Android Gradle 三方依赖管理详解
2023-02-27 21:11:53