private void OnTriggerEnter2D(Collider2D collision) { IPickupable pickupable = collision.gameObject.GetComponent <IPickupable>(); //Debug.Log("Trigger: " + collision.gameObject.name); Checkpoint c = collision.GetComponent <Checkpoint>(); if (collision.gameObject.GetComponent <Spike>() != null) { collision.gameObject.GetComponent <Spike>().MakeDamage(this); } if (pickupable != null) { pickupable.OnPickUp(this); } else if (collision.gameObject.GetComponent <IHazard>() != null) { collision.gameObject.GetComponent <IHazard>().MakeDamage(this); } else if (c != null) { if (!c.activated) { _checkpointPosition = collision.GetComponent <Checkpoint>().GetCheckpointPosition(); c.ActivateCheckpoint(); } } else if (collision.gameObject.GetComponent <IMovingPlatform>() != null) { Debug.Log("Parent"); collision.gameObject.GetComponent <IMovingPlatform>().ParentToPlatform(this.gameObject.transform); } }
public void Pickup(IPickupable target) { // Drop carried thing so new thing can be picked up if (Carrying) { Drop(); } else { // If not carrying, hand will be disabled so need to enable it Enable(); } // Position will be the position of last Drop() so need to move to cursor again -> otherwise, won't move til next update MoveToCursor(); held = target; previousParent = target.gameObject.transform.parent; // Remember previous parent so hierarchy can be restored on Drop() held.gameObject.transform.position = transform.position; // Set object as child and match position held.gameObject.transform.parent = transform; held.OnPickUp(); }