How to call an sprite animation, hide the main character and show him again in another spot?

Hello guys, I’m having some trouble with my 2D game, here’s the deal:

I have 2 elevator’s, I need my sprite(which is the main character) to:

  • When my character is in front of the elevator and I press W, it hides the main character and start an animation
  • After a short delay, the sprite re-appears on the other elevator and after the animation of the second elevator finishe’s.

And them, the script stops.

I tried a lot of ways but couldn’t figure it out how to do it, can you guys help me?

Hard to tell without seeing your code. But here are the steps for a one way for doing this:

  • when click W disable sprite renderer ( GetComponent< SpriteRenderer >().enabled = false;)
  • wait a while for instance calling a method SpawnPlayerInOtherElevator() (i.e. Invoke(“SpawnPlayerInOtherElevator”,1f):wink:
  • in SpawnPlayerInOtherElevator(), First move the player to the other elevator position (i.e. transform.position = elevator.transform.position) depends on your player controler setup.
  • enable sprite (GetComponent< SpriteRenderer >().enabled = true;)

There are some other issues like you should disable your player controler for the time he is invisible etc. But you will figure this out.

//disable sprite, it will be hidden
GameObject.Find(“playergameobjectname”).GetComponent().enabled = false;

//set tranform position of player to elevator position
GameObject.Find(“playergameobjectname”).transform.position = GameObject.Find(“elevator gameobjectname”).transform.position;

//now lets make our sprite visible again
GameObject.Find(“playergameobjectname”).GetComponent().enabled = true;

you can use Invoke method if you want to make delay between these actions.