JumpPad script for a JumpPad like Geometery dash

Im trying to make a JumpPad that automatically jumps your charater like the ones in geometry dash

I wrote this code to the JumpPad but when my charater goes over it I get this error code: MissingComponentException: There is no ‘Rigidbody2D’ attached to the “JumpPad” game object, but a script is trying to access it.
You probably need to add a Rigidbody2D to the game object “JumpPad”. Or your script needs to check if the component is attached before using it.

153398-anteckning-2020-02-28-151255.png

That’s cause you’re trying to AddForce the JumpPad itself. You can use the collision variable to AddForce the object that triggered with the JumpPad

collision.GetComponent<Rigidbody2D>().AddForce(JumpHeight, ForceMode2D.Impulse);

You could also add a tag, so that it will only AddForce to a specific object with that tag

if (collision.CompareTag("YourTag"))
{
    collision.GetComponent<Rigidbody2D>().AddForce(JumpHeight, ForceMode2D.Impulse);
}