private void OnCollisionEnter(Collision other) { script = other.gameObject.GetComponent <ObjDestroy>(); if ((other.gameObject.tag == "Projectile" && script.objIsActive()) || other.gameObject.tag == "Blade") { if (!actionShield.shieldIsOn()) { if (small && !isChanging) { StartCoroutine(ReturnNormal(playerSize, duration)); } else if (!small) { SceneManager.LoadScene("MainScene"); } } else { return; } } }
//This function will activate a pickup of the nearest object within range. public void ButtonCheck() { if (buttonDown) { buttonDown = false; pickup.transform.parent = null; isHolding = false; return; } if (pickups.Count == 1 && buttonDown == false) { if (!actionShield.shieldIsOn()) { pickup = pickups[0]; buttonDown = true; inRange = true; isHolding = true; //isHoldingKey = false; } } // If there are more than one pickupables in range, // This will determine and select the nearest one. if (pickups.Count > 1 && buttonDown == false) { Vector3 currentPosition = this.transform.position; float nearestDist = Mathf.Infinity; foreach (GameObject obj in pickups) { if (obj.gameObject != null) { Vector3 dist = obj.transform.position - currentPosition; float distSqr = dist.sqrMagnitude; if (distSqr < nearestDist) { nearestDist = distSqr; pickup = obj; } } } buttonDown = true; inRange = true; isHolding = true; } }
//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(); } // KeyCode for Marie-Eve and Audrey's milestone // if (Input.GetKeyDown(KeyCode.M)) // { // if(actionShield.collectedShield()) { // if (!shieldActivated){ // shieldActivated = true; // actionPickup.dropIt(); // } else { // shieldActivated = false; // } // } else return; // // } 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.P)) { // if (!actionEat.isSmall()) { //call pickup function if (!actionShield.shieldIsOn()) { actionPickup.PickUp(); } //} } // // if (Input.GetKeyDown(KeyCode.F)) // { // // if(actionPickup.IsHoldingKey()) { // open.openDoor(); // } // // } if (Input.GetKeyDown(KeyCode.E)) { //call eat function actionEat.EatFood(); } // if (Input.GetKeyDown(KeyCode.T)) // { // if (actionPickup.IsHoldingObject()) // { // print("throw"); // actionThrow.ThrowObject(); // } // } //... more actions }