how to make an AI damage a third person controller ?

how do I make a “zombie” who deals damage when he hits me with his sword ? I have a c# code and i have set the animations that he follows me and then when he comes into a certain range he attacks me. Soo how do I make my character take damage ? or when my character takes too much damage then he dies ? Please help :slight_smile:

using UnityEngine;
using System.Collections;

public class chase : MonoBehaviour {

	public Transform player;
	static Animator anim;

	// Use this for initialization
	void Start () 
	{
		anim = GetComponent<Animator>();
	}
	
	// Update is called once per frame
	void Update () 
	{
		Vector3 direction = player.position - this.transform.position;
		float angle = Vector3.Angle(direction,this.transform.forward);
		if(Vector3.Distance(player.position, this.transform.position) < 10 && angle < 30)
		{
			
			direction.y = 0;

			this.transform.rotation = Quaternion.Slerp(this.transform.rotation,
										Quaternion.LookRotation(direction), 0.1f);

			anim.SetBool("isIdle",false);
			if(direction.magnitude > 3)
			{
				this.transform.Translate(0,0,0.05f);
				anim.SetBool("isWalking",true);
				anim.SetBool("isAttacking",false);
			}
			else
			{
				anim.SetBool("isAttacking",true);
				anim.SetBool("isWalking",false);
			}

		}
		else 
		{
			anim.SetBool("isIdle", true);
			anim.SetBool("isWalking", false);
			anim.SetBool("isAttacking", false);
		}

	}
}

Unity knows nothing about “damage”. Thats game logic.

You need to make a “health” component that tracks health and has a public method to call to do damage.

Then you do something like this
player.GetComponent.TakeDamage(damageAmount);