My zombie that has the ai script won’t die from gunshots with the shooting gun script…
Any help will be appreciated.
Check out my youtube channel: http://www.youtube.com/user/Picardiastudios?feature=mhee
AI Script:
var target : Transform; //the enemy's target
var moveSpeed = 3; //move speed
var rotationSpeed = 3; //speed of turning
var myTransform : Transform; //current transform data of this enemy
var isNotDead : boolean = true;
var health : float = 100;
function Awake()
{
myTransform = transform; //cache transform data for easy access/preformance
}
function Start()
{
target = GameObject.FindWithTag("Player").transform; //target the player
}
function Update () {
if(health < 10){
isNotDead = false;
animation.Play("die");
Destroy(gameObject, 1);
}
if(isNotDead){
//rotate to look at the player
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
var distance = Vector3.Distance(target.position, myTransform.position);
if (distance < 3.0f) {
animation.Play("attack1");
}
else{
//move towards the player
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
animation.Play("walk");
}
}
}
function ApplyDamage(dmg : float){
health -= dmg;
}
Shooting Gun Script:
#pragma strict
var Range : float = 1000;
var Force : float = 1000;
var bullets : int = 5;
var shootSound : AudioClip;
function Start () {
}
function Update () {
if(Input.GetKeyDown(KeyCode.R)){
bullets = 5;
GameObject.Find("Gun").animation.Play("reload");
}
var hit : RaycastHit;
var direction : Vector3 = transform.TransformDirection(Vector3.forward);
Debug.DrawRay(transform.position , direction * Range , Color.blue);
if(Input.GetMouseButtonDown(0)){
audio.PlayOneShot(shootSound);
bullets--;
if(Physics.Raycast(transform.position , direction , hit, Range)){
var hitRotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
if(hit.collider.gameObject.tag == "zombie"){
//hit.rigidbody.AddForceAtPosition( direction * 100 , hit.point);
//hit.collider.gameObject.animation.Play("die");
hit.collider.gameObject.SendMessage("ApplyDamage", 25);
}
}
}
}