// Update is called once per frame void Update() { bool targetIsDead; bool targetIsOutOfRange; if (target == null) { targetIsDead = false; targetIsOutOfRange = false; } else { // test if target is dead targetIsDead = target.GetComponent <HealthSystem>().healthAsPercentage <= Mathf.Epsilon; // test if target is out of range var distanceToTarget = Vector3.Distance(transform.position, target.transform.position); targetIsOutOfRange = distanceToTarget > currentWeaponConfig.GetMaxAttackRange(); } float characterHealth = GetComponent <HealthSystem>().healthAsPercentage; bool characterIsDead = (characterHealth <= Mathf.Epsilon); if (characterIsDead || targetIsOutOfRange || targetIsDead) { StopAllCoroutines(); } }
// Update is called once per frame void Update() { bool targetIsDead; bool targetIsOutOfRange; if (target == null) { targetIsDead = false; targetIsOutOfRange = false; } else { var targetHealth = target.GetComponent <HealthSystem>().healthAsPercentage; targetIsDead = targetHealth <= Mathf.Epsilon; float distanceToTarget = Vector3.Distance(gameObject.transform.position, target.transform.position); targetIsOutOfRange = distanceToTarget > currentWeaponConfig.GetMaxAttackRange(); } var characterHealth = gameObject.GetComponent <HealthSystem>().healthAsPercentage; bool characterIsDead = characterHealth <= Mathf.Epsilon; if (characterIsDead || targetIsDead || targetIsOutOfRange) { StopAllCoroutines(); } }
void Update() { bool targetIsDead; bool targetIsOutOfRange; if (target == null) { targetIsDead = false; targetIsOutOfRange = false; } else { var targetHealth = target.GetComponent <HealthSystem>().healthAsPercentage; targetIsDead = targetHealth <= Mathf.Epsilon; var distanceToTarget = Vector3.Distance(transform.position, target.transform.position); targetIsOutOfRange = distanceToTarget > currentWeaponConfig.GetMaxAttackRange(); if (lookAtEnemy && !targetIsOutOfRange && !targetIsDead) { Vector3 targetPosition = new Vector3(target.transform.position.x, transform.position.y, target.transform.position.z); transform.LookAt(targetPosition); } } float characterHealth = GetComponent <HealthSystem>().healthAsPercentage; bool characterIsDead = characterHealth <= Mathf.Epsilon; if (characterIsDead || targetIsOutOfRange || targetIsDead) { StopAllCoroutines(); } }
void Update() { bool targetIsDead; bool targetIsOutOfRange; if (target == null) { targetIsDead = false; targetIsOutOfRange = false; } else { targetIsDead = target.GetComponent <HealthSystem>().HealthAsPercentage <= Mathf.Epsilon; var distanceToTarget = Vector3.Distance(transform.position, character.transform.position); targetIsOutOfRange = distanceToTarget > currentWeaponConfig.GetMaxAttackRange(); } float characterHealth = GetComponent <HealthSystem>().HealthAsPercentage; bool characterIsDead = (characterHealth <= Mathf.Epsilon); // no update fica vendo se o personagem ou os inimigos estao mortos ou esta fora de alcance pra parar de atacar if (characterIsDead || targetIsOutOfRange || targetIsDead) { StopAttacking(); } }
// Update is called once per frame void Update() { bool targetIsDead; bool targetIsOutOfRange; if (target == null) { targetIsDead = true; targetIsOutOfRange = false; } else { float targetHealth = target.GetComponent <HealthSystem>().healthAsPercentage; targetIsDead = (targetHealth <= Mathf.Epsilon); float distance = Vector3.Distance(transform.position, target.transform.position); float range = currentWeaponConfig.GetMaxAttackRange(); targetIsOutOfRange = (distance > range); } float characterHealth = GetComponent <HealthSystem>().healthAsPercentage; bool characterIsDead = (characterHealth <= Mathf.Epsilon); if (characterIsDead || targetIsOutOfRange || targetIsDead) { StopAllCoroutines(); } }
void Update() { bool targetIsDead; bool targetOutOfRange; if (target == null) { targetIsDead = false; targetOutOfRange = false; } else { targetIsDead = target.GetComponent <HealthSystem>().HealthAsPercentage() <= Mathf.Epsilon; targetOutOfRange = currentWeaponConfig.GetMaxAttackRange() < Vector3.Distance(transform.position, target.transform.position); } bool characterIsDead = GetComponent <HealthSystem>().HealthAsPercentage() <= Mathf.Epsilon; if (characterIsDead || targetIsDead || targetOutOfRange) { StopAllCoroutines(); } }
private void Update() { currentWeaponConfig = weaponSystem.getCurrentWeapon; currentWeaponRange = currentWeaponConfig.GetMaxAttackRange(); distanceToPlayer = Vector3.Distance(player.transform.position, transform.position); // initial state //Debug.Log(gameObject.name + " State: " + state); // switch(state) // { // case States.attacking: // //Debug.Log(gameObject.name + " State: " + state); // if( distanceToPlayer > currentWeaponRange && distanceToPlayer > chaseRadius) // { // state = States.patrolling; // } // if(distanceToPlayer > currentWeaponRange && distanceToPlayer <= chaseRadius) // { // state = States.chasing; // } // if(state == States.attacking) // { // //Debug.Log("Attacking State"); // StopAllCoroutines(); // //weaponSystem.AttackTarget(player.gameObject); // } // break; // case States.patrolling: // if(patrolPath == null) // { // state = States.idle; // } // if(distanceToPlayer <= currentWeaponRange) // { // state = States.attacking; // } // if(distanceToPlayer <= chaseRadius && distanceToPlayer > currentWeaponRange) // { // state = States.chasing; // } // if(state == States.patrolling) // { // //Debug.Log("Patrolling State"); // StopAllCoroutines(); // weaponSystem.StopAttacking(); // //StartCoroutine (Patrol() ); // } // break; // case States.chasing: // if(distanceToPlayer <= currentWeaponRange) // { // state = States.attacking; // } // if(distanceToPlayer > chaseRadius) // { // state = States.patrolling; // } // if(state == States.chasing) // { // //Debug.Log("Chasing State"); // StopAllCoroutines(); // weaponSystem.StopAttacking(); // //StartCoroutine( ChasePlayer() ); // } // break; // case States.idle: // if(distanceToPlayer <= currentWeaponRange) // { // state = States.attacking; // } // if(distanceToPlayer <= chaseRadius) // { // state = States.chasing; // } // if(patrolPath != null) // { // state = States.patrolling; // } // //Debug.Log("Idle State"); // break; // default: // Debug.Log("No State!!"); // break; // } // new pluggable state AI if (currentState != null) { currentState.UpdateState(this); } }
void Update() { // check if target out of range, alive, etc. bool isTargetDead; bool isTargetOutOfRange; if (target == null) { isTargetDead = false; isTargetOutOfRange = false; } else { // test if target is dead isTargetDead = target.GetComponent <HealthSystem>().IsCharacterDead(); // test if target is out of range isTargetOutOfRange = Vector3.Distance(transform.position, target.transform.position) > currentWeaponConfig.GetMaxAttackRange(); } bool characterIsDead = GetComponent <HealthSystem>().IsCharacterDead(); if (characterIsDead || isTargetOutOfRange || isTargetDead) { StopAllCoroutines(); } }