Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Powerups : MonoBehaviour
- {
- public bool doublePoints;
- public bool safeMode;
- public float powerupLength;
- public Sprite[] powerupSprites;
- private PowerupManager thePowerupManager;
- // Start is called before the first frame update
- void Start()
- {
- thePowerupManager = FindObjectOfType<PowerupManager>();
- }
- void Awake ()
- {
- int powerupSelector = Random.Range(0, 2);
- switch (powerupSelector)
- {
- case 0: doublePoints = true; break;
- case 1: safeMode = true; break;
- }
- //need the sprite renderer to be change the sprite based on the random power up. green (powerup1)= double points, blue (powerup2) = safe mode
- GetComponent<SpriteRenderer>().sprite = powerupSprites[powerupSelector];
- }
- // OnTriggerEnter2D is called when the Collider2D other enters the trigger
- void OnTriggerEnter2D(Collider2D other)
- {
- // Check if the colliding object is the player
- if (other.name == "Player")// (other.CompareTag("Player")) commented out would have Player walk through the powerup gem
- {
- // Activate the powerup in the PowerupManager
- thePowerupManager.ActivatePowerup(doublePoints, safeMode, powerupLength);
- // Deactivate the powerup object
- gameObject.SetActive(false);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement