Skip to content

Instantly share code, notes, and snippets.

@curious-username
Created October 22, 2021 02:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save curious-username/bc7d0e5f9eab1e4932a67b156ffd43d1 to your computer and use it in GitHub Desktop.
Save curious-username/bc7d0e5f9eab1e4932a67b156ffd43d1 to your computer and use it in GitHub Desktop.
powerup script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PowerUp : MonoBehaviour
{
[SerializeField]
private float _speed = 3.0f;
[SerializeField]
private int _powerupID;
void Start()
{
}
void Update()
{
Movement();
}
private void Movement()
{
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.TripleShotActive();
break;
case 1:
player.SpeedUpActive();
break;
case 2:
player.ShieldsActive();
break;
case 3:
player.AmmoRefill();
break;
case 4:
player.AddHealth();
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