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 TestInteract() { if (currentHolding != null) { //interactable that is holdable is released currentHolding.Drop(); currentHolding = null; return; } var interactables = FindObjectsOfType <Interactable>().Where(a => a.isLocked == false); Interactable closestItem = null; var closestDist = float.MaxValue; foreach (var interactable in interactables) { var dist = Vector3.Distance(interactable.transform.position, gameObject.transform.position); if (dist < interactDistance && dist < closestDist) { closestItem = interactable; closestDist = dist; } } if (closestItem != null) { //Can it be held? var holdable = closestItem.GetComponent <Holdable>(); if (holdable != null) { currentHolding = holdable; currentHolding.Pickup(); } //Todo otherwise interact } }
private void ThrowItem() { if (heldItem == null) { return; } anim.SetBool("HoldingPot", false); anim.SetBool("HoldingItem", false); heldItem.Drop(); // Check if held item is the pot if (heldItem is Crockpot) { // Throw pot Vector3 otherPosition = GameController.Instance.GetOtherPlayer(this).transform.position; heldItem.Rb.AddForce( throwForce.x * direction, throwForce.y, (otherPosition.z - transform.position.z) * throwForce.z, ForceMode.Impulse ); } else if (heldItem is Item) { // Throw the ingredient in front of you heldItem.Rb.AddForce( throwForce.x * direction, throwForce.y, 0, ForceMode.Impulse ); } heldItem = null; throwing = false; // TODO return to idle }
void Update() { var isMoving = false; direction.x = 0; switch (currentState) { case MovementState.entering: anim.SetInteger("Direction", 3); direction.x -= 1; isMoving = true; if (transform.position.x < deliveryX) { currentState = MovementState.waiting; } break; case MovementState.returning: anim.SetInteger("Direction", 1); direction.x += 1; isMoving = true; if (transform.position.x > homeX) { currentState = MovementState.idle; } break; case MovementState.waiting: if (isCloseSocketAvailable() == true) { //interactable that is holdable is released currentHolding.Drop(); currentHolding = null; currentState = MovementState.returning; } break; case MovementState.idle: if (sourceSocket.OccupiedBy != null) { var ingredient = sourceSocket.OccupiedBy; var holdable = ingredient.GetComponent <Holdable>(); if (holdable != null) { currentHolding = holdable; currentHolding.Pickup(); } currentState = MovementState.entering; } break; } if (isMoving) { speed = targetSpeed; } else { anim.SetInteger("Direction", -1); // Goin' nowhere speed = 0; } anim.SetFloat("Speed", speed); this.transform.position += new Vector3(direction.x * speed, 0, 0); if (currentHolding != null) { var holdPosition = holdLocation.position; holdPosition.x += direction.x * 0.2f; holdPosition.y += direction.y * 0.2f; currentHolding.transform.position = holdPosition; } }
void CmdDrop() { equiped.Drop(); equiped = null; }
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); } }
void Update() { var isMoving = false; direction.y = 0; switch (currentState) { case MovementState.entering: anim.SetInteger("Direction", 2); direction.y += 1; isMoving = true; if (transform.position.y > homeY) { currentState = MovementState.waiting; } break; case MovementState.deliverating: anim.SetInteger("Direction", 0); direction.y -= 1; isMoving = true; if (transform.position.y < deliveryY) { currentState = MovementState.idle; } break; case MovementState.idle: // interactable that is holdable is released // Should be able to always do this currentHolding.Drop(); currentHolding = null; currentState = MovementState.entering; break; case MovementState.waiting: var deliverySocket = GetCookedPizzaWithOrder(); if (deliverySocket != null) { var holdable = deliverySocket.OccupiedBy.GetComponent <Holdable>(); if (holdable != null) { currentHolding = holdable; currentHolding.Pickup(); } else { Debug.Log("Pizza isn't holdable?"); } currentState = MovementState.deliverating; } break; } if (isMoving) { speed = targetSpeed; } else { anim.SetInteger("Direction", -1); // Goin' nowhere speed = 0; } anim.SetFloat("Speed", speed); this.transform.position += new Vector3(0, direction.y * speed, 0); if (currentHolding != null) { var holdPosition = holdLocation.position; holdPosition.x += direction.x * 0.2f; holdPosition.y += direction.y * 0.2f; currentHolding.transform.position = holdPosition; } }