您好,登錄后才能下訂單哦!
這篇文章主要介紹Unity如何實(shí)現(xiàn)鼠標(biāo)或者手指點(diǎn)擊模型播放動(dòng)畫,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
具體內(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; } } }
以上是“Unity如何實(shí)現(xiàn)鼠標(biāo)或者手指點(diǎn)擊模型播放動(dòng)畫”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。