How to create fade animation when my character teleports?

Ok, so I tried doing this in the only way I know.

Here is the script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Teleporting : MonoBehaviour
{

    public Transform teleportTarget;
    public GameObject thePlayer;

    public GameObject teleportUI;


    void OnTriggerEnter2D(Collider2D other)
    {
        teleportUI.SetActive(true);
        thePlayer.transform.position = teleportTarget.transform.position;
    }

}

It basically turns on my panel which has fade animation and it works the first time. Problem is that after finishing this, my panel stays active. That means that animation won’t play again because my panel is already active.

Any solution?

EDIT:
I fixed it. I made new script that sits on panel: pastemyst | (untitled)
after that you will select your animation and then:
s - Album on Imgur

  • Click on that to add AnimationEvent on your last frame
  • Select ( I don’t know how to call that ) but it’s above your animation key
  • Find your function that turns off panel

That’s it!

Probably just add a timer of some kind that deactivates the teleportUI after a time expires.
You can do that by setting a constant float for the timeout, on setting teleportUI to active, you set a tracking float variable to 0, then every update/fixed update you increment that float variable by the deltatime/fixeddeltatime and compare against your constant. If greater or equal, deactivate the teleportUI again and stop incrementing (although deactivating the teleportUI I think will suspend update/fixedupdate so that should be sufficient I think).

I actually did it in another way, pretty much added AnimationEvent which calls function that turn’s off panel at the end of animation