Skip to content

Instantly share code, notes, and snippets.

@marcosecchi
Created October 20, 2022 08:10
Show Gist options
  • Save marcosecchi/183aa2653081920d36e60a4c9d45a9c3 to your computer and use it in GitHub Desktop.
Save marcosecchi/183aa2653081920d36e60a4c9d45a9c3 to your computer and use it in GitHub Desktop.
Code with errors
using UnityEngine;
public class MageCharacter : MonoBehaviour
{
public string characterName;
private int _hitPoints
public int maxHitPoints;
private int _mana;
public int maxMana:
/ Initializes the character
private void Start()
{
Debug.Log("Initializing character: " + characterName);
_hitPoints = maxHitPoints;
_mana = maxMana;
}
// Casts a spell if there is enough mana.
public void CastSpell(string spellName, int manaCost)
{
if(_mana < manaCost)
{
Debug.Log("Error: Not enough mana!);
}
else
{
_mana = _mana - manaCost;
Debug.Log("Spell cast: " + spellName);
}
}
// Damages the character, checking if he is dead afterwards.
public void Damage(int damage)
{
_hitPoints = _hitPoints - damage;
Debug.Log("Damage taken: " + damage);
if(_hitPoints <= 0)
{
Debug.Log("Character has died!";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment