PO/Assets/Scripts/Enemy.cs

73 lines
1.9 KiB
C#
Raw Normal View History

2022-01-12 10:06:03 +03:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
2022-01-12 10:06:03 +03:00
using UnityEngine.UI;
public class Enemy : MonoBehaviour
{
public EnemyConfig enemyConfig;
public GameObject enemyPosition;
2022-01-12 10:06:03 +03:00
[SerializeField] private Text enemyName;
[SerializeField] private Text enemyMaxHp;
[SerializeField] private Text enemyHp;
[SerializeField] private Slider enemyHealthbar;
[SerializeField] private int hp;
[Header("For checking. dont touch this")]
[SerializeField] int phaseAttack = 0;
public List<UnityEvent> attackLoop = new List<UnityEvent>();
[HideInInspector] public int index;
2022-01-12 10:06:03 +03:00
public void ChangeHp(int damage)
{
hp -= damage;
if (hp <= 0)
2022-01-12 10:06:03 +03:00
{
Death();
}
else if (hp > enemyConfig.enemyCharacteristics.maxHp)
2022-01-12 10:06:03 +03:00
{
hp = enemyConfig.enemyCharacteristics.maxHp;
}
enemyHp.text = hp.ToString();
enemyHealthbar.value = hp;
}
public void NewInformation()
{
SpriteRenderer _sprRend = enemyPosition.GetComponent<SpriteRenderer>();
_sprRend.sprite = enemyConfig.enemyCharacteristics.sprite;
var _character = enemyConfig.enemyCharacteristics;
enemyName.text = _character.name;
enemyMaxHp.text = _character.maxHp.ToString();
enemyHp.text = _character.maxHp.ToString();
enemyHealthbar.maxValue = _character.maxHp;
enemyHealthbar.value = _character.maxHp;
hp = _character.maxHp;
}
public void Death()
{
SpriteRenderer _sprRend = enemyPosition.GetComponent<SpriteRenderer>();
_sprRend.sprite = null;
Session.instance.EnemyDeath(index);
2022-01-12 10:06:03 +03:00
gameObject.SetActive(false);
}
public void Turn()
{
BaseEnemyTurn.basic.FindLoopTurn(this.gameObject, phaseAttack);
phaseAttack++;
}
2022-01-12 10:06:03 +03:00
}