Unity實現(xiàn)鼠標(biāo)或者手指點(diǎn)擊模型播放動畫
更新時間:2020年01月20日 15:30:48 作者:liang_704959721
這篇文章主要為大家詳細(xì)介紹了Unity實現(xiàn)鼠標(biāo)或者手指點(diǎn)擊模型播放動畫,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了unity鼠標(biāo)或者手指點(diǎn)擊模型播放動的具體代碼,供大家參考,具體內(nèi)容如下
using UnityEngine; using System.Collections; public class ClickPlayAnimation : MonoBehaviour { /// <summary> /// 實現(xiàn)功能為點(diǎn)擊模型播放動畫 /// 使用方法,給模型添加碰撞,添加腳本 /// </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"); } // 顯示當(dāng)前選中對象的名稱 // print(hit.collider.gameObject); } } } if(isPlayAnim) { animation.Play(); isPlayAnim = false; } } }
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
DevExpress中GridControl列轉(zhuǎn)義的實現(xiàn)方法
這篇文章主要介紹了DevExpress中GridControl列轉(zhuǎn)義的實現(xiàn)方法,在項目開發(fā)中有一定的實用價值,需要的朋友可以參考下2014-08-08Winform基于多線程實現(xiàn)每隔1分鐘執(zhí)行一段代碼
這篇文章主要介紹了Winform基于多線程實現(xiàn)每隔1分鐘執(zhí)行一段代碼的方法,設(shè)計線程的操作及時間函數(shù)的用法,需要的朋友可以參考下2014-10-10C#/VB.NET?實現(xiàn)彩色PDF轉(zhuǎn)為灰度PDF
本文以C#代碼為例介紹如何實現(xiàn)將彩色PDF文件轉(zhuǎn)為灰度(黑白)的PDF文件,即將PDF文檔里面的彩色圖片或者文字等通過調(diào)用方法轉(zhuǎn)為文檔頁面為灰色調(diào)、無彩色效果的文檔??靵砀S小編一起學(xué)習(xí)吧2021-11-11C#讀取XML的CDATA節(jié)點(diǎn)內(nèi)容實例詳解
在本篇文章里小編給大家整理了關(guān)于C# 讀取XML的CDATA節(jié)點(diǎn)內(nèi)容的相關(guān)知識點(diǎn)內(nèi)容,有需要的朋友們參考學(xué)習(xí)下。2019-09-09