Created
October 27, 2023 20:51
-
-
Save TheMehranKhan/15e1f2345de124c87ac56c7e6a9162af to your computer and use it in GitHub Desktop.
Revisions
-
TheMehranKhan created this gist
Oct 27, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,57 @@ /* Author: themehrankhan License: MIT License Description: This code block provides a power-up system functionality in Unity. It allows the player to collect power-ups and apply their effects. Usage: 1. Attach this script to the power-up object in Unity. 2. Set the power-up effect and duration in the inspector. */ using UnityEngine; public class PowerUp : MonoBehaviour { public PowerUpEffect effect; // Power-up effect public float duration = 5f; // Duration of the power-up effect private void OnTriggerEnter(Collider other) { if (other.CompareTag("Player")) { ApplyEffect(other.gameObject); Destroy(gameObject); } } private void ApplyEffect(GameObject player) { switch (effect) { case PowerUpEffect.SpeedBoost: player.GetComponent<PlayerMovement>().speed *= 2f; Invoke(nameof(ResetEffect), duration); break; case PowerUpEffect.Invincibility: player.GetComponent<HealthSystem>().enabled = false; Invoke(nameof(ResetEffect), duration); break; // Add more power-up effects here } } private void ResetEffect() { // Reset power-up effect here } } public enum PowerUpEffect { SpeedBoost, Invincibility // Add more power-up effects here }