public override void UpdateState(AgenteEstatico agent) { //Código para cuando no se detecta al jugador if (agent.targetDetected) { var lookRotation = Quaternion.LookRotation(agent.targetOdj.transform.position - agent.transform.position); agent.transform.rotation = Quaternion.Slerp(agent.transform.rotation, lookRotation, agent.speedRotation * Time.deltaTime); if (nextFire < Time.time) { agent.FireBullet(); nextFire = Time.time + rateFire; } } else { agent.TransitionToState(agent.idleState); } }
public override void UpdateState(AgenteEstatico agent) { if (agent.targetDetected) //Si el target sigue detectado { //Primero hacia que dirección esta el target, hacemos una resta entre las posiciones para obtenerla y guardarla en lookRotation var lookRotation = Quaternion.LookRotation(agent.targetObj.transform.position - agent.transform.position); //Realizaremos una rotación suave a lo largo de la ejecucion, apuntando siempre al target en base a la dirección guardada de lookrotation agent.transform.rotation = Quaternion.Slerp(agent.transform.rotation, lookRotation, agent.speedRotation * Time.deltaTime); //Controlamos los disparos, si el tiempo acumulado es menor a Time.time, puede disparar // Time.time es una varible de la librería de Unity, es el tiempo que esta transcurriendo en el juego if (nextFire < Time.time) { agent.FireBullet(); //Se manda llamar el metodo de disparar nextFire = Time.time + rateFire; //acumulamos el tiempo, para cuando toque disparar nuevamente } } else { agent.TransitionToState(agent.idleState); } }