void OnCollisionEnter(Collision other) { if (isFly) { var tmpObj = other.gameObject.GetComponent <ObjectForBird>(); if (tmpObj) { if (tmpObj.GetComponent <VRObjectBase>().GetVRObjectMode() != VRObjectMode.NeverMove) { Debug.Log("Catch"); objMode = tmpObj.GetVRObjectMode(); //tmpObj.SetVRObjectMode(VRObjectMode.None); obj = other.transform.gameObject; tmpObj.caught = true; obj.transform.parent = this.transform; } } SetVRObjectMode(VRObjectMode.Grabable); Rigidbody rigidbody = GetComponent <Rigidbody>(); rigidbody.velocity = Vector3.zero; Invoke("FlyBack", 0.5f); } isFly = false; //isFlyBack = false; flyFlag = true; }
void FinishFly() { if (!isFlyBack) { return; } if (obj) { obj.gameObject.GetComponent <ObjectForBird>().caught = false; obj.transform.parent = null; } rigidBody.velocity *= 0.5f; rigidBody.useGravity = true; obj = null; objMode = VRObjectMode.None; direction = Vector3.zero; }
public void SetVRObjectMode(VRObjectMode mode) { this.VRObjectMode = mode; if (VRObjectMode != VRObjectMode.NeverMove) { transform.tag = "VRItem"; if (rigidBody == null) { rigidBody = gameObject.AddComponent <Rigidbody>(); } rigidBody.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic; rigidBody.useGravity = UseGravity; if (Mass != 0) { rigidBody.mass = Mass; } if (VRObjectMode == VRObjectMode.Grabable) { //Throwable追加 Throwable thro = gameObject.GetComponent <Throwable>(); if (!thro) { thro = gameObject.AddComponent <Throwable>(); } thro.onPickUp = onPickUp; thro.onDetachFromHand = onThrowAway; //Attachイベント消去 onAttachedToHand = new UnityEvent(); onDetachedFromHand = new UnityEvent(); } else { Throwable thro = gameObject.GetComponent <Throwable>(); if (thro) { Destroy(thro); } } //InteractableHoverEvents追加 InteractableHoverEvents ihe = gameObject.GetComponent <InteractableHoverEvents>(); ihe.onHandHoverBegin = onHandHoverBegin; ihe.onHandHoverEnd = onHandHoverEnd; if (VRObjectMode != VRObjectMode.Attachable) { //Attachイベント消去 onAttachedToHand = new UnityEvent(); onDetachedFromHand = new UnityEvent(); } ihe.onAttachedToHand = onAttachedToHand; ihe.onDetachedFromHand = onDetachedFromHand; } else { DestroyImmediate(rigidBody); Throwable thro = gameObject.GetComponent <Throwable>(); if (thro) { Destroy(thro); } } }