Hi i’m programming a game and just now i got a stack overflow error but i encountered this error for the first time, i tried to google but i couldn’t find a solution, i hope you can help me.
Here is the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
public class BattleUnit : MonoBehaviour
{
[SerializeField] bool isPlayerUnit;
[SerializeField] BattleHud hud;
public bool IsPlayerUnit
{
get { return IsPlayerUnit; }
}
public BattleHud Hud
{
get { return hud; }
}
public Pokémon Pokémon { get; set; }
Image image;
Vector3 originalPos;
Color originalColor;
private void Awake()
{
image = GetComponent<Image>();
originalPos = image.transform.localPosition;
originalColor = image.color;
}
public void SetUp(Pokémon pokémon)
{
Pokémon = pokémon;
if (isPlayerUnit)
image.sprite = Pokémon.Base.BackSprite;
else
image.sprite = Pokémon.Base.FrontSprite;
hud.SetData(pokémon);
image.color = originalColor;
PlayerEnterAnimation();
}
public void PlayerEnterAnimation()
{
if (isPlayerUnit)
image.transform.localPosition = new Vector3(-500f, originalPos.y);
else
image.transform.localPosition = new Vector3(500f, originalPos.y);
image.transform.DOLocalMoveX(originalPos.x, 1f);
}
public void PlayAttackAnimation()
{
var sequence = DOTween.Sequence();
if (isPlayerUnit)
sequence.Append(image.transform.DOLocalMoveX(originalPos.x + 50f, 0.25f));
else
sequence.Append(image.transform.DOLocalMoveX(originalPos.x - 50f, 0.25f));
sequence.Append(image.transform.DOLocalMoveX(originalPos.x, 0.25f));
}
public void PlayHitAnimation()
{
var sequence = DOTween.Sequence();
sequence.Append(image.DOColor(Color.gray, 0.1f));
sequence.Append(image.DOColor(originalColor, 0.1f));
}
public void PlayFaintAnimation()
{
var sequence = DOTween.Sequence();
sequence.Append(image.transform.DOLocalMoveY(originalPos.y - 150f, 0.2f));
sequence.Join(image.DOFade(0f, 0.5f));
}
}