using UnityEngine; namespace Gamekit2D { public class FmodPlayer : MonoBehaviour { private float distance = 0.05f; private float Material; private bool wasGrounded = true; private LayerMask LM = 1 << 31; private FMOD.Studio.EventInstance Footsteps; private PlayerCharacter pc; public FMOD.Studio.EventInstance Falling; [HideInInspector] public bool playerSubmerged = false; void Start() { Footsteps = FMODUnity.RuntimeManager.CreateInstance("event:/SFX/Ellen/Ellen_Footsteps"); FMODUnity.RuntimeManager.AttachInstanceToGameObject(Footsteps, transform, GetComponent()); pc = GetComponent(); } void PlayMeleeEvent(string path) { FMODUnity.RuntimeManager.PlayOneShot(path, transform.position); } void FixedUpdate() { MaterialCheck(); Debug.DrawRay(transform.position, Vector2.down * distance, Color.blue); PlayerLanded(); wasGrounded = IsGrounded(); IsGrounded(); PlayerFalling(); } void MaterialCheck() { RaycastHit2D hit; hit = Physics2D.Raycast(transform.position, Vector2.down, distance, LM); if (hit.collider) { if (hit.collider.tag == "Material: Earth") Material = 1f; else if (hit.collider.tag == "Material: Stone") Material = 2f; else Material = 1f; } } void PlayFootstepsEvent() { Footsteps.setParameterValue("Material", Material); Footsteps.start(); } void OnDestroy() { Footsteps.release(); Falling.release(); } void PlayerFalling() { FMOD.Studio.PLAYBACK_STATE PbState; Falling.getPlaybackState(out PbState); if (!IsGrounded() && pc.m_MoveVector.y < -3 && !playerSubmerged) { Falling.setParameterValue("Velocity", pc.m_MoveVector.y); if (PbState != FMOD.Studio.PLAYBACK_STATE.PLAYING) { Falling = FMODUnity.RuntimeManager.CreateInstance("event:/SFX/Ellen/Ellen_Falling"); Falling.start(); Falling.release(); } } } void PlayerLanded() { if (IsGrounded() && !wasGrounded && pc.m_MoveVector.y < 0) { FMOD.Studio.EventInstance Landing = FMODUnity.RuntimeManager.CreateInstance("event:/SFX/Ellen/Ellen_Land"); FMODUnity.RuntimeManager.AttachInstanceToGameObject(Landing, transform, GetComponent()); Landing.setParameterValue("Velocity", pc.m_MoveVector.y); Footsteps.setParameterValue("FootstepDuck", pc.m_MoveVector.y); Landing.start(); Landing.release(); Falling.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT); } } bool IsGrounded() { return Physics2D.Raycast(transform.position, Vector2.down, distance, LM); } } }