j'ai voudrais savoir comment désactiver la fonction "chase" quand la fonction "attack" et en marche.
Peut-être une boolean, mais je ne sais pas comment la mettre en place sur ce script vu qu'on ne peut pas transformer une fonction en boolean.
Code : Tout sélectionner
#pragma strict
var AnimHealth : int = 100;
var EnemyHealth : int;
var Distance : float;
var Target : Transform;
var lookAtDistance : float = 20;
var chaseRange : float = 10;
var attackRange : float = 2.2;
var moveSpeed : float = 3;
var Damping : float = 6;
var attackRepeatTime : float = 1;
var damage : float = 10;
private var attackTime : float;
var controller : CharacterController;
var gravity : float = 20;
private var moveDirection : Vector3 = Vector3.zero;
function Start () {
attackTime = Time.time;
FindHealth();
}
function Update () {
Distance = Vector3.Distance(Target.position, transform.position);
if (Distance < lookAtDistance){
lookAt();
}
if (Distance < attackRange){
attack();
}
else if (Distance < chaseRange){
chase();
}
}
function lookAt (){
var rotation = Quaternion.LookRotation(Target.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation,Time.deltaTime * Damping);
}
function chase() {
GetComponent.<Animator>().Play("creature1run");
moveDirection = transform.forward;
moveDirection *= moveSpeed;
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
function attack() {
if (Time.time > attackTime){
if (AnimHealth >= 50){
GetComponent.<Animator>().Play("creature1Attack1");
}
if (AnimHealth < 50){
GetComponent.<Animator>().Play("creature1Attack3");
}
Target.SendMessage("PlayerDamage", damage);
Debug.Log ("The enemy has attacked");
attackTime = Time.time + attackRepeatTime;
}
}
function ApplyDamage (damage : int){
chaseRange += 30;
moveSpeed += 0.2;
lookAtDistance += 40;
AnimHealth -= damage;
}
function FindHealth(){
Target = GameObject.Find("Player").GetComponent(HealthScript).transform;
}