Animation dependent on user input

Hello, I would like my animation to start when a players presses mousebutton. The animation is simply moving a sprite, but I want the animation to move the sprite to the mouse pressed place. It is not possible when each keyframe of the animation is hardcoded. Is parameterizing the animation possible?

Yes its possible to start animation on mouse button press.

  • If you want to move the sprite to mouse position then use simple code to move your gameobject towards mouse pointer as well as start animation.

  • Animation will be having only sprite animation.

  • For moving object towards mouse pointer you can do like this :

        if (Input.GetMouseButton(0))
        {
                var targetPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                targetPos.z = transform.position.z;
                transform.position = Vector3.MoveTowards(transform.position, targetPos, 2.0f  *  Time.deltaTime);
        }
    

This is for 2D.
This may help you. Thanks. If you have any doubt ask again.