Added a bunch of features
This commit is contained in:
@@ -5,19 +5,31 @@ using UnityEngine;
|
||||
public class Monster : MonoBehaviour {
|
||||
public int value;
|
||||
|
||||
Rigidbody2D rigidBody;
|
||||
|
||||
void Awake() {
|
||||
StartCoroutine (DestroySelfAfter (30f));
|
||||
rigidBody = GetComponent<Rigidbody2D> ();
|
||||
|
||||
StartCoroutine (ReverseDirectionAfter (2f));
|
||||
StartCoroutine (DestroySelfAfter (4f));
|
||||
}
|
||||
|
||||
void OnMouseOver() {
|
||||
if (Input.GetMouseButtonDown(0)) {
|
||||
//TODO: play death sound
|
||||
GameObject.Find ("SoundController").GetComponent<SoundController> ().PlaySnapShot ();
|
||||
GameObject.Find ("Flash").GetComponent<Flash> ().StartFlash ();
|
||||
PersistentData.score += value;
|
||||
Destroy (gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator ReverseDirectionAfter(float seconds) {
|
||||
yield return new WaitForSeconds (seconds);
|
||||
rigidBody.velocity = new Vector2 (-rigidBody.velocity.x, -rigidBody.velocity.y);
|
||||
}
|
||||
|
||||
IEnumerator DestroySelfAfter(float seconds) {
|
||||
//clean up lost objects
|
||||
yield return new WaitForSeconds (seconds);
|
||||
Destroy (gameObject);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user