Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Activators : MonoBehaviour {
- public KeyCode Key;
- bool Active;
- GameObject Note, GM;
- SpriteRenderer SR;
- Color OldColor;
- public bool CreateMode;
- public GameObject BasicNote;
- public ParticleSystem Hit;
- public AudioSource Failure, Miss;
- public bool Inv = true;
- void Start () {
- GM = GameObject.Find ("GameManager");
- SR = GetComponent<SpriteRenderer> ();
- OldColor = SR.color;
- }
- void Update () {
- //Creating a song by hand
- if (CreateMode) {
- if (Input.GetKeyDown (Key))
- Instantiate (BasicNote, transform.position, Quaternion.identity);
- } else {
- //Invincibility at the start of a song
- if (Input.GetKeyDown (Key)) {
- StartCoroutine (pressed ());
- if (Inv == true) {
- Miss.Play ();
- }
- }
- //Hitting a note
- if (Input.GetKeyDown (Key) && Active) {
- Destroy (Note);
- GM.GetComponent<gamemanager> ().addstreak ();
- addscore ();
- Active = false;
- explode ();
- }
- //Miss a note
- else if (Input.GetKeyDown (Key) && !Active && Inv == false) {
- Miss.Play ();
- if (GM.GetComponent<gamemanager>().streak > 25) {
- Failure.Play ();
- }
- GM.GetComponent<gamemanager> ().resetstreak ();
- }
- }
- }
- void OnTriggerStay2D(Collider2D col) {
- //Player wins
- if (col.gameObject.tag == "WinNote") {
- GM.GetComponent<gamemanager> ().Win ();
- }
- //Assigning the current note
- if (col.gameObject.tag == "Note") {
- Note = col.gameObject;
- Active = true;
- }
- //Turning off invincibility
- if (col.gameObject.tag == "Inv") {
- Inv = false;
- }
- }
- void OnTriggerExit2D(Collider2D col) {
- //If the player misses a note
- GM.GetComponent<gamemanager> ().missnote ();
- Active = false;
- GM.GetComponent<gamemanager> ().resetstreak ();
- }
- void addscore () {
- //Calculate total score
- PlayerPrefs.SetInt ("Score", PlayerPrefs.GetInt ("Score") + GM.GetComponent<gamemanager> ().getscore ());
- }
- void explode () {
- //Particle effect when key is pressed
- ParticleSystem explode = Instantiate (Hit) as ParticleSystem;
- explode.transform.position = transform.position;
- explode.Play ();
- }
- IEnumerator pressed () {
- //Changes activator color when key is pressed
- SR.color = new Color (0, 0, 0);
- yield return new WaitForSeconds (0.2f);
- SR.color = OldColor;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement