Added marixil's work, v1.1
This commit is contained in:
@@ -13,9 +13,11 @@ public class Monster : MonoBehaviour {
|
||||
}
|
||||
|
||||
Rigidbody2D rigidBody;
|
||||
SpriteRenderer spriteRenderer;
|
||||
|
||||
void Awake() {
|
||||
rigidBody = GetComponent<Rigidbody2D> ();
|
||||
spriteRenderer = GetComponent<SpriteRenderer> ();
|
||||
}
|
||||
|
||||
void OnMouseOver() {
|
||||
@@ -36,6 +38,26 @@ public class Monster : MonoBehaviour {
|
||||
IEnumerator DestroySelfAfter(float seconds) {
|
||||
//clean up lost objects
|
||||
yield return new WaitForSeconds (seconds);
|
||||
Destroy (gameObject);
|
||||
StartCoroutine (FadeCoroutine(0.01f));
|
||||
}
|
||||
|
||||
IEnumerator FadeCoroutine(float period) {
|
||||
float absolute = 1.0f;
|
||||
float degree = -0.02f;
|
||||
|
||||
while(true) {
|
||||
//wait
|
||||
yield return new WaitForSeconds (period);
|
||||
|
||||
//fade routine
|
||||
absolute += degree;
|
||||
|
||||
//fade
|
||||
spriteRenderer.color = new Color (1, 1, 1, absolute);
|
||||
|
||||
if (absolute <= 0f) {
|
||||
Destroy (gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user