using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Character : MonoBehaviour
{
public string name;
public int damage;
public int hp;
public int maxHp;
public Character(string name, int damage, int maxHp)
{
this.name = name;
this.damage = damage;
this.maxHp = maxHp;
this.hp = this.maxHp;
}
public void Attack(Character target)
{
Debug.Log(this.name + "이(가) " + target.name + "을(를) 공격합니다.");
target.Hit(this.damage);
}
public void Hit(int damage)
{
Debug.Log(this.name + "이(가) " + damage + "만큼 피해를 받았습니다.");
this.hp -= damage;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Program : MonoBehaviour
{
Character hong = new Character("홍길동", 3, 10);
Character lim = new Character("임꺽정", 2, 12);
void Start()
{
Debug.Log("이름 : " + hong.name + " 공격력 : " + hong.damage + " 체력 : " + hong.hp + "/" + hong.maxHp);
Debug.Log("이름 : " + lim.name + " 공격력 : " + lim.damage + " 체력 : " + lim.hp + "/" + lim.maxHp);
hong.Attack(lim);
Debug.Log("이름 : " + lim.name + " 공격력 : " + lim.damage + " 체력 : " + lim.hp + "/" + lim.maxHp);
}
}