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(); } }
bool IsTargetInRange(GameObject target) { if (myRPGWeapon == null) { return(false); } float distanceToTarget = (target.transform.position - transform.position).magnitude; return(distanceToTarget <= myRPGWeapon.GetMaxAttackRange()); }