PO/Assets/Scripts/LibraryEffects.cs

49 lines
1.3 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)
{
_enemy.GetComponent<Enemy>().ChangeHp(_damage);
}
public void InstantiateEffect(string _name, GameObject _parent, int _damageText)
{
for (int i = 0; i < effectIcons.Length; i++)
{
if (effectIcons[i].name == _name)
{
effectPrefab.GetComponentInChildren<Image>().sprite = effectIcons[i].icon;
}
}
var _move = new Vector3(520, -369, 0);
effectPrefab.GetComponentInChildren<Text>().text = _damageText.ToString();
GameObject link = Instantiate(effectPrefab, _parent.transform);
link.transform.localPosition = _move;
_parent.GetComponent<Enemy>().effectsLink.Add(link);
}
}