PO/Assets/Scripts/LibraryEffects.cs

86 lines
2.2 KiB
C#
Raw Permalink 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;
//public Dictionary<string, Sprite> effectsIcon = new Dictionary<string, Sprite>();
2022-02-11 20:15:57 +03:00
public GameObject effectPrefab;
public enum CardEffects
{
poison,
stun
};
2022-02-11 20:15:57 +03:00
[System.Serializable]
public class IconsEffects
{
public CardEffects name;
2022-02-11 20:15:57 +03:00
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
{
if (_enemy.name == "Player(Clone)")
{
_enemy.GetComponent<Player>().ChangeHp(_damage);
}
else
{
_enemy.GetComponent<Enemy>().ChangeHp(_damage);
}
2022-02-13 21:56:03 +03:00
}
2022-03-06 16:11:48 +03:00
public void Stun(GameObject _enemy)
{
if (_enemy.name == "Player(Clone)")
{
_enemy.GetComponent<Player>().hasStun = true;
}
else
{
_enemy.GetComponent<Enemy>().hasStun = true;
}
2022-03-06 16:11:48 +03:00
}
public void InstantiateEffect(string _name, GameObject _parent, int _damageText, int _numInColumn)
2022-02-09 21:22:43 +03:00
{
2022-02-11 20:15:57 +03:00
for (int i = 0; i < effectIcons.Length; i++)
{
if (effectIcons[i].name.ToString() == _name)
2022-02-11 20:15:57 +03:00
{
effectPrefab.GetComponentInChildren<Image>().sprite = effectIcons[i].icon;
}
}
2022-02-13 21:56:03 +03:00
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);
}
2022-02-09 21:22:43 +03:00
}
}