- Home /
Best way to move a canvas?
Good day.
Which is the best practice to make a canvas or more specific, an object in a canvas (a panel) move from side toside, or apear from the top of the screen, you know. A panel that expands from a side and go outside the screen again.
Which is the best codes for move canvas?
Thx!
Answer by losingisfun · Apr 03, 2018 at 11:07 AM
it depends HOW you want to move it, but you can change the Transform.position just like any normal object, the difference with a canvas is that it has a different space to the game (depending on whether you use 'world space' or not). - if you want to make it move over a space of time you'll need to write a method to handle that, e.g. a IEnumerator like:
IEnumerator moveRight () {
Vector2 pos = panelThing.transform.position;
for (int i = 0; i < 100; i++) {
pos.x += 10f;
panelThing.transform.position = pos;
yield return new waitForSeconds (0.01f);
}
}
you can call this by using StartCoroutine (moveRight());
Even iTween will give you nice effects like ease in , ease out ,sine wave, cosine wave etc