using System.Collections; using System.Collections.Generic; using UnityEngine; public class HandPosTest : MonoBehaviour { bool isStay = false; Transform oldTransform; Rigidbody rigidbody; bool isTirgger = true; // Start is called before the first frame update void Start() { oldTransform = this.transform.parent; rigidbody = this.GetComponent(); } // Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.X)) { HandExit(); } } private void OnTriggerStay(Collider other) { if (other.gameObject.name == "PalmBox_L" || other.gameObject.name == "PalmBox_R") { if (isTirgger) { isTirgger = false; GameObject obj = other.transform.parent.Find("PalmBox_GD").gameObject; this.transform.parent = obj.transform; rigidbody.useGravity = false; Debug.Log("手了我:" + other.gameObject.name); } isStay = true; } } private void OnTriggerExit(Collider other) { if (other.gameObject.name == "PalmBox_L" || other.gameObject.name == "PalmBox_R") { isStay = false; isTirgger = true; } } void HandExit() { rigidbody.useGravity = true; this.transform.parent = oldTransform; } //private void OnCollisionStay(Collision collision) //{ // Debug.Log("˭������:"+collision.gameObject.name); //} //private void OnCollisionExit(Collision collision) //{ //} }