private void DoThrowExecute(PickupInteraction item, HumanoidInventoryController inventory) { if (CanThrow(item)) { inventory.DropItem(item, true); // TODO: The item should know by itself whether it is attached or not // Rigidbody is ensured by CanThrow Rigidbody body = item.GetComponent <Rigidbody>(); body.AddForce(DoThrowGetAngle() * THROW_DISTRACTION_FORCE, ForceMode.Impulse); } }
public override void DoInteraction(GameObject user) { base.DoInteraction(user); if (user != null) { HumanoidInventoryController inventory = user.GetComponent <HumanoidInventoryController>(); if (inventory != null) { inventory.Pickup(this); } } }
void Update() { // Add some delay /*if (button_cooldown > 0.0f) * { * button_cooldown -= Time.deltaTime; * return; * }*/ // Handle possible interactions first InteractionController interactions = this.gameObject.GetComponent <InteractionController>(); interactions.UpdateInteractions(); foreach (InteractionType type in Enum.GetValues(typeof(InteractionType))) { if (GetButtonDown(type)) { Debug.Log("Checking interaction: " + type); foreach (Interactable obj in interactions.GetInteractions(type)) { Debug.Log("> " + obj.gameObject.name); if (obj.RequestInteraction(this.gameObject)) { Debug.Log("Interacting with: " + obj); return; } } } } // Handle inventory stuff HumanoidInventoryController inventory = this.gameObject.GetComponent <HumanoidInventoryController>(); if (GetButtonDown(InteractionType.Place)) { inventory.ExecutePlace(); return; } if (GetButtonDown(InteractionType.Holster)) { inventory.ExecuteHolster(); return; } if (GetButtonDown(InteractionType.Aim)) { // TODO } if (CanThrow(inventory.GetItemInHands())) { if (GetButtonUp(InteractionType.Throw)) { DoThrowExecute(inventory.GetItemInHands(), inventory); } else if (GetButtonPressed(InteractionType.Throw)) { trajectory_renderer.enabled = DoThrowAiming(inventory.GetItemInHands()); if (trajectory_renderer.enabled) { return; } } } }