using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
using System.Collections.Generic;
public class ClickPlayAnimation : MonoBehaviour
{
///
/// ʵ�ֹ���Ϊ���ģ�Ͳ��Ŷ���
/// ʹ�÷�������ģ�������ײ����ӽű�
///
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("asd");
}
}
}
}
}
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("asd");
}
// ��ʾ��ǰѡ�ж��������
// print(hit.collider.gameObject);
}
}
}
if (isPlayAnim)
{
GetComponent().Play("asd");
isPlayAnim = false;
}
}
}
想通过点击物体触发动画,但是点击后提示动画找不着
那你检查一下你动画剪辑名有没有写对呢