'Move GameObject with Sprite Renderer animation

I have an object in which I have added a sprite Render and an animation to see a sprite sheet in motion, the fact is that I want this object to move from one position to another. But I don't understand why it doesn't work.

  • The first thing I do with this object is to instantiate it to make a clone.
  • Then in the update I do the following:

Method void:

spriteRenderer = throwObject.spriteRenderer;
GameObject spriteRendererObject = Instantiate(spriteRenderer);

Update:

if(_animationStarted2){
                       Vector3 startPos = transform.position;
        
                        
                        Vector3 targetPos = _targetPos;
                        
        
                        spriteRenderer.transform.position = Vector3.MoveTowards(startPos, Vector3.Lerp(startPos, targetPos, 0.1f),speed);
        
                        if (startPos == targetPos)
                        {
                            _animationStarted2 = false;
                            Destroy(gameObject, 0.25f);
                        }
         }


Sources

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

Source: Stack Overflow

Solution Source