Unity實現(xiàn)鼠標(biāo)或者手指點擊模型播放動畫
更新時間:2020年01月20日 15:30:48 作者:liang_704959721
這篇文章主要為大家詳細(xì)介紹了Unity實現(xiàn)鼠標(biāo)或者手指點擊模型播放動畫,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了unity鼠標(biāo)或者手指點擊模型播放動的具體代碼,供大家參考,具體內(nèi)容如下
using UnityEngine;
using System.Collections;
public class ClickPlayAnimation : MonoBehaviour {
/// <summary>
/// 實現(xià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)文章
C#啟動windows服務(wù)方法的相關(guān)問題分析
C#啟動windows服務(wù)的方法都是什么呢?C#啟動服務(wù)類型為Disabled的windows服務(wù)會遇到什么樣的問題呢?那么本文就向你介紹C#啟動windows服務(wù)的方法的相關(guān)內(nèi)容2012-12-12
C#開發(fā)Windows服務(wù)實例之實現(xiàn)禁止QQ運行
這篇文章主要介紹了通過C#開發(fā)Windows服務(wù),查殺qq進程的服務(wù)功能,需要的朋友可以參考下2013-10-10
Datagridview使用技巧(9)Datagridview的右鍵菜單
這篇文章主要為大家詳細(xì)介紹了Datagridview使用技巧,Datagridview的右鍵菜單,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-05-05

