Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
managing powerups
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PowerUp : MonoBehaviour
{
[SerializeField]
private float _speed = 3.0f;
[SerializeField]
private int _powerupID;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
PowerupGarbageCollection();
}
private void PowerupGarbageCollection()
{
transform.Translate(Vector3.down * _speed * Time.deltaTime);
if (transform.position.y < -3.8f)
{
Destroy(this.gameObject);
}
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Player")
{
Player player = other.GetComponent<Player>();
if (player != null)
{
//if powerUp ID is 0
switch (_powerupID)
{
case 0:
player.ShieldsActive();
break;
default:
Debug.Log("Default Value");
break;
}
Destroy(this.gameObject);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment