push sound

This commit is contained in:
DominikB
2023-06-24 14:22:30 +02:00
parent 63e74b9229
commit d3b407ea48
10 changed files with 490 additions and 1000 deletions

View File

@@ -7,6 +7,9 @@ public class IsPushingTester: MonoBehaviour
private Animator animator;
private Rigidbody2D rb;
private bool isColliding;
public AudioSource audioSource; // Reference to the AudioSource component
public AudioClip pushSound; // The sound clip to be played
public bool isPlaying = false; // Boolean to control the sound loop
void Start()
@@ -21,11 +24,20 @@ public class IsPushingTester: MonoBehaviour
if (isColliding && rb.velocity.magnitude > 0.1f)
{
animator.SetBool("IsPushing", true);
if(!isPlaying){
audioSource.clip = pushSound;
audioSource.loop = true;
audioSource.Play();
isPlaying = true;}
}
else
{
animator.SetBool("IsPushing", false);
audioSource.Stop();
isPlaying = false;
}
}

View File

@@ -10,6 +10,7 @@ public Sprite originalSprite;
public Sprite activatedSprite;
public AudioSource audioSource; // Reference to the AudioSource component
public AudioClip buttonClickSound; // The sound clip to be played
public AudioClip doorOpenSound;
private bool isActive = false;
// Start is called before the first frame update
void Start()
@@ -29,6 +30,7 @@ void OnTriggerEnter2D(Collider2D other) {
spriteRenderer.sprite = activatedSprite;
if(!isActive){
audioSource.PlayOneShot(buttonClickSound);
audioSource.PlayOneShot(doorOpenSound);
isActive = true;
}
}