Unity實(shí)現(xiàn)鼠標(biāo)或者手指點(diǎn)擊模型播放動(dòng)畫(huà)
更新時(shí)間:2020年01月20日 15:30:48 作者:liang_704959721
這篇文章主要為大家詳細(xì)介紹了Unity實(shí)現(xiàn)鼠標(biāo)或者手指點(diǎn)擊模型播放動(dòng)畫(huà),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
本文實(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)畫(huà)
/// 使用方法,給模型添加碰撞,添加腳本
/// </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#啟動(dòng)windows服務(wù)方法的相關(guān)問(wèn)題分析
C#啟動(dòng)windows服務(wù)的方法都是什么呢?C#啟動(dòng)服務(wù)類型為Disabled的windows服務(wù)會(huì)遇到什么樣的問(wèn)題呢?那么本文就向你介紹C#啟動(dòng)windows服務(wù)的方法的相關(guān)內(nèi)容2012-12-12
C#?手寫(xiě)識(shí)別的實(shí)現(xiàn)示例
本文主要介紹了C#?手寫(xiě)識(shí)別的實(shí)現(xiàn)示例,文章詳細(xì)介紹了如何使用C#語(yǔ)言調(diào)用OpenCV庫(kù)實(shí)現(xiàn)手寫(xiě)識(shí)別,并通過(guò)示例程序展示了整個(gè)手寫(xiě)識(shí)別過(guò)程,感興趣的可以了解一下2023-08-08
C#自定義事件監(jiān)聽(tīng)實(shí)現(xiàn)方法
這篇文章主要介紹了C#自定義事件監(jiān)聽(tīng)實(shí)現(xiàn)方法,涉及C#事件監(jiān)聽(tīng)的實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-08-08
C#開(kāi)發(fā)Windows服務(wù)實(shí)例之實(shí)現(xiàn)禁止QQ運(yùn)行
這篇文章主要介紹了通過(guò)C#開(kāi)發(fā)Windows服務(wù),查殺qq進(jìn)程的服務(wù)功能,需要的朋友可以參考下2013-10-10
Datagridview使用技巧(9)Datagridview的右鍵菜單
這篇文章主要為大家詳細(xì)介紹了Datagridview使用技巧,Datagridview的右鍵菜單,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-05-05

