Created
June 25, 2019 01:55
-
-
Save pr00thmatic/93684163e8ea112ebb86f9b4fcd584a7 to your computer and use it in GitHub Desktop.
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 characters
public interface IMage { | |
public Mage Mage { get; } | |
} |
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 characters
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>(); | |
} | |
} |
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 characters
[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