- Home /
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?
Answer by yagizpoyraz · Jul 17, 2014 at 07:49 AM
//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.
Answer by smallbit · Jul 17, 2014 at 04:07 AM
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().enabled = false;)
wait a while for instance calling a method SpawnPlayerInOtherElevator() (i.e. Invoke("SpawnPlayerInOtherElevator",1f);)
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().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.
Hey man, thanks for this answer =]
Can you explain that in javascript? (Noob in coding here e.e)
Your answer
Follow this Question
Related Questions
Hide parts of the sprite in 2D? 0 Answers
Animated Overlay Armor Sprite 1 Answer
How do I animate a 2D sprite? 1 Answer
Animation with Transparency Floats Above Ground 1 Answer
Is there a way to abstract sprite from animation clip? 0 Answers