Added the need for multiple wipes to rid dirt and spray while also fading the dirt and spray texture with each wipe

This commit is contained in:
Gregory Campbell
2020-06-03 18:27:09 -04:00
parent eea7c91968
commit b51a31b643
6 changed files with 30 additions and 3 deletions
+16 -1
View File
@@ -7,6 +7,8 @@ public class DirtScript : MonoBehaviour
public GameObject Spray; public GameObject Spray;
private bool sprayed = false; private bool sprayed = false;
private int wiped = 0;
Color tmp;
void OnCollisionEnter2D(Collision2D other){ void OnCollisionEnter2D(Collision2D other){
@@ -16,9 +18,22 @@ public class DirtScript : MonoBehaviour
Instantiate(Spray, new Vector2(this.transform.position.x, this.transform.position.y), Quaternion.identity); Instantiate(Spray, new Vector2(this.transform.position.x, this.transform.position.y), Quaternion.identity);
} }
}
void OnCollisionExit2D(Collision2D other){
tmp = this.GetComponent<SpriteRenderer>().color;
if(other.gameObject.name == "Rag" && sprayed) if(other.gameObject.name == "Rag" && sprayed)
{ {
Destroy(this.gameObject);
wiped++;
tmp.a -= 0.15f;
this.GetComponent<SpriteRenderer>().color = tmp;
if(wiped >= 3) Destroy(this.gameObject);
} }
} }
+14 -2
View File
@@ -5,11 +5,23 @@ using UnityEngine;
public class SprayScript : MonoBehaviour public class SprayScript : MonoBehaviour
{ {
void OnCollisionEnter2D(Collision2D other){ private int wiped = 0;
Color tmp;
void OnCollisionExit2D(Collision2D other){
tmp = this.GetComponent<SpriteRenderer>().color;
if(other.gameObject.name == "Rag") if(other.gameObject.name == "Rag")
{ {
Destroy(this.gameObject);
wiped++;
tmp.a -= 0.15f;
this.GetComponent<SpriteRenderer>().color = tmp;
if(wiped >= 3) Destroy(this.gameObject);
} }
} }
Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.
Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 KiB

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.