void Update() { // Hold an object if (controller.GetPressDown(grip) && holdable != null) { currentlyHolding = holdable; currentlyHolding.Hold(transform); ToggleModelsActive(); } // Holds and snaps an object if (controller.GetPressDown(touchPad) && holdable != null) { currentlyHolding = holdable; currentlyHolding.HoldSnap(transform); ToggleModelsActive(); } // Drops the held object if ((controller.GetPressUp(grip) || controller.GetPressUp(touchPad)) && currentlyHolding != null) { currentlyHolding.Drop(controller.velocity, controller.angularVelocity); currentlyHolding = null; ToggleModelsActive(); } // If held object is gun, shoot if (controller.GetPressDown(trigger) && currentlyHolding != null) { var gun = currentlyHolding.gameObject.GetComponent <Shooting>(); if (gun != null) { gun.Shoot(); } } // Move Slider if (controller.GetPress(trigger) && slider != null) { slider.Move(transform); } // Press Button if (controller.GetPressDown(trigger) && button != null) { button.Press(); } // Scene reset if (controller.GetPressDown(menu)) { SceneManager.LoadScene(SceneManager.GetActiveScene().name); } }
private void PickupItem(Holdable item) { if (heldItem != null) { // Fail to pickup item return; } if (item is Crockpot) { anim.SetBool("HoldingPot", true); } else { anim.SetBool("HoldingItem", true); } Debug.Log("Picked up " + item.name); heldItem = item; item.Hold(); heldItem.transform.SetPositionAndRotation(holdTransform.localPosition, holdTransform.localRotation); heldItem.transform.SetParent(holdTransform, false); }
void Update() { // Hold an object if (Input.GetKeyDown(KeyCode.E) && holdable != null) { currentlyHolding = holdable; currentlyHolding.Hold(transform); } // Holds and snaps an object if (Input.GetKeyDown(KeyCode.R) && holdable != null) { currentlyHolding = holdable; currentlyHolding.HoldSnap(transform); } // Drops the held object if ((Input.GetKeyUp(KeyCode.E) || Input.GetKeyUp(KeyCode.R)) && currentlyHolding != null) { currentlyHolding.Drop(rb.velocity, rb.angularVelocity); currentlyHolding = null; } // Hold snap toggle if (Input.GetKeyDown(KeyCode.T)) { if (!holdToggle && holdable != null) { currentlyHolding = holdable; currentlyHolding.HoldSnap(transform); holdToggle = true; } else if (holdToggle && currentlyHolding != null) { currentlyHolding.Drop(rb.velocity, rb.angularVelocity); currentlyHolding = null; holdToggle = false; } } // Press button if (Input.GetKeyDown(KeyCode.F) && button != null) { button.Press(); } if (Input.GetKey(KeyCode.E) && slider != null) { slider.Move(transform); } // If held object is gun, shoot if (Input.GetMouseButtonDown(0) && currentlyHolding != null) { var gun = currentlyHolding.GetComponent <Shooting>(); if (gun != null) { gun.Shoot(); } } if (Input.GetMouseButtonDown(1)) { Teleport.Tele(transform.parent, transform.parent); } }