using System.Collections; using System.Collections.Generic; using UnityEngine; public class GrabItem : MonoBehaviour { public bool restIsBack = false; //�ſ����Ƿ񷵻�ԭλ�� public bool isUseRigidbody = false; //�Ƿ�ʹ������ private Vector3 startPosition = Vector3.zero; //��ʼλ�� public bool startIsUseRigid = true; private Rigidbody m_rig; public Transform m_originParent; private CatchManager m_catch; public AudioSource cathcAudio; public AudioSource downAudio; private string nowCatchHandName = ""; public EffectHideAndShowCtr effectHideAndShowCtr; //��ʱ��� bool isRun = false; float waitTime = 2f; float runTime = 0; //��ʱ�ȴ���ʾ���ֵĶ�������Ч�� bool isRun2 = false; float waitTime2 = 1f; float runTime2 = 0; private void Awake() { m_rig = GetComponent(); if(effectHideAndShowCtr == null) effectHideAndShowCtr = GetComponent(); m_originParent = transform.parent; startPosition = this.transform.localPosition; SetRigState(startIsUseRigid); } private void Update() { if (isRun) { runTime += Time.deltaTime; if (runTime >= waitTime) { //��ʼ���� isRun = false; runTime = 0; HideObj(); } } } void HideObj() { if (effectHideAndShowCtr != null) { //this.GetComponent().enabled = false; effectHideAndShowCtr.Hide(); StartCoroutine(ShowObj()); } } IEnumerator ShowObj() { yield return new WaitForSeconds(1); this.GetComponent().isTrigger = true; //transform.SetParent(m_originParent); SetRigState(false); isUseRigidbody = false; SetStartPosition(); effectHideAndShowCtr.Show(); SetMoveMent(true); //StartCoroutine(SetEnabled()); } //IEnumerator SetEnabled() //{ // yield return new WaitForSeconds(1); // this.GetComponent().enabled = true; //} public void OnReset(string name) { if (nowCatchHandName != name) return; if (downAudio != null) downAudio.Play(); if (restIsBack) { isRun = true; this.GetComponent().isTrigger = false; isUseRigidbody = true; transform.SetParent(m_originParent); SetRigState(true); } else { transform.SetParent(m_originParent); SetRigState(true); } } private void OnTriggerEnter(Collider other) { if (other.gameObject.CompareTag("RightHand")) { //Debug.Log("Ent������:"+other.gameObject.name);0 SetTriggerParameter("DisTrigger"); SceneMgr.Instance.isTrigger=true; //if (m_catch == null) m_catch = other.GetComponent(); if (m_catch == null) return; // Debug.Log("111�Ƿ�ʼ:"+ m_catch.Start); if (m_catch.Start) { isRun = false; runTime = 0; nowCatchHandName = other.gameObject.name; SetMoveMent(false); SetRigState(false); m_catch.SetParent(transform); m_catch.SetCurrentItem(this); if (cathcAudio != null) cathcAudio.Play(); } } } private void OnTriggerExit(Collider other) { if (other.gameObject.CompareTag("RightHand")) { SceneMgr.Instance.isTrigger = false; } } private void OnTriggerStay(Collider other) { if (other.gameObject.CompareTag("RightHand")) { //Debug.Log("Stay������"+ other.gameObject.name); m_catch = other.GetComponent(); if (m_catch == null) return; //Debug.Log("222�Ƿ�ʼ:" + m_catch.Start); if (m_catch.Start) { isRun = false; runTime = 0; nowCatchHandName = other.gameObject.name; SetMoveMent(false); SetRigState(false); m_catch.SetParent(transform); m_catch.SetCurrentItem(this); } } } private void SetRigState(bool value) { if (isUseRigidbody) { m_rig.useGravity = value; m_rig.isKinematic = !m_rig.useGravity; } } private void SetStartPosition() { this.transform.localRotation = new Quaternion(0,0,0,0); this.transform.localPosition = startPosition; } void SetMoveMent(bool isMove) { if (this.GetComponent() != null) { Debug.Log("�����ƶ�:"+isMove); this.GetComponent().isMove = isMove; } } [Header("��������")] [SerializeField] private GameObject childAnimator; // ֱ���϶��� public void SetTriggerParameter(string parameterName) { if (childAnimator != null) { Destroy(childAnimator); } } }