public void EnterCode(int codeValue) { if (cabinetOpen) { if (waitForCodeCheck == false) { SfxManager.PlaySfx(16); if (passCodeDisplay.text == "---") { passCodeDisplay.text = codeValue.ToString(); } else { passCodeDisplay.text += codeValue; } if (passCodeDisplay.text.Length == 3) { waitForCodeCheck = true; if (numAttempts == 9) { //Play right sound and move elevator numAttempts = 0; } else { StartCoroutine(checkCode(int.Parse(passCodeDisplay.text))); } } } } }
IEnumerator MonsterHit() { while (true) { if (codeAccepted == false) { lightParticleIndex++; SfxManager.PlaySfx(Random.Range(27, 33)); CameraShake.ShakeCamera(0.1f, 0.7f); ElevatorLightBurst(lightParticleIndex % 4); if (lightParticleIndex <= 5) { lightControl.CeilingLightOff(lightParticleIndex % 5); } SfxManager.PlaySfx(Random.Range(21, 26)); yield return(new WaitForSeconds(Random.Range(1f, 10f))); } else { break; } } }
/// <summary> /// 播放特效 /// </summary> public void PlaySfx(int id) { if (sfxManager == null) { return; } sfxManager.PlaySfx(id); }
void OnCollisionEnter(Collision other) { SoundEffects[] sfx = other.gameObject.GetComponents <SoundEffects>(); foreach (SoundEffects s in sfx) { if (!s.loop) { SfxManager.PlaySfx(s.id); } } }
IEnumerator OpenCabinetDoor() { Transform targetAngle = cabinetDoor.Find("TargetAngle"); //Play panel open sound SfxManager.PlaySfx(15); cabinetDoor.forward = Vector3.Slerp(cabinetDoor.forward, targetAngle.forward, 5f); cabinetOpen = true; yield return(null); }
private void CheckForInput() { if (_isOnGround || _doubleJump) { if (Input.GetKeyDown(key: KeyCode.Space)) { if (_doubleJump && !_isOnGround) { sFXManager.PlaySfx("DoubleJump"); _doubleJump = false; } sFXManager.PlaySfx("Jump"); _jump = true; _isOnGround = false; animator.SetTrigger(Jump); animator.SetBool(IsGrounded, false); } } }
void CancelAction() { Vector3 screenPosition = Input.mousePosition; screenPosition.z = 10f; Vector3 worldPosition = Camera.main.ScreenToWorldPoint(screenPosition); worldPosition.z = 0f; Vector2 pos = new Vector2(Mathf.Round(worldPosition.x), Mathf.Floor(worldPosition.y)); int taskId = Tasks.GetTaskAtXY((int)pos.x, -(int)pos.y); if (taskId != -1) { if (Tasks.TaskList[taskId].Status == 1) { Tasks.TaskList[taskId].Claimant.ForgetTask(); } Tasks.RemoveTask(taskId); SfxPlayer.PlaySfx(9); } }
private IEnumerator MoveDoorsRoutine(float start, float end, float waitTime = 0) { yield return(new WaitForSeconds(waitTime)); bool opening = start < end; if (floorsVisited == 0) { SfxManager.PlaySfx(opening ? 3 : 2); } else { if (opening) { SfxManager.PlaySfx(3); } else { // Play broken door sfx instead SfxManager.PlaySfx(Random.Range(34, 36)); } } while (opening ? doorPosition <end : doorPosition> end) { doorPosition += elevatorDoorSpeed * ((start < end) ? Time.deltaTime : -Time.deltaTime); if (opening && !canOpenDoors) { leftDoor.localPosition = Vector3.Lerp(leftDoorClosedPosition, leftDoorOpenPosition, doorPositionCurve.Evaluate(doorPosition)); rightDoor.localPosition = Vector3.Lerp(rightDoorClosedPosition, rightDoorOpenPosition, doorPositionCurve.Evaluate(doorPosition)); } else { leftDoor.localPosition = Vector3.Lerp(leftDoorClosedPosition, leftDoorOpenPosition, doorPosition); rightDoor.localPosition = Vector3.Lerp(rightDoorClosedPosition, rightDoorOpenPosition, doorPosition); } yield return(null); } doorPosition = opening ? Mathf.Min(doorPosition, end, 1) : Mathf.Max(doorPosition, end, 0); moveDoorsRoutine = null; }
private IEnumerator checkCode(int codeValue) { yield return(new WaitForSeconds(2f)); string compareStr = "11"; string firstTwoDigits = codeValue.ToString().Substring(0, 2); Debug.Log(string.Compare(firstTwoDigits, compareStr)); if (numAttempts >= 5 && !attempts.Contains(codeValue) && string.Compare(firstTwoDigits, compareStr) == 0) { //Right codeAccepted = true; passCodeDisplay.text = ""; SfxManager.PlaySfx(18); yield return(new WaitForSeconds(1f)); MoveFloor(5); } else { //Wrong //check for unique attempts Debug.Log(codeValue); Debug.Log(attempts.Contains(codeValue)); if (!attempts.Contains(codeValue)) { numAttempts++; attempts.Add(codeValue); } passCodeDisplay.text = "RETRY"; SfxManager.PlaySfx(17); yield return(new WaitForSeconds(1f)); passCodeDisplay.text = "---"; waitForCodeCheck = false; } }
private IEnumerator MoveFloorsRoutine(int start, int end) { if (doorPosition > 0) { if (floorsVisited == 0) { yield return(StartCoroutine(MoveDoorsRoutine(doorPosition, 0, waitTime: 3))); } else { yield return(StartCoroutine(MoveDoorsRoutine(doorPosition, doorPosition - 0.1f, waitTime: 1))); if (doorPosition > 0) { moveFloorsRoutine = null; yield break; } } } yield return(new WaitForSeconds(1)); SfxManager.PlayLoop(1); int floorProgress = 0; string directionArrow = (start < end) ? "v " : "^ "; floorDisplay.text = directionArrow + (floorPosition == 0 ? "1F" : "B" + floorPosition); while ((start < end) ? floorPosition <end : floorPosition> end) { if (floorsVisited == 0 && floorProgress == 2) // Elevator crash cutscene { yield return(new WaitForSeconds(elevatorFloorInterval * 0.5f)); SfxManager.StopLoop(0); SfxManager.StopLoop(1); SfxManager.PlaySfx(4); CameraShake.ShakeCamera(0.3f, 5); // Shake Camera for 5 seconds for (int i = 0; i < 5; i++) // Lights flash for a bit { lightControl.AllLightsOff(); floorDisplay.gameObject.SetActive(false); yield return(new WaitForSeconds(0.15f)); lightControl.AllLightsOn(); floorDisplay.gameObject.SetActive(true); yield return(new WaitForSeconds(0.1f)); } // Lights turn off lightControl.AllLightsOff(); floorDisplay.gameObject.SetActive(false); yield return(new WaitForSeconds(5)); SfxManager.PlaySfx(19); // Evacuation announcement yield return(new WaitForSeconds(20)); SfxManager.PlaySfx(5); // Lights turn on sound yield return(new WaitForSeconds(1)); // Lights back on lightControl.AllLightsOn(); floorDisplay.gameObject.SetActive(true); yield return(new WaitForSeconds(2)); //shepardTone.SetActive(true); SfxManager.PlayLoop(0); SfxManager.PlayLoop(1, 0.1f); SfxManager.PlayLoop(3); yield return(new WaitForSeconds(elevatorFloorInterval * 0.5f)); } else if (floorPosition == 4 && end == 5) // Last cutscene part 1 { onRouteToSecret = true; StartCoroutine(AnimateFloorDisplay()); yield return(new WaitForSeconds(10)); onRouteToSecret = false; } else { yield return(new WaitForSeconds(elevatorFloorInterval * 0.5f)); SfxManager.StopLoop(4); } floorProgress++; SfxManager.PlaySfx(1); floorPosition += (start < end) ? 1 : -1; floorDisplay.text = directionArrow + "B" + floorPosition; } floorDisplay.text = floorPosition == 0 ? " 1F" : " B" + floorPosition; if (floorPosition == 5) { floorDisplay.text = "EXIT"; } if (floorPosition == 0) { SfxManager.PlayLoop(4); } SfxManager.StopLoop(1); yield return(new WaitForSeconds(1)); if (floorsVisited == 1) //Floor 2 Cut Scene { floor1.SetActive(false); floor2.transform.position = Vector3.zero; floor2.SetActive(true); yield return(StartCoroutine(MoveDoorsRoutine(0, 1))); SfxManager.PlaySfx(9); yield return(new WaitForSeconds(2)); SfxManager.PlaySfx(10); Coroutine flickerLightsRoutine = StartCoroutine(FlickerElevatorLights()); yield return(new WaitForSeconds(8)); canCloseDoors = true; yield return(new WaitForSeconds(8)); canCloseDoors = false; // Play banging effect/cutscene yield return(StartCoroutine(MoveDoorsRoutine(doorPosition, 0))); StopCoroutine(flickerLightsRoutine); lightControl.AllLightsOn(); floor2.SetActive(false); SfxManager.PlaySfx(11); CameraShake.ShakeCamera(0.3f, 2); SfxManager.PlaySfx(25); yield return(new WaitForSeconds(2)); SfxManager.PlaySfx(12); CameraShake.ShakeCamera(0.3f, 2); SfxManager.PlaySfx(23); yield return(new WaitForSeconds(1)); //SfxManager.PlaySfx(13); // Intercom message StartCoroutine(OpenCabinetDoor()); passCodeDisplay.text = "---"; yield return(new WaitForSeconds(10)); StartCoroutine(MonsterHit()); } else if (floorsVisited == 2) //Floor 3 Cutscene { floor2.SetActive(false); floor3.transform.position = Vector3.zero; floor3.SetActive(true); yield return(StartCoroutine(MoveDoorsRoutine(0, 1))); yield return(new WaitForSeconds(3)); cameraFade.CutToBlack(); yield return(new WaitForSeconds(5)); sfxBehindYou.SetActive(true); yield return(new WaitForSeconds(1)); cameraFade.CutFromBlack(); StartCoroutine(JumpScareScene()); } else { yield return(StartCoroutine(MoveDoorsRoutine(0, 1))); } floorsVisited++; moveFloorsRoutine = null; }
// Update is called once per frame void Update() { if (gameOver && !win && !gameFinished) { //Sound management bgmManager.StopBgm(); sfxManager.PlaySfx(gameoverSfx); //for this boolean see description on declaration gameFinished = true; anim.SetBool("Lose", true); gameoverTextAnim.enabled = true; menuBtn2Anim.enabled = true; restartBtn2Anim.enabled = true; snailSadAnim.enabled = true; shells.timeIsRunning = false; gameOverText.enabled = true; gameover.enabled = true; menuBtn2.enabled = true; restartBtn2.enabled = true; snailSad.enabled = true; menu2.enabled = true; restart2.enabled = true; } if (win && !gameOver && !gameFinished) { //Sound management bgmManager.StopBgm(); sfxManager.PlaySfx(winSfx); //for this boolean see description on declaration gameFinished = true; winTextAnim.enabled = true; menuBtnAnim.enabled = true; nextBtnAnim.enabled = true; restartBtnAnim.enabled = true; snailHappyAnim.enabled = true; shells.timeIsRunning = false; //Time.timeScale = 0; winText.enabled = true; //Application.LoadLevel(nextLevel); winning.enabled = true; shellTemplate.enabled = true; menuBtn.enabled = true; restartBtn.enabled = true; nextBtn.enabled = true; snailHappy.enabled = true; scoreText.enabled = true; score.text = "Score : " + shells.starScore * 1000; if (shells.starScore == 1) { shell1Anim.enabled = true; shell1.enabled = true; } else if (shells.starScore == 2) { shell1Anim.enabled = true; shell2Anim.enabled = true; shell1.enabled = true; shell2.enabled = true; } else if (shells.starScore == 3) { shell1Anim.enabled = true; shell2Anim.enabled = true; shell3Anim.enabled = true; shell1.enabled = true; shell2.enabled = true; shell3.enabled = true; } menu.enabled = true; next.enabled = true; restart.enabled = true; } }
public void Yay() { SfxManager.PlaySfx("Laser"); }
void OnTriggerEnter(Collider c) { onButtonPress.Invoke(); SfxManager.PlaySfx(0); buttonVisual.localPosition = Vector3.forward * 0.09f; }
void Update() { Debug.DrawLine(hip.position, head.position, Color.blue); Vector3 lean = head.position - hip.position; Vector3 leanDirection = Vector3.ProjectOnPlane(lean, Vector3.up); Debug.DrawRay(hip.position, leanDirection, Color.red); float xAxis = leanDirection.x; float zAxis = leanDirection.z; if (keyControls) { xAxis = Input.GetAxis("Horizontal"); zAxis = -Input.GetAxis("Vertical"); lean = Vector3.up; } if (canMove) { // Normal controls if (wireTransform == null) { float height = hip.position.y; if (prevHeights.Count < 60) { prevHeights.Enqueue(height); } else { float avgPrevHeight = prevHeights.Sum() / prevHeights.Count(); if (height - avgPrevHeight > 0.1f || (keyControls && Input.GetKey(KeyCode.Space))) { if (Time.time - lastJumpTime > jumpDelay) { rigidbody.velocity += jumpStrength * Vector3.up; speed = Mathf.Max(speed, 3f); lastJumpTime = Time.time; SfxManager.PlaySfx(1); } } prevHeights.Enqueue(height); prevHeights.Dequeue(); } // Tilt the button when turning float leanAngle = (xAxis < 0 ? 1 : -1) * Vector3.Angle(Vector3.up, Vector3.ProjectOnPlane(lean, Vector3.forward)); tiltAnchor.localEulerAngles = new Vector3(0, 0, leanAngle); // Turn the button angle = (angle + xAxis * 180 * Time.deltaTime) % 360; // Accelerate/Decelerate the button if (zAxis < 0) // Forward { speed = Mathf.Min(maxSpeed, speed - zAxis * 5 * Time.deltaTime); } else if (zAxis > 0.2f) // Backward { speed = Mathf.Max(-maxSpeed, speed - zAxis * 3 * Time.deltaTime); } else { speed = Mathf.Lerp(speed, 0, 0.5f * Time.deltaTime); } // Spin the button based on the speed buttonSpin = (buttonSpin + 360 * speed * Time.deltaTime) % 360; buttonAnchor.localEulerAngles = Vector3.right * buttonSpin; // Rotate the button transform.eulerAngles = Vector3.up * angle; // Set the speed of the button Vector3 gravity = Vector3.Project(rigidbody.velocity, Vector3.down); rigidbody.velocity = Quaternion.Euler(0, angle, 0) * Vector3.forward * speed + gravity; //rigidbody.AddForce(Quaternion.Euler(0, angle, 0) * Vector3.forward * speed); } else // Wire controls { // Accelerate/Decelerate the button if (zAxis < 0) // Forward { speed = Mathf.Min(maxSpeed, speed - zAxis * 5 * Time.deltaTime); } else if (zAxis > 0.2f) // Backward { speed = Mathf.Max(0, speed - zAxis * 3 * Time.deltaTime); } else { speed = Mathf.Lerp(speed, 0, 0.5f * Time.deltaTime); } Debug.Log(xAxis); buttonLean += buttonLeanSpeed * Time.deltaTime; buttonLean = Mathf.Clamp(buttonLean, -60, 60); buttonLeanSpeed -= xAxis * 100 * Time.deltaTime; buttonLeanSpeed += Mathf.Sign(buttonLeanSpeed) * (1 + speed) * Time.deltaTime; tiltAnchor.localEulerAngles = new Vector3(0, 0, buttonLean); Vector3 gravity = Vector3.Project(rigidbody.velocity, Vector3.down); /* * if (Mathf.Abs(buttonLean) > 75f) * { * Physics.IgnoreLayerCollision(LayerMask.NameToLayer("ObstaclePlatform"), LayerMask.NameToLayer("Player"), true); * } * else * {*/ transform.eulerAngles = new Vector3(0, wireTransform.eulerAngles.y, 0); rigidbody.velocity = wireTransform.forward * speed + gravity; //} // Spin the button based on the speed buttonSpin = (buttonSpin + 360 * speed * Time.deltaTime) % 360; buttonAnchor.localEulerAngles = Vector3.right * buttonSpin; } } else { angle = Mathf.Clamp(angle + xAxis * 180 * Time.deltaTime, 150, 250); speed = 0; transform.eulerAngles = Vector3.up * angle; rigidbody.velocity = Vector3.zero; } }