Solved: Play Animation When Object is hit by raycast

I have a melee weapon and a training dummy.
I also have a raycast that does damage to an enemy when it hit withing melee range.
I have made an animation for the training dummy and so i want the animation to play when the raycast hits in melee range, just as a melee weapon would.

Here is my melee script:

public class MeleeSystem : MonoBehaviour {
public int damage = 50;
public float distance;
public float maxDistance = 1.5f;
public Transform axe;

RaycastHit hit;

void Update()
{
	if (Input.GetButtonDown ("Fire1"))
	{
		if (Physics.Raycast (transform.position, transform.TransformDirection (Vector3.forward), out hit))
		{
			distance = hit.distance;
			if (distance < maxDistance)
			{
				hit.transform.SendMessage ("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
			}
		}
	}
}

}

I have an animation on the melee weapon that plays when i left click but i need to know how to get it to cause the animation on the other target.

Hey,
i think you want to play the animation as the weapon hits the target.
since you are using raycast for that, you can use “hit.collider” thing to play its animation,

 void Update() {
         Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         RaycastHit hit;
         if (Physics.Raycast(ray , out hit))
             if(hit.transform.tag == "someTag") {
                      //play animation here
             }
         
     }

I just needed a reference to the object i wanted to animate so this is what it looks like now and it is working:

using UnityEngine;
using System.Collections;

public class MeleeSystem : MonoBehaviour {
public int damage = 50;
public float distance;
public float maxDistance = 1.5f;
public Transform axe;
public GameObject other;

RaycastHit hit;

void Update()

{
	if (Input.GetButtonDown ("Fire1"))
	{
		if (Physics.Raycast (transform.position, transform.TransformDirection (Vector3.forward), out hit))
		{
			distance = hit.distance;
			if (distance < maxDistance)
			{
				hit.transform.SendMessage ("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
			}

			if (hit.collider.tag == "TrainingDummy") 
			
			{
				other.GetComponent<Animation>().Play();
			}
	}
}

}
}