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