Unity实现鼠标或者手指点击模型播放动画
- 作者: 功夫不好1
- 来源: 51数据库
- 2020-08-09
这篇文章主要为大家详细介绍了Unity实现鼠标或者手指点击模型播放动画,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了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;
}
}
}

以上就是本文的全部内容,希望对大家的学习有所帮助,
推荐阅读
- C#通过fleck实现wss协议的WebSocket多人Web实时聊天(附源码)
- 团队城市未满足要求:MSBuildTools12.0_x86_Path 存在
- 使用 MSBuild.exe 在发布模式下构建 C# 解决方案
- 当我发布 Web 应用程序时,AfterPublish 脚本不运行
- 构建时 T4 转换的产品仅在下一个构建中使用
- ASP.NET Core Application (.NET Framework) for Windows x64 only error in project.assets.json
- 新的 .csproj 格式 - 如何将整个目录指定为“链接文件"到子目录?
- 如何将条件编译符号(DefineConstants)传递给 msbuild
- MSBuild 支持 Visual Studio 2017 RTM 中的 T4 模板
- NuGet 包还原找不到包,没有源
热点文章
团队城市未满足要求:MSBuildTools12.0_x86_Path 存在
0
使用 MSBuild.exe 在发布模式下构建 C# 解决方案
0
当我发布 Web 应用程序时,AfterPublish 脚本不运行
0
构建时 T4 转换的产品仅在下一个构建中使用
0
ASP.NET Core Application (.NET Framework) for Windows x64 only error in project.assets.json
0
新的 .csproj 格式 - 如何将整个目录指定为“链接文件"到子目录?
0
如何将条件编译符号(DefineConstants)传递给 msbuild
0
MSBuild 支持 Visual Studio 2017 RTM 中的 T4 模板
0
NuGet 包还原找不到包,没有源
0
使用 C# 6.0 功能运行 TFS 构建
0
