PO/Assets/Scripts/LibraryEffects.cs

43 lines
1.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class LibraryEffects : MonoBehaviour
{
public static LibraryEffects main;
public Dictionary<string, Sprite> effectsIcon = new Dictionary<string, Sprite>();
public GameObject effectPrefab;
[System.Serializable]
public class IconsEffects
{
public string name;
public Sprite icon;
}
public IconsEffects[] effectIcons;
public void Start()
{
main = this;
}
public void Poison(GameObject _enemy, int _damage)
{
for (int i = 0; i < effectIcons.Length; i++)
{
if(effectIcons[i].name == "poison")
{
effectPrefab.GetComponentInChildren<Image>().sprite = effectIcons[i].icon;
}
}
effectPrefab.GetComponentInChildren<Text>().text = _damage.ToString();
_enemy.GetComponent<Enemy>().ChangeHp(_damage);
GameObject link = Instantiate(effectPrefab, _enemy.transform);
_enemy.GetComponent<Enemy>().effectsLink.Add(link);
}
}