Hi there the problem i am having is when i destroy an enemy all other enimies stop targeting me and stay still i will show both scripts that i think are doing this first one is AI seconds is AI health
function Awake()
{
animation["Walk"].layer =0;
}
var waypoint : Transform[];
static public var speed : float = 20;
private var currentWaypoint : int;
var loop : boolean = true;
var player : Transform;
function Update() {
var distFromPlayer : Vector3 = player.position - transform.position;
if(currentWaypoint < waypoint.length){
var target : Vector3 = waypoint[currentWaypoint].position;
var moveDirection : Vector3 = target - transform.position;
var velocity = rigidbody.velocity;
if(moveDirection.magnitude <1){
currentWaypoint++;
}
else if (distFromPlayer.magnitude < 20){ // If we are close to the enemy
velocity = Vector3.zero;
target = player.position;
velocity = (player.position - transform.position).normalized * speed;
if((player.position - waypoint[currentWaypoint].position).magnitude > 20){
target = waypoint[currentWaypoint].position;
velocity = moveDirection.normalized * speed;
}
}
else{
velocity = moveDirection.normalized * speed;
}
}
else{
if(loop){
currentWaypoint = 0;
}
else{
velocity = Vector3.zero;
}
}
rigidbody.velocity =velocity;
transform.LookAt(target);
}
AI Health
var health : int = 100;
var prefab : Transform;
var sound : AudioClip;
var Points : Transform;
var smallleaf : Transform;
var branch : Transform;
function OnCollisionEnter (hit : Collision)
{
if(hit.gameObject.tag == "Bottle")
{
health -= 25;// Take 25 away from the monsters health
AudioSource.PlayClipAtPoint(sound,transform.position);// When the mosnetr is hit play a sound at it's position
var instanceBullet2=Instantiate(smallleaf,transform.position, transform.rotation);//clone an object when the monster is hit
Debug.Log (health);//tell us if the health is worrking
animation.Play("Hit");//Play the animation Hit
yield WaitForSeconds(0.6);//Wait for 0.6 seconds before playing the next animation
animation.CrossFade("Walk");// Smoothly transition between hit and walk
animation.Play("Walk");// Play the animation Walk
if (health <= 0)
{
animation.Play("LookAround");// Play the animation if we are dead
MonsterTreeAI1.speed = 0;
yield WaitForSeconds(3);//play the animation in it's full length
Destroy(gameObject);
AudioSource.PlayClipAtPoint(sound,transform.position);//Play a AudioClip at the objects position
var instanceBullet=Instantiate(prefab, transform.position, transform.rotation);//spawn a prefab
var instanceBullet1=Instantiate(Points, transform.position, transform.rotation);//spawn a prefab
var instanceBullet3=Instantiate(branch, transform.position, Quaternion.identity); //spawn a prefab
}
}
}
You are a star mate ******************************** works perfect
– john-essyWell apart from now when i set the speed to 0 it sets the speed to 0 through all of my enemy prefabs any Ideas
– john-essySorted it
– john-essy