Some1 PLEASE HELP I SPENT HOURS trying 2 fix but nothing. My trigger / animation wont play on collision

Hi guys please help I tried everything I know spent hours no luck.

I have Gameobject/image and want to play a animation on collision on it but nothing is working

I tried tons of combos and options. I have a small question…If you drag an image onto scene is that considered a gameobject?- maybe that the problem??

But I added rigigbodies 2d 2d colliders 2d oncollision on trigger ect etc I checked a lot of basics And tried a lot of scripts from references area

Nothing happens on any collision I set trigger to gameobject.

I see animation playing rapidly but will not play on collision at all. But animation is working when reviewed in animation inspector area

Anyway
I currently have this (javascript)

function OnCollisionEnter2D(Collider2D) {

    if(gameObject.tag == "Player")
 {
         animation.Play("crack");
     }
 }

I also tried OnTriggerEnter 2d etc scripts & more
I added this to game object but nothing happens

the animation keeps playing constantly with things I did in animator controller.
I tried looking at animator controller animations
scripts still nothing.
My animation just keeps playing from the botched( I think botched) parameter I put thru animator controller

I did add this to correct gameobject and tagged other gameobject correctly as player
I tried keeping this simple but still not working. So here is 1 scripts I tried above. Please post correct script for me so I can add it to my image/gameobject and move on.

PLEASE PLEASE Someone who is good at this HELP!I literally spent a ton of time and need pro help!

I think your problem is that you’re not checking the collided object’s tag–you’re checking the tag of the GameObject this script is on. Try this:

function OnCollisionEnter2D(Collider2D theCollider) {
 
     if(theCollider.gameObject.tag == "Player")
     {
          animation.Play("crack");
     }
  }

Yes I tried few things and that error went away
but I now have the problem of the animation still will not play.

I am trying every option here but still nothing.

I have used these codes and attached it to the gameobject

function OnCollisionEnter2D(coll: Collision2D) {
	if (coll.gameObject.tag == "Player")
		animation.Play("crack");
}

and also tried this code

function OnCollisionEnter2D(coll: Collision2D) {

    if(gameObject.tag == "Player")
 {
         animation.Play("crack");
     }
     }

But nothing is working

I am really searching and trying here but cannot resolve this

The animation will not play on collision, The objects just bounce eachother around as colliders should but No animation

Thank yOU

I don’t think your problem is in the code.
I have found similar problems when creating and using old style animations (not mecanim). It seems to be a bug introduced in the last versions.
Unfortunately when this happened to me I had to recreate the animations.
For the time being what I do and recomend is to follow these exact steps when creating animations.

  1. DO THIS FIRST. Add the animation component to the GameObject to be animated. If you don’t, an Animator component is created and that interferes with the old style animations.
  2. Then open de animation window and create an animation clip from there.
  3. Add your curves and animate
  4. As soon as you finished your first animation, go to your Animatiosn project folder and drag the animation clip to the Aimation property of the Animation component in the inspector, so this one is the default animation. Most of the times I found problems I had forgotten to do this.
  5. If you want to add more animations to the GameObject, do so but don’t forget to do step 4 first.

Hope this helps