using UnityEngine; public class FmodPlayer : MonoBehaviour { private float distance = 0.05f; private float Material; private bool wasGrounded = true; private LayerMask LM = 1 << 31; private float Height; private float old_Height; private float Height_Difference; FMOD.Studio.EventInstance Footsteps; void Start() { Footsteps = FMODUnity.RuntimeManager.CreateInstance("event:/SFX/Ellen/Ellen_Footsteps"); } 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(); PlayerFallingCheck(); Footsteps.setParameterValue("Material", Material); } 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.start(); } void OnDestroy() { Footsteps.release(); } void PlayerLanded() { if (IsGrounded() && !wasGrounded) { FMOD.Studio.EventInstance Landing = FMODUnity.RuntimeManager.CreateInstance("event:/SFX/Ellen/Ellen_Land"); Landing.setParameterValue("Velocity", Height_Difference); Footsteps.setParameterValue("FootstepDuck", Height_Difference); Landing.start(); Landing.release(); Debug.Log(Height_Difference); } } bool IsGrounded() { return Physics2D.Raycast(transform.position, Vector2.down, distance, LM); } void PlayerFallingCheck() { old_Height = Height; Height = transform.position.y; Height_Difference = Height - old_Height; if (Height_Difference > 0) Height_Difference = Height_Difference * -1; } }