Advertisement
johnnygoodguy2000

PowerupManager.cs

Apr 15th, 2024 (edited)
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.87 KB | Gaming | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PowerupManager : MonoBehaviour
  6. {
  7.     private bool doublePoints;
  8.     private bool safeMode;
  9.    
  10.     private bool powerupActive;
  11.  
  12.     private float powerupLengthCounter;
  13.     private ScoreManager theScoreManager;
  14.     private PlatformGenerator thePlatformGenerator;
  15.     private GameManager theGameManager;
  16.     private float normalPointsPerSecond;
  17.     private float spikeRate;
  18.  
  19.     private PlatformDestroyer[] spikeList;
  20.  
  21.    
  22.  
  23.     // Start is called before the first frame update
  24.     void Start()
  25.     {
  26.         theScoreManager = FindObjectOfType<ScoreManager>(); //GameObject.Find("ScoreManager").GetComponent<ScoreManager>();
  27.         thePlatformGenerator = FindObjectOfType<PlatformGenerator>();//GameObject.Find("PlatformGenerator").GetComponent<PlatformGenerator>();
  28.         theGameManager = FindObjectOfType<GameManager>();
  29.     }
  30.  
  31.     // Update is called once per frame
  32.     void Update()
  33.     {
  34.         if (powerupActive)
  35.         {
  36.             powerupLengthCounter -= Time.deltaTime;
  37.  
  38.             if (theGameManager.powerupReset)
  39.             {
  40.                 powerupLengthCounter = 0;
  41.  
  42.                 theGameManager.powerupReset = false;
  43.  
  44.             }
  45.  
  46.             if (doublePoints)
  47.             {
  48.                 theScoreManager.pointsPerSecond = normalPointsPerSecond * 2f;
  49.                 theScoreManager.shouldDouble = true;
  50.             }
  51.            /* else
  52.             {
  53.                 thePlatformGenerator.randomSpikeThreshold = spikeRate / 2f;
  54.             }
  55.             */
  56.             if (safeMode)
  57.             {
  58.                 thePlatformGenerator.randomSpikeThreshold = 0f;
  59.             }
  60.  
  61.             if (powerupLengthCounter <= 0)
  62.             {
  63.                 // Reset modifications made during powerup activation
  64.                 theScoreManager.pointsPerSecond = normalPointsPerSecond;
  65.                 theScoreManager.shouldDouble = false;
  66.                 thePlatformGenerator.randomSpikeThreshold = spikeRate;
  67.  
  68.                 powerupActive = false;
  69.             }
  70.         }
  71.     }
  72.  
  73.     public void ActivatePowerup(bool points, bool safe, float time)
  74.     {
  75.         doublePoints = points;
  76.         safeMode = safe;
  77.         powerupActive = true;
  78.         powerupLengthCounter = time;
  79.  
  80.         // Store original values for resetting later
  81.         normalPointsPerSecond = theScoreManager.pointsPerSecond;
  82.         spikeRate = thePlatformGenerator.randomSpikeThreshold;
  83.  
  84. if (safeMode) {
  85.    
  86.  
  87.          spikeList = FindObjectsOfType<PlatformDestroyer>();
  88.         for (int i = 0; i < spikeList.Length; i++)
  89.         {
  90.             if (spikeList[i].gameObject.name.Contains ("spikes"))
  91.             {
  92.                 spikeList[i].gameObject.SetActive(false);
  93.             }
  94.            
  95.         }
  96. }
  97.         powerupActive = true;
  98.     }
  99. }
  100.  
  101.  
  102.  
  103.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement