/** * Note: This current implentation creates goofy situations with carryables. * If the character is standing near an interactable, and a carryable * if the carryable interaction executes first, the carryable will get * picked up, and the other object will not be interacted with. If the * interactable interaction executes first, that interaction will occur * AND the carryable will be picked up. */ public void Interact() { if (character.isAlive) { bool interacted = false; // Using index iteration because the interactable might be destroyed // through the interaction. Iterating in reverse in case an element // is removed. for (int i = interactables.Count - 1; i >= 0; i--) { InteractableBehavior interactable = interactables[i]; interactable.Interact(gameObject, interaction); interacted = true; } // There is no way to know that an interaction really occurred, so // we just need to test if there are any interactables around. if (!interacted) { Carrier carrier = character.GetComponent <Carrier>(); if (carrier != null && carrier.heldObject != null) { carrier.Drop(); } } character.movementState = Character.MovementState.IDLE; } }
private void ConsumeObject(Carrier carrier) { GameObject consumable = carrier.heldObject.gameObject; carrier.Drop(); Destroy(consumable); }
public void Die() { Carrier carrier = GetComponent <Carrier>(); if (carrier != null) { carrier.Drop(); } respawner.StartRespawn(this); isAlive = false; movementState = MovementState.DEAD; gameObject.SetActive(false); }
public override void Expose(GameObject target, HazardType hazardType) { if (vulnerabilities.Contains(hazardType)) { Carryable carryable = target.GetComponent <Carryable>(); if (carryable != null) { Carrier carrier = carryable.carrier; if (carrier != null) { carrier.Drop(); } } Destroy(target); } }
/// <summary> /// So it can't be picked up while being destroyed. /// </summary> public void SetToUntouchable() { carrier?.Drop(); canBePickedUp = false; }