private void OnTriggerEnter(Collider other) { if (!activated && owningObject != null && !owningObject.GetBusy() && (owningObject.GetObjectMover().GetGrabbed() || owningObject.GetAttached())) { AttachmentTrigger trigger = other.GetComponent <AttachmentTrigger>(); if (trigger) { Debug.Log("Plug: " + this.gameObject.name + ", collided with trigger: " + trigger.gameObject.name); } if (trigger && !trigger.GetOwningObject().GetBusy() && trigger.attachmentType == this.attachmentType && trigger.GetOwningObject().GetObjectMover().GetGrabbed()) { Debug.Log("Activating plug" + this.name + " via trigger: " + trigger.name); Activate(trigger); } } }
public void Activate(AttachmentTrigger trigger) { activated = true; if (trigger != null) { attachedObjectTrigger = trigger; attachedObject = trigger.GetOwningObject(); attachedObjectMover = attachedObject.GetObjectMover(); attachedObjectGrabbedBy = attachedObjectMover.GetGrabbedBy(); } if (attachedObject != null && attachedObjectMover && attachedObjectGrabbedBy) { attachedObject.SetBusy(true); inlineRot = GetLocalInlineRotation(attachedObjectMover.transform); attachedObjectGrabbedBy.Release(); //attachedObjectMover.SetMoveMode(2); //attachedObjectGrabbedBy.Grab(attachedObjectMover); moveGuide.SetParent(this.transform); moveGuide.SetPositionAndRotation(attachedObjectTrigger.transform.position, attachedObjectTrigger.transform.rotation); attachedObject.KillCollision(); attachedObject.KillPhysics(); attachedObject.IgnoreCollision(owningObject.GetGameObject().GetComponent <BoxCollider>(), true); attachedObjectMover.transform.localRotation = inlineRot; //moveObjectOffeset = Vector3.Magnitude(attachedObjectMover.transform.position - attachedObjectGrabbedBy.transform.position); attachedObjectMover.transform.SetParent(moveGuide); //attachedObjectMover.transform.SetParent(moveGuide); tracking = true; owningObject.SetBusy(true); } else { Deactivate(); } }