using System.Collections; using System.Collections.Generic; using UnityEngine; public class IsMovingTester : MonoBehaviour { private Animator animator; private Rigidbody2D rb; public AudioSource audioSource; // Reference to the AudioSource component public AudioClip watschelSound; // The sound clip to be played public bool isPlaying = false; // Boolean to control the sound loop private FallingDetection fallingDetection; void Start() { animator = GetComponent(); rb = GetComponent(); fallingDetection = gameObject.GetComponent(); } void Update() { if (rb.velocity.magnitude > 0.1f) { animator.SetBool("IsMoving", true); //Bewegt sich gerade und kein anderer Wert ist an, ausserdem Spielt es noch nicht if (!animator.GetBool("IsPushing") && !animator.GetBool("IsFalling")&&!fallingDetection.isJumping){ if(!isPlaying){ audioSource.clip = watschelSound; audioSource.loop = true; audioSource.Play(); isPlaying = true;} } else { audioSource.Stop(); isPlaying = false; } } else { animator.SetBool("IsMoving", false); audioSource.Stop(); isPlaying = false; } } }