Instantly share code, notes, and snippets.

Embed
What would you like to do?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ShieldPowerUp : MonoBehaviour {
#region Member Variables
public static ShieldPowerUp instance;
public bool on;
public GameObject shieldHitVisualFX;
public SpriteRenderer shieldActiveVisualFX;
#endregion
void Awake()
{
if (instance == null)
instance = this;
else
Destroy(this);
}
void Start () {
InitMembers();
}
//=============================
public void ShieldTakesHit()
{
ShieldHitFX();
TurnShieldOff();
}
#region Private Member Functions
void InitMembers()
{
on = false;
shieldActiveVisualFX.enabled = false;
}
void ShieldHitFX()
{
GameObject vfx = Instantiate(shieldHitVisualFX, gameObject.transform.position, gameObject.transform.rotation);
vfx.GetComponent<ParticleSystem>().Play();
}
void TurnShieldOff()
{
on = false;
shieldActiveVisualFX.enabled = false;
}
void TurnShieldOn()
{
on = true;
shieldActiveVisualFX.enabled = true;
}
#endregion
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment