PO/Assets/Scripts/LibraryEffects.cs

54 lines
1.4 KiB
C#
Raw Normal View History

2022-02-09 21:22:43 +03:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
2022-02-11 20:15:57 +03:00
using UnityEngine.UI;
2022-02-09 21:22:43 +03:00
public class LibraryEffects : MonoBehaviour
{
public static LibraryEffects main;
2022-02-11 20:15:57 +03:00
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;
2022-02-09 21:22:43 +03:00
public void Start()
{
main = this;
}
public void Poison(GameObject _enemy, int _damage)
2022-02-13 21:56:03 +03:00
{
_enemy.GetComponent<Enemy>().ChangeHp(_damage);
}
2022-03-06 16:11:48 +03:00
public void Stun(GameObject _enemy)
{
_enemy.GetComponent<Enemy>().hasStun = true;
}
2022-02-13 21:56:03 +03:00
public void InstantiateEffect(string _name, GameObject _parent, int _damageText)
2022-02-09 21:22:43 +03:00
{
2022-02-11 20:15:57 +03:00
for (int i = 0; i < effectIcons.Length; i++)
{
2022-02-13 21:56:03 +03:00
if (effectIcons[i].name == _name)
2022-02-11 20:15:57 +03:00
{
effectPrefab.GetComponentInChildren<Image>().sprite = effectIcons[i].icon;
}
}
2022-02-13 21:56:03 +03:00
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);
2022-02-09 21:22:43 +03:00
}
}