Added spray and wipe sounds for when dirt gets sprayed on and destroyed respectively

This commit is contained in:
Gregory Campbell
2020-06-10 19:24:54 -04:00
parent aa1525a7d5
commit 32c7f0c5f4
2 changed files with 120 additions and 1 deletions
+17 -1
View File
@@ -2,13 +2,22 @@
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(AudioSource))]
public class DirtScript : MonoBehaviour
{
public GameObject Spray;
public AudioClip[] WipeSounds;
public AudioClip[] SpraySounds;
private bool sprayed = false;
private int wiped = 0;
Color tmp;
AudioSource soundPlayer;
void Start()
{
soundPlayer = GetComponent<AudioSource>();
}
void OnTriggerEnter2D(Collider2D other){
@@ -16,6 +25,7 @@ public class DirtScript : MonoBehaviour
{
sprayed = true;
Instantiate(Spray, new Vector2(this.transform.position.x, this.transform.position.y), Quaternion.Euler(Random.Range(0, 2)*180, Random.Range(0, 2)*180, 0));
soundPlayer.PlayOneShot(SpraySounds[Random.Range(0, SpraySounds.Length)]);
}
}
@@ -32,7 +42,13 @@ public class DirtScript : MonoBehaviour
tmp.a -= 0.15f;
this.GetComponent<SpriteRenderer>().color = tmp;
if(wiped >= 3) Destroy(this.gameObject);
if(wiped >= 3)
{
AudioSource.PlayClipAtPoint(WipeSounds[Random.Range(0, WipeSounds.Length)], Camera.main.transform.position );
Destroy(this.gameObject);
}
}