//Método que representa a visão no inimigo private void observar() { timer += Time.deltaTime; /* * Só usado para depurar * this.visao.setAbertura(this.aberturaDeVisao); * this.visao.setAltura(this.alturaDeVisao); * this.visao.setLargura(this.larguraDeVisao); * this.visao.setRaio(this.raioDeVisao);*/ //Debug.Log(timer); if (this.visao.getVendoPlayer() && this.estadoAtual != Enumerates.estadoComportamento.ATACAR) { // Debug.Log("vi ele"); this.estadoAtual = this.aoVerPlayer; this.viuPlayerAntes = true; timer = 0; } else if (this.visao.getVendoPlayer() == false && timer >= this.tempoDesistirDeSeguir && this.viuPlayerAntes) { // Debug.Log("Perdi ele "); timer = 0; this.estadoAtual = this.aoPerderPlayer; this.viuPlayerAntes = false; } else if (this.visao.getVendoPlayer()) { timer = 0; this.viuPlayerAntes = true; } }
// Update is called once per frame void Update() { this.observar(); this.distanciaDoPlayer = Vector3.Distance(transform.position, this.player.position); if (this.controllerLife.getEstadoAtual().Equals(Enumerates.estadoDeVida.Vivo)) { this.arma.setAtk(false); if (this.estadoAtual.Equals(Enumerates.estadoComportamento.IDLE)) { //Faz animação de idle } else if (this.estadoAtual.Equals(Enumerates.estadoComportamento.SEGUIR)) { if (this.distanciaDoPlayer <= distanciaDeAtk) { // Debug.Log("ficou menor"); this.estadoAtual = Enumerates.estadoComportamento.ATACAR; } else { this.followPlayer(); } } else if (this.estadoAtual.Equals(Enumerates.estadoComportamento.PATRULHAR)) { this.patrulharObj.patrulharMethod(); // Debug.Log(((PatrulharLinhaReta)this.patrulharObj).vetorPercorrido); } else if (this.estadoAtual.Equals(Enumerates.estadoComportamento.ATACAR)) { //Debug.Log("Entrou no atacando"); this.nav.SetDestination(transform.position); if (distanciaDoPlayer > this.distanciaDeAtk && this.visao.getVendoPlayer()) { this.estadoAtual = this.aoVerPlayer; } else if (distanciaDoPlayer > this.distanciaDeAtk && this.visao.getVendoPlayer() == false) { this.estadoAtual = this.aoPerderPlayer; } else { //faz o que é referente ao ataque //provavelmente executa animação Debug.Log("atacando"); this.arma.setAtk(true); //Esse trecho a abaixo é só para teste da arma this.arma.setPosition(new Vector3(0, 0, 1.6f)); //this.arma.setPosition(new Vector3(0, 0, -0.5f)); } } else if (this.estadoAtual.Equals(Enumerates.estadoComportamento.VOLTARPISICAOINICIAL)) { //Debug.Log("voltando"); this.nav.SetDestination(this.posInicial); if (transform.position.x == this.posInicial.x && transform.position.z == this.posInicial.z) { //Debug.Log("chegeu na pos inicial"); this.estadoAtual = this.aoVoltarPosicaoInicial; } } } }
public void setEstadoComp(Enumerates.estadoComportamento estado) { this.estadoAtual = estado; }