trigger animation when sprite is hit by another sprite?

ok, so i am not too good at scripting

so i want something like mario, when my character jumps and hits the block, it triggers the animation to make it move

just wondering the if statement for when one sprite touches another sprite to trigger this animation.

thanks

First you’ll need to have rigidbody2d your player and a collider. Your box will need only a collider (ex: a box collider 2d) for the events to work. Now you should be able to utilize the OnCollisionEnter2D() function from your behavior scripts.

using UnityEngine;
using System.Collections;

public class Example : MonoBehaviour {
    void OnCollisionEnter2D(Collision2D col) {
        if (col.gameObject.tag == "Block")
            col.gameObject.SendMessage("PlayerHit");
        
    }
}