Skip to content

Instantly share code, notes, and snippets.

@pr00thmatic
Created June 25, 2019 01:55
Show Gist options
  • Save pr00thmatic/93684163e8ea112ebb86f9b4fcd584a7 to your computer and use it in GitHub Desktop.
Save pr00thmatic/93684163e8ea112ebb86f9b4fcd584a7 to your computer and use it in GitHub Desktop.
public interface IMage {
public Mage Mage { get; }
}
public class KoboldMage : MonoBehaviour, IMage {
public Mage mage;
public Mage Mage { get => mage; }
public List<GameObject> spells;
public ICasteableSpell selectedSpell;
void OnEnable () {
SelectSpell(0)
}
void Update () {
if (Input.GetKeyDown(KeyCode.Space) && spells.Count > 0) {
Mage.CastSpell(selectedSpell);
}
}
void SelectSpell (int index) {
/* no hace falta que la interfaz herede de MonoBehaviour para hacer esto!
basta con que esté implementada desde un MonoBehaviour. */
selectedSpell = Mage.spells[index].GetComponent<ICasteableSpell>();
}
}
[System.Serializable] // para poder editar sus propiedades desde el editor de unity.
public class Mage {
public float spellPower;
public ICasteableSpell CastSpell (ICasteableSpell spell) {
ICasteableSpell casted = Instantiate(spell.prototype).GetComponent<ICasteableSpell>();
casted.damage = spellPower;
return casted;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment