i can't kill the emeny ai

I’m working on a simple combat script. I set up the enemy ai to patrol a waypoint and do damage to the player and also take damage. I can’t get the ai to lose any damage when it is hit with the prefab I made. If anyone can point a mistake I made in this script it would be much appreciated.

public var path1 : Transform;
public var path2 : Transform; 
public var speed : float = 2;
public var maxHealth  : float = 1;


private var target : Transform;
private var controller : CharacterController;
private var currentHealth : int = maxHealth;


function Start()
{
	SetTarget(path1);
	controller = GetComponent(CharacterController);
	currentHealth = maxHealth;
}

function Update()
{
	//look at the target
	var Look : Vector3 = new Vector3(target.position.x, this.transform.position.y, target.position.z);
	transform.LookAt(Look);
	// move
	controller.SimpleMove(transform.forward*speed);
	}
}
function SetTarget(newTarget : Transform) : void
{
	target = newTarget;
}

function OnTriggerEnter(node : Collider) : void
{
	if (node.transform == target)
		{
		if (target == path1)
			SetTarget(path2);
		else if (target == path2)
			SetTarget(path1);
		} 
}
function OnTirggerEnter(other : Collider) 
{
if(other.tag == "shot")
{
 currentHealth -5;
  }
  }

function ModiflyHeath(change : float)
{
	currentHealth += change;
	if (currentHealth > maxHealth)
	{
		currentHealth = maxHealth;
	}
	if (currentHealth <= 0)
	{
		Destroy(this.gameObject);
	}
}

2 Answers

2

The first and most serious problem is that you have a function called ‘OnTirggerEnter()’. The function is called ‘Trigger’ not Tirgger’, so it will never be called. But if you spelled it correctly, then you would have an issue because you already have an ‘OnTriggerEnter()’ function. You need to move your shot code inside the existing ‘OnTriggerEnter()’ function.

In addition you need to also make sure the collider being used has "Is Trigger" checked.

made changes to my script still not working.

First, can you update your question above with the latest version of your script so we can see the changes you made. Second, is OnTriggerEnter() firing? Put a Debug.Log() statement inside and see if you are getting output. And confirm that the collider has the 'isTrigger' flag set as suggested by @Commander Quackers.

hope this helps