// Plays the sound only once per state Sonic is in void PlayOnce(AudioClip SoundFile, CharControlMotor.SonicState currentState) { if (prevState != currentState) { prevState = currentState; SonicJumpSound.PlayOneShot(SoundFile); } }
// Update is called once per frame void Update2() { var mystate = properties.sonicState; switch (mystate) { case CharControlMotor.SonicState.Normal: // Released peel charge if (prevState == CharControlMotor.SonicState.ChargingPeel) { PlayOnce(chosenSounds[5], mystate); } break; case CharControlMotor.SonicState.ChargingPeel: PlayOnce(chosenSounds[4], mystate); break; case CharControlMotor.SonicState.Peel: // Released peel charge if (prevState == CharControlMotor.SonicState.ChargingPeel) { PlayOnce(chosenSounds[5], mystate); } break; case CharControlMotor.SonicState.ChargingSpin: if (Input.GetButtonDown("Jump")) { PlaySound(chosenSounds[6]); } break; case CharControlMotor.SonicState.Spindash: if (!CurrentlyActive) { CurrentlyActive = true; PlaySound(chosenSounds[7]); } break; case CharControlMotor.SonicState.SpinningAir: break; case CharControlMotor.SonicState.Brake: PlayOnce(chosenSounds[8], mystate); break; } // Reset the state for one-time SFX if (mystate == CharControlMotor.SonicState.Normal) { prevState = mystate; } if (!properties.jumped && mystate == CharControlMotor.SonicState.Normal && CurrentlyActive) { CurrentlyActive = false; } if (properties.jumped && !CurrentlyActive) { CurrentlyActive = true; PlaySound(chosenSounds[0]); } if (properties.RingGotB) { properties.RingGotB = false; PlaySound(chosenSounds[1]); } if (properties.GotHurtCheck && !properties.Death) { // Ring Loss sound is separate from Sonic's sounds SonicRingLossSound.Play(); //PlaySound(chosenSounds[2]); } if (properties.GotHurtCheck && properties.Death) { PlaySound(chosenSounds[3]); } }
// Update is called once per frame void LateUpdate() { CharControlMotor.SonicState state = charCtrl.state.stateId; // Stop following Sonic when he dies if (state == CharControlMotor.SonicState.Dead) { return; } // Set the camera to Sonic's location when charging spin or peel else if (state == CharControlMotor.SonicState.ChargingPeel || state == CharControlMotor.SonicState.ChargingSpin || state == CharControlMotor.SonicState.Peel || state == CharControlMotor.SonicState.Spindash) { // Reset the offset so it's focused back on Sonic currentOffset = Vector2.zero; // Fix the camera on Sonic's position thisTrans.position = new Vector3(followTarget.position.x, followTarget.position.y, thisTrans.position.z); return; } Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")); if (input.y != 0 && (charCtrl == null || charCtrl.speedvar.CompareTo(0f) == 0)) { if (Mathf.Sign(input.y) != Mathf.Sign(vertHeld)) { vertHeld = 0; } if (input.y > 0) { vertHeld += Time.deltaTime; } else { vertHeld -= Time.deltaTime; } } else { vertHeld = 0; } Vector2 targetPos = new Vector2(sideDistance * input.x, 0); if (Mathf.Abs(vertHeld).CompareTo(vertHoldtime) >= 0) { targetPos.y = (vertHeld > 0 ? vertDistance.y : vertDistance.x) * input.y; } else { targetPos.y = 0; } currentOffset = Vector2.SmoothDamp(currentOffset, targetPos, ref followSmooth, smoothTime, maxSpeed, Time.deltaTime * ((affectedByPause) ? Time.timeScale : 1)); Vector3 newPos = followTarget.position; newPos.x += currentOffset.x; newPos.y += currentOffset.y; if (followZ) { newPos.z = followTarget.position.z; } else { newPos.z = thisTrans.position.z; } thisTrans.position = newPos; }