'Step by Step mouving player + Animate it in unity

I'm going to make a game projet for the highschool, i'm at the first years to my cursus and i can't find documentation about what i'm doing.

let me introdius wath kind of game I make: I make a 2D platform game and it look like this : "Picture : camera of the game". I'm looking for to animate my "player" (that are a shere) when it move from a platform to an other platform. I use "Animation" component to animate the player but the animation are played vy absolute position not a relative position. the script that I made is that :

void Update()
{   
    if (Input.GetKeyDown(KeyCode.UpArrow) == true)
    {
        My_Animation.Play("Players");
        My_IsPlaying_forward = true;
    }
    if (Input.GetKeyDown(KeyCode.RightArrow) == true)
    {
        transform.Translate(0, 0,(float)-1.25);
    }
    if (Input.GetKeyDown(KeyCode.DownArrow) == true)
    {
        transform.Translate((float)-1.25, 0, 0);
    }
    if (Input.GetKeyDown(KeyCode.LeftArrow) == true)
    {
        transform.Translate(0, 0, (float)1.25);
    }
}
private void FixedUpdate()
{
    if (My_IsPlaying_forward == true)
    {
        transform.Translate((float)1.25, 0, 0);
    }
}

But when I push on the UpArrow, the animation comeback to the original point. How Can I make a sphere animate and move this sphere from platform to platform ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source