How to check if Rigidbody2d is moving

How to check if Rigidbody2d is moving .

Here my code if it helps you.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Indingo_Movement : MonoBehaviour
{

public int runMod; // Run Speed multiplier

private Rigidbody2D MyRigidBody;

private Animator MyAnimator;

[SerializeField]
private float movementSpeed;

private bool facingRight;

private PolygonCollider2D myPolygonCollider2D;

// Use this for initialization
void Start()
{
facingRight = true;
MyRigidBody = GetComponent<Rigidbody2D>();
MyAnimator = GetComponent<Animator>();
myPolygonCollider2D = GetComponent<PolygonCollider2D>();
}

// Update is called once per frame
void FixedUpdate()
{

float horizontal = Input.GetAxis(“Horizontal”);

HandleMovement(horizontal);

Flip(horizontal);

Deactivator();

}

private void HandleMovement(float horizontal)
{
if (Input.GetKey(KeyCode.RightShift))
{
MyRigidBody.velocity = new Vector2(horizontal * movementSpeed * runMod, MyRigidBody.velocity.y); // x – 1, y = 0;

MyAnimator.SetFloat(“speed”, Mathf.Abs(horizontal));
MyAnimator.SetBool(“isRun”, true);

}
else
{

MyRigidBody.velocity = new Vector2(horizontal * movementSpeed, MyRigidBody.velocity.y); // x – 1, y = 0;
MyAnimator.SetBool(“isRun”, false);

MyAnimator.SetFloat(“speed”, Mathf.Abs(horizontal));
}
}

private void Flip(float horizontal)
{
if (horizontal > 0 && !facingRight || horizontal < 0 && facingRight)
{
facingRight = !facingRight;

Vector3 thescale = transform.localScale;

thescale.x *= -1;

transform.localScale = thescale;
}
}

private void Deactivator ()
{
if (Input.GetAxis(“Horizontal”) > 0)
{

myPolygonCollider2D.enabled = false;

}
}
}

Declare a Vector2 lastPosition and set it to your position in void Start(). Then run this in update:

if (lastPosition != transform.position)
        {
            //code
        }