<gh_stars>0using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class PlayerAfterImage : MonoBehaviour
{
   [SerializeField]
    private float activeTime = 2f;
    private float timeActivated;
    private float alpha;
    [SerializeField]
    private float alphaSet = 0.8f;
    [SerializeField]
    private float alphaDecay = 0.85f;

    private Transform player;

    private GameObject playerObject;

    private Transform playerSpriteComponent;
    private SpriteRenderer SR;
    private SpriteRenderer playerSR;

    private Color color;

    private void OnEnable()
    {
        SR = GetComponent<SpriteRenderer>();
        playerObject =  GameObject.FindGameObjectWithTag("Player");
        player = playerObject.transform;
        playerSpriteComponent = player.Find("Sprite");
        playerSR = playerSpriteComponent.GetComponent<SpriteRenderer>();

        alpha = alphaSet;
        SR.sprite = playerSR.sprite;
        SR.flipX = playerSR.flipX;
        transform.position = player.position;
        transform.rotation = player.rotation;

        transform.localScale = new Vector3(4,4,0);
        timeActivated = Time.time;
    }

    private void Update()
    {
        alpha -= alphaDecay * Time.deltaTime;
        color = new Color(1f, 1f, 1f, alpha);
        SR.color = color;

        if(Time.time >= (timeActivated + activeTime))
        {
            PlayerAfterImagePool.Instance.AddToPool(gameObject);
        }

    }
}
    
