push sound
This commit is contained in:
@@ -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;
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user