Animation play on trigger

I have seen this question asked a lot but none of their solutions work for me and have not found any that do work or are up to date so I am going to ask here. I have a script that should make it so that when the player walks into the trigger it will play the animation “blob_attack”.

I have tried everything from putting the animation name itself into the code but nothing has worked. I just do not get this animation stuff. If someone could help me sort this out that would be great. (There are no errors in the code just the animation does not play.)

using UnityEngine;
using System.Collections;

public class blob_attack : MonoBehaviour {

// Use this for initialization
void Start () {

}

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

}

void OnTriggerEnter2D(Collider2D other)
{
    if (other.tag == "Enemy")
    {
        GetComponent<Animation>().Play();
    }
}

}

First thing first:

Both gameobjects should have (in this case) 2D colliders with one of them at least 1 2DRigidbody!
(In case of 3D object this should be colliders with at least one rigidbody)
The collider which has the script attached should me marked as “Trigger”

Double check inside the OnTrigger enter, if there is indeed an actual trigger happening:

protected void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag == "Enemy")
        {
            Debug.Log("Enemy collision");
            GetComponent<Animation>().Play();
        }
    }

If the colliders are setup correctly you should have a look at the animation component that is attached to the script’s gameObject.

The Animation component should be filled with the correct animation and “Play Automatically” Should be turned off:

67887-capture.png

I hope this solves your problem!