**Can you help me**
![alt text][1]
[1]: /storage/temp/49151-capture.jpg
using UnityEngine;
using System.Collections;
public class EnemyController : MonoBehaviour{
NavMeshAgent nav;
Transform player;
Animator controller;
float health;
GameManagement game;
CapsuleCollider capsuleCollider;
Animator anim;
bool isDead = false;
int pointValue = 10;
public float timeToAttack;
void Awake(){
nav = GetComponent ();
player = GameObject.FindGameObjectWithTag ("player").transform;
controller = GetComponentInParent ();
game = FindObjectOfType ();
health = 20 + (1.25f * game.round);
capsuleCollider = GetComponent ();
anim = GetComponent ();
}
void Update (){
if (!isDead)
{
nav.SetDestination (player.position);
float distance = Vector3.Distance(transform.position, player.position);
if (distance < 3)
{
attackTimer += Time.deltaTime;
}
else if (attackTimer > 0)
{
attackTimer -= Time.deltaTime*2;
}
else
attackTimer = 0;
}
}
bool Attack()
{
if (attackTimer > timeToAttack)
{
//sound
attackTimer = 0;
return true;
}
return false;
}
void ApplyDamage(float damage)
{
health -= damage;
if (health <=0)
Death ();
GameManagement.AddPoints(pointValue);
}
void Death ()
{
isDead = true;
nav.Stop ();
capsuleCollider.isTrigger = true;
anim.SetTrigger ("isDead");
//GameManagement.score += 10;
//GameManagement.money += 10;
//enemyAudio.clip = deathClip;
//enemyAudio.Play ();
Destroy (gameObject, 4f);
}
void OnCollisionStay(Collision collisionInfo)
{
if(collisionInfo.gameObject.tag == "player")
{
if(Attack ())
collisionInfo.collider.MessageUpwards("PlayerDamage", damage, SendMessageOptions.Rect);
}
}
}
↧