(C#) OnTriggerEnter2D wont trigger.

I’m trying to make a coin, if you pass over it plays an animation ‘Pickup’
I tried debuging and it wont trigger even if I pass into it.

using UnityEngine;
using System.Collections;

public class coinAnimation : MonoBehaviour {

    Animator animator;

    void OnCollisionEnter2D(Collision2D collision)
        if (collision.gameObject.tag == "ball")  

        // Use this for initialization
        void Start()
        animator = GetComponent<Animator>();

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



Here is some screen caps:

You’re using wrong function. If you want it to respond it with Trigger then you need to use function


Ref : Unity - Scripting API: MonoBehaviour.OnTriggerEnter2D(Collider2D)

Or you can make it work if you just uncheck “Is Trigger” (Assuming other object has rigidbody2d attached to it)

Also you haven’t created transiction in your animator controller that can play “Pick Up” animation when Trigger “Pickup” is set.