Placing the sprite game object in the players position and also enable and disable it when needed

I have a sprite game object in my unity game. It is an animation which is used to show when a collectible is collected by the player. So I need the animation to be played only when the player collects a collectibLe. also the sprite game object has to be positioned in the same position as that of the player. How does I do that? Any help from any one is easily appreciated. Thanks in advance.

If i understood correctly your question you just have to write a script that instantiates that sprite you want at the player’s position.

I assume that somewhere in your code you have called a collision function to detect when the player has collected the collectible object. Inside that function you could call the Instantiate function and set the position of the sprite at the player’s position. To be clear you’ll have something like that.

OnCollisionEnter2D(collision2D collision)
{
 if(collision.transform.tag == "collectible")
 {
   your code here
   Instantiate(sprite animation, transform.position, Quaternion.identity);
 }
}

For the animation to be played only when the sprite appears, just uncheck the loop parameter of the animation from the inspector.

On a monobehaviour attached to the player use this method:

void OnCollisionEnter(Collision collision) {
            
    if (collision.gameObject.tag == "collectable")
    {
       //Then create sprite
       //Set sprite transform.position to transform.position
    }
}

you will also need to add a tag to the collectable called “collectable”