//Call this for player throw. This will throw the object where the player is facing. public void ThrowObject() { if (pickupper.IsHoldingObject()) { heldObject = pickupper.HeldObject(); var throwRb = heldObject.GetComponent <Rigidbody>(); pickupper.ButtonCheck(); var vel = Projectile.GetProjectileVelocity(maxForce, throwDistance, transform.up, transform.forward); throwRb.AddForce(vel, ForceMode.VelocityChange); throwSound.Play(); heldObject = null; } else { heldObject = null; } }
// Update is called once per frame void Update() { //use button is E if (Input.GetButtonDown("Use")) { if (PickUp.IsHoldingObject()) { Usable usable = PickUp.HeldObject().GetComponent <Usable>(); if (usable != null) { usable.Use(); Debug.Log("use Pressed"); } } } }
//player actions private void PlayerActions() { float horizontal = Input.GetAxis("Horizontal"); float vertical = Input.GetAxis("Vertical"); RigidBodyController controller = GetComponentInParent <RigidBodyController>(); controller.Locomote(new Vector3(horizontal, 0, vertical)); controller.Rotate(); if (Input.GetKeyDown(KeyCode.Space)) { controller.Jump(); } if (Input.GetMouseButtonDown(0)) { //become other player on left click CreateRay(); } if (Input.GetKeyDown(KeyCode.C)) { if (CamMode == 1) { CamMode = 0; } else { CamMode++; } StartCoroutine(CamChange()); } if (Input.GetKeyDown(KeyCode.U)) { if (actionPickup && actionPickup.IsHoldingObject()) { Usable usable = actionPickup.HeldObject().GetComponent <Usable>(); if (usable) { usable.Use(); } } } if (Input.GetKeyDown(KeyCode.I)) { //checks for the actionpickup script and if it is holding an object if (actionPickup && actionPickup.IsHoldingObject()) { //get the spawner script in the children component of pickupper script actionSpawn = actionPickup.GetComponentInChildren <Spawner>(); //call spawn function actionSpawn.Spawn(); } } if (Input.GetKeyDown(KeyCode.P)) { //call pickup function actionPickup = GetComponentInParent <Pickupper>(); actionPickup.PickUp(); } if (Input.GetKeyDown(KeyCode.E)) { //call eat function actionEat = GetComponentInParent <Eat>(); actionEat.EatFood(); } if (Input.GetKeyDown(KeyCode.T)) { if (actionPickup && actionThrow && actionPickup.IsHoldingObject()) { actionThrow.ThrowObject(); } } //... more actions }