public void useItem(Item item, bool fromHand) { Debug.Log("Using Item: " + item + " - " + fromHand); switch (item.itemID) { //Add cases for each item ID that has an effect when consumed. case 0: { print("Drunk dat drink"); //Add stat increases here vitals.setEnergy(30); //increases energy levels by 30 audioSource.PlayOneShot(burpSound, 1.0f); break; } case 1: { print("Drunk dat alc"); //Add stat increases here vitals.setSoberness(-30); //lowers your soberness levels by 30 audioSource.PlayOneShot(burpSound, 1.0f); break; } case 2: { print("Where did you get this?"); //Add stat increases here break; } } //When the item is used, and is 'Destroyed when used', destroys the item if (item.destroyWhenUsed == true) { if (fromHand == true) { Destroy(GameObject.Find("FPPCamera").GetComponent <PickupDrop>().itemInHand.gameObject); itemHolding = -1; } else { updateItems(item.itemID, false); } } }
private void resetPlayer() { if (!alreadyResetting) { alreadyResetting = true; Debug.Log("Knocked out sequence finished."); audioSource.PlayOneShot(bird, 1.0f); //sets the player position to the nearest respawn point player.transform.position = findClosedPoint().transform.position; player.transform.rotation = Quaternion.Euler(0, 0, 0); //Freezes all the rotation axis player.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeRotation; switch (CurrentMode) { case Mode.Dead: //gets a reference to the health that's attached to the player and then reset the health vitals.setHealth(100); break; case Mode.Drunk: vitals.setSoberness(100.0f, true); break; case Mode.Exhausted: vitals.setEnergy(50); break; default: break; } vitals.setKnockedOutState(false); } Transform fadeTopPos = fadeTop.transform; Transform fadeBottomPos = fadeBottom.transform; //Moves the top black overlay down to the centre if (fadeTop.GetComponent <RectTransform>().localPosition.y < 1200) { fadeTop.transform.position = Vector3.Lerp(fadeTopPos.position, new Vector3(fadeTopPos.position.x, fadeTopPos.position.y + 4.0f), 100.0f * Time.deltaTime); } //moves the bottom black overlay up to the centre if (fadeBottom.GetComponent <RectTransform>().localPosition.y > -1200) { fadeBottom.transform.position = Vector3.Lerp(fadeBottomPos.position, new Vector3(fadeBottomPos.position.x, fadeBottomPos.position.y - 4.0f), 100.0f * Time.deltaTime); } else { //re-enables the disabled scripts playerController.enabled = true; CamMouseLook.enabled = true; //since the reset seqence has finished, destroy the script alreadyResetting = false; destroyScript(); } }
private void Update() { //increases and lowers the fov over time if (fovIncrease) { FPPCamera.fieldOfView += fovModifier * Time.deltaTime; if (FPPCamera.fieldOfView >= 140.0f) { fovIncrease = false; } } else { FPPCamera.fieldOfView -= fovModifier * Time.deltaTime; if (FPPCamera.fieldOfView <= 120.0f) { fovIncrease = true; } } //each frame, increase the soberness of the player vitals.setSoberness((100.0f / reduceDrunkSpeed) * Time.deltaTime); //slowly change the smooth value for the camera lerp each frame //smooth = vitals.getSoberness() / 10.0f; //slowly lower the fov modifer each frame fovModifier -= ((10.0f / reduceDrunkSpeed) * Time.deltaTime); //update the alpha of the drunk overlay image float drunkOverlayAlpha = (0.1f / 100.0f) * (100.0f - vitals.getSoberness()); drunkOverlay.color = new Color(drunkOverlay.color.r, drunkOverlay.color.g, drunkOverlay.color.b, drunkOverlayAlpha); //print("drunkOverlayAlpha = " + drunkOverlay.color.a); //update the alpha of the drunk fade image float drunkFadeAlpha = (1.0f / 100.0f) * (100.0f - vitals.getSoberness()); drunkFade.color = new Color(drunkFade.color.r, drunkFade.color.g, drunkFade.color.b, drunkFadeAlpha); //print("drunkFadeAlpha = " + drunkFade.color.a); //if the player is now sober again if (vitals.getSoberness() >= 100.0f) { drunkEnding = true; //ensures the sober value is exactly 100.0f | 100% vitals.setSoberness(100.0f, true); //reset the player fov over time FPPCamera.fieldOfView = Mathf.Lerp(FPPCamera.fieldOfView, initialFOV, resetFOVTimer); resetFOVTimer += (1.0f / 100.0f) * Time.deltaTime; } //only destroy the script one the fov has finished resetting if (FPPCamera.fieldOfView - Mathf.Abs(initialFOV) < 1.0f && drunkEnding) { destroyScript(); } }