Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PickUpManager : MonoBehaviour {
- // singleton
- public static PickUpManager instance;
- int maxNumPickUps = 5;
- float rate = 0.01f;
- float maxTimeSpawned = 10f;
- float maxTimeActive = 5f;
- class PickUp {
- public GameObject pickUp;
- public float timeLeftDespawn;
- public float timeLeftActive;
- public bool isCollected;
- public bool isGreen;
- }
- class GreenPickUp : PickUp {
- // buffs
- public bool isLaserBeam;
- public bool isUmbrella;
- public bool isDestroyedSpawnedMeteors;
- }
- class RedPickUp : PickUp {
- // debuffs
- public bool isSlowPlayerDown;
- public bool isIncreaseMeteorSpawnRate;
- public bool isIncreaseMeteorSize;
- }
- List<PickUp> spawnedPickUps = new List<PickUp>();
- List<PickUp> collectedPickUps = new List<PickUp>();
- void Awake() {
- instance = this;
- }
- public void SpawnPickUp(List<GameObject> levelCubes) {
- if (!(Random.value < rate) || spawnedPickUps.Count == maxNumPickUps - 1)
- return;
- // select random cube
- GameObject cubePickUp = levelCubes[Random.Range(0, levelCubes.Count)];
- GameObject pickUp = cubePickUp.transform.GetChild (Random.Range (0, 2)).gameObject;
- // if it's already active, return
- if (pickUp.activeSelf)
- return;
- else
- pickUp.SetActive (true);
- // create PickUp struct
- PickUp pu = new PickUp();
- /*if(pickUp.CompareTag ("GreenPickUp")) {
- pu = new GreenPickUp ();
- }
- else {
- pu = new RedPickUp ();
- }*/
- pu.pickUp = pickUp;
- pu.timeLeftDespawn = maxTimeSpawned;
- pu.timeLeftActive = maxTimeActive;
- pu.isGreen = pickUp.CompareTag ("GreenPickUp");
- spawnedPickUps.Add (pu);
- } // SpawnPickUp()
- public void RemoveSpawnedPickUp(GameObject pickUp) {
- for(int i=0; i < spawnedPickUps.Count; ++i) {
- PickUp pu = spawnedPickUps [i];
- spawnedPickUps.Remove (pu);
- }
- }
- public void CollectPickUp(GameObject pickUp) {
- for(int i=0; i < spawnedPickUps.Count; ++i) {
- PickUp pu = spawnedPickUps [i];
- spawnedPickUps.Remove (pu);
- collectedPickUps.Add (pu);
- }
- }
- public void UpdatePickUps(float deltaTime) {
- UpdateSpawnedPickUps (deltaTime);
- UpdateCollectedPickUps (deltaTime);
- } // UpdatePickUps()
- public void UpdateSpawnedPickUps(float deltaTime) {
- for(int i=0; i < spawnedPickUps.Count; ++i) {
- PickUp pu = spawnedPickUps [i];
- pu.timeLeftDespawn -= deltaTime;
- // despawn if time is up
- if(pu.timeLeftDespawn <= 0) {
- pu.pickUp.SetActive (false);
- spawnedPickUps.Remove (pu);
- }
- } // for()
- } // UpdateSpawnedPickUps()
- public void UpdateCollectedPickUps(float deltaTime) {
- for(int i=0; i < collectedPickUps.Count; ++i) {
- PickUp pu = collectedPickUps [i];
- pu.timeLeftActive -= deltaTime;
- // deactivate if time is up
- if(pu.timeLeftActive <= 0) {
- collectedPickUps.Remove (pu);
- if(pu.isGreen) {
- pu.pickUp.GetComponent<PickUpBuffs> ().Deactivate ();
- }
- else {
- pu.pickUp.GetComponent<PickUpDebuffs> ().Deactivate ();
- }
- }
- } // for()
- } // UpdateCollectedPickUps()
- public void ClearPickUpList() {
- spawnedPickUps.Clear ();
- collectedPickUps.Clear ();
- }
- // ========================
- // buff/debuff methods including reverts
- // ========================
- public void BuffLaserBeam() {
- }
- public void BuffUmbrella() {
- }
- public void BuffDestroyedSpawnedMeteors() {
- }
- public void DebuffSlowPlayerDown() {
- float changeVal = PlayerController.instance.GetSpeed () / (-2f);
- PlayerController.instance.ChangeSpeedBy (changeVal);
- }
- public void DebuffSlowPlayerDownRevert() {
- float changeVal = PlayerController.instance.GetSpeed () / (2f);
- PlayerController.instance.ChangeSpeedBy (changeVal);
- }
- public void DebuffIncreaseMeteorSpawnRate() {
- }
- public void DebuffIncreaseMeteorSize() {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment