PO/Assets/Scripts/LibraryEffects.cs

86 lines
2.2 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;
public enum CardEffects
{
poison,
stun
};
[System.Serializable]
public class IconsEffects
{
public CardEffects name;
public Sprite icon;
}
public IconsEffects[] effectIcons;
public void Start()
{
main = this;
}
public void Poison(GameObject _enemy, int _damage)
{
if (_enemy.name == "Player(Clone)")
{
_enemy.GetComponent<Player>().ChangeHp(_damage);
}
else
{
_enemy.GetComponent<Enemy>().ChangeHp(_damage);
}
}
public void Stun(GameObject _enemy)
{
if (_enemy.name == "Player(Clone)")
{
_enemy.GetComponent<Player>().hasStun = true;
}
else
{
_enemy.GetComponent<Enemy>().hasStun = true;
}
}
public void InstantiateEffect(string _name, GameObject _parent, int _damageText, int _numInColumn)
{
for (int i = 0; i < effectIcons.Length; i++)
{
if (effectIcons[i].name.ToString() == _name)
{
effectPrefab.GetComponentInChildren<Image>().sprite = effectIcons[i].icon;
}
}
effectPrefab.GetComponentInChildren<Text>().text = _damageText.ToString();
GameObject link = Instantiate(effectPrefab, _parent.transform);
if (_parent.name == "Player(Clone)")
{
var _move = new Vector3(185, 86 - 100 * _numInColumn, 0);
link.transform.localScale = new Vector3(0.3f, 0.3f, 0.3f);
link.transform.localPosition = _move;
_parent.GetComponent<Player>().effectsLink.Add(link);
}
else
{
var _move = new Vector3(520, -369 - 300 * _numInColumn, 0);
link.transform.localPosition = _move;
_parent.GetComponent<Enemy>().effectsLink.Add(link);
}
}
}