2020-06-02 20:11:26 -04:00
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2020-06-10 19:24:54 -04:00
|
|
|
[RequireComponent(typeof(AudioSource))]
|
2020-06-02 20:11:26 -04:00
|
|
|
public class DirtScript : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public GameObject Spray;
|
2020-06-10 19:55:09 -04:00
|
|
|
public GameObject Particles;
|
2020-06-10 19:24:54 -04:00
|
|
|
public AudioClip[] WipeSounds;
|
|
|
|
|
public AudioClip[] SpraySounds;
|
2020-06-02 20:11:26 -04:00
|
|
|
|
|
|
|
|
private bool sprayed = false;
|
2020-06-03 18:27:09 -04:00
|
|
|
private int wiped = 0;
|
|
|
|
|
Color tmp;
|
2020-06-10 19:24:54 -04:00
|
|
|
AudioSource soundPlayer;
|
|
|
|
|
|
|
|
|
|
void Start()
|
|
|
|
|
{
|
|
|
|
|
soundPlayer = GetComponent<AudioSource>();
|
|
|
|
|
}
|
2020-06-02 20:11:26 -04:00
|
|
|
|
2020-06-05 14:49:25 -04:00
|
|
|
void OnTriggerEnter2D(Collider2D other){
|
2020-06-02 20:11:26 -04:00
|
|
|
|
|
|
|
|
if(other.gameObject.name == "SprayBottle" && !sprayed)
|
|
|
|
|
{
|
|
|
|
|
sprayed = true;
|
2020-06-06 19:44:55 -04:00
|
|
|
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));
|
2020-06-10 19:24:54 -04:00
|
|
|
soundPlayer.PlayOneShot(SpraySounds[Random.Range(0, SpraySounds.Length)]);
|
2020-06-10 19:55:09 -04:00
|
|
|
Instantiate(Particles, new Vector2(this.transform.position.x, this.transform.position.y), Quaternion.identity);
|
2020-06-02 20:11:26 -04:00
|
|
|
}
|
|
|
|
|
|
2020-06-03 18:27:09 -04:00
|
|
|
}
|
|
|
|
|
|
2020-06-05 14:49:25 -04:00
|
|
|
void OnTriggerExit2D(Collider2D other){
|
2020-06-03 18:27:09 -04:00
|
|
|
|
|
|
|
|
tmp = this.GetComponent<SpriteRenderer>().color;
|
|
|
|
|
|
2020-06-02 20:11:26 -04:00
|
|
|
if(other.gameObject.name == "Rag" && sprayed)
|
|
|
|
|
{
|
2020-06-03 18:27:09 -04:00
|
|
|
|
|
|
|
|
wiped++;
|
|
|
|
|
|
|
|
|
|
tmp.a -= 0.15f;
|
|
|
|
|
this.GetComponent<SpriteRenderer>().color = tmp;
|
|
|
|
|
|
2020-06-10 19:24:54 -04:00
|
|
|
if(wiped >= 3)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
AudioSource.PlayClipAtPoint(WipeSounds[Random.Range(0, WipeSounds.Length)], Camera.main.transform.position );
|
2020-06-10 19:55:09 -04:00
|
|
|
Instantiate(Particles, new Vector2(this.transform.position.x, this.transform.position.y), Quaternion.identity);
|
|
|
|
|
Destroy(this.gameObject);
|
2020-06-10 19:24:54 -04:00
|
|
|
|
|
|
|
|
}
|
2020-06-03 18:27:09 -04:00
|
|
|
|
2020-06-02 20:11:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|