Skip to content

Instantly share code, notes, and snippets.

@mvenezia
Last active July 28, 2018 19:29
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 mvenezia/abcf0bdd674f1f7c752b1c2cbdc0beb0 to your computer and use it in GitHub Desktop.
Save mvenezia/abcf0bdd674f1f7c752b1c2cbdc0beb0 to your computer and use it in GitHub Desktop.
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