Added a bunch of features
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Flash : MonoBehaviour {
|
||||
SpriteRenderer spriteRenderer;
|
||||
|
||||
float alpha = 1.0f;
|
||||
const float gradient = 0.1f;
|
||||
const float period = 0.1f;
|
||||
|
||||
float lastClick; //prevent double exposure
|
||||
|
||||
void Awake() {
|
||||
spriteRenderer = GetComponent<SpriteRenderer> ();
|
||||
|
||||
spriteRenderer.color = new Color (1f, 1f, 1f, 0f);
|
||||
}
|
||||
|
||||
public void StartFlash() {
|
||||
StartCoroutine (FlashCoroutine ());
|
||||
}
|
||||
|
||||
IEnumerator FlashCoroutine() {
|
||||
lastClick = Time.time;
|
||||
float thisClick = lastClick;
|
||||
|
||||
alpha = 1.0f;
|
||||
|
||||
while (alpha > 0) {
|
||||
yield return new WaitForSeconds (period);
|
||||
|
||||
if (thisClick != lastClick) {
|
||||
break;
|
||||
}
|
||||
|
||||
alpha -= gradient;
|
||||
spriteRenderer.color = new Color (1f, 1f, 1f, alpha);
|
||||
}
|
||||
}
|
||||
}
|
||||
Generated
+13
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5f42feb702d6b2b49a80e802d2811da4
|
||||
timeCreated: 1523426005
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class SoundController : MonoBehaviour {
|
||||
AudioSource audioSource;
|
||||
public AudioClip snapShot;
|
||||
|
||||
void Awake() {
|
||||
audioSource = GetComponent<AudioSource> ();
|
||||
}
|
||||
|
||||
public void PlaySnapShot() {
|
||||
audioSource.PlayOneShot (snapShot, 1.0f);
|
||||
}
|
||||
}
|
||||
Generated
+13
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c721dd74b396cd74c8a87e1944178d3e
|
||||
timeCreated: 1523425291
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user