hola amigos, sucede que… u.u programé una inteligencia artificial. consta de 3 scripts, el de la inteligencia artificial que es el que contiene los estados del enemigo, otro de rango de visión y otro del rango de ataque. En el de visión y ataque, definí que cuando el player hiciera colision con ese rango, pasará al estado de persecución y cuando salga, al de reposo, y lo mismo con el de ataque. Ahora, en la IA también tengo el estado de morir, que es lo que pasa con eso? Que la IA funciona, pero cuando coloco varios personajes y mato 1 mueren todos, porque la variable de estados la tengo como estática, osea que al sufrir una modificación allí, se modificara en los demás scripts.
quisiera saber como crear un método para que los enemigos puedan morir por separados
(in english, in this time of google translate u.u )
I programmed an artificial intelligence. Consists of 3 scripts, that of the artificial intelligence that is the one that contains the states of the enemy, another one of range of vision and another one of the range of attack. In the vision and attack, I defined that when the player collided with that range, it will pass to the state of persecution and when it leaves, to rest, and the same with the attack. Now, in AI I also have the state of dying, what’s wrong with that? That AI works, but when I put several characters and kill 1 all die, because the state variable I have as public, so that when undergoing a modification there, it will be modified in the other scripts.
aquí están los codigos (here is the codes):
#pragma strict
static var estado : int = 0; //estado de inteligencia artificial en el que se encuentra
var vida : float = 100;
var morir : boolean = false;
var nada : AnimationClip;
var corre : AnimationClip;
var ataca1 : AnimationClip;
var muere : AnimationClip;
var player : Transform;
function Start () {
}
function Update () {
if (estado == 0){
GetComponent.<Animation>().Play (nada.name);
}
if (estado == 1){
GetComponent.<Animation>().Play (corre.name);
transform.LookAt(player);
transform.Translate (Vector3 (0,0,1)*Time.deltaTime);
}
if (estado == 2){
GetComponent.<Animation>().Play (ataca1.name);
}
if (estado == 3){
GetComponent.<Animation>().Play (muere.name);
Destroy (this.gameObject, 2);
}
if (vida <= 0){
muerto = true;
}
if (muerto == true){
estado = 3;
vida = 0;
}
}
function OnTriggerEnter (other : Collider ){
if (other.gameObject.tag == "ManodelPlayer"){
vida -= 20;
}
}
#pragma strict
var on : GameObject;
var off : GameObject;
function Start () {
}
function Update () {
}
function OnTriggerEnter (other : Collider){
if (other.gameObject.tag == "Player" ){
IA.estado = 1;
}
}
function OnTriggerExit (other : Collider){
if (other.gameObject.tag == "Player" ){
IA.estado = 0;
}
}
#pragma strict
function Start () {
}
function Update () {
}
function OnTriggerEnter (other : Collider){
if (other.gameObject.tag == "Player" ){
IA.estado = 2;
}
}
function OnTriggerExit (other : Collider){
if (other.gameObject.tag == "Player" ){
IA.estado = 1;
}
}
gracias amigos.
thank you guys
