// Update is called once per frame void Update() { // If we dont have a target do nothing if (target == null) { return; } AIUtilities.LookAtTarget(transform, target.position, maxRotation); AIUtilities.ClampTurretRotation(transform, minRotationAngle, maxRotationAngle); float angleToPosition = AIUtilities.GetAngleToTarget(transform, target.position); if (Vector3.Distance(transform.position, target.position) < 600) { if (Mathf.Abs(angleToPosition) < 1) { if ((_shotCounter += Time.deltaTime) > fireRate) { _shotCounter = 0.0f; Shoot(); } } } }
// Update is called once per frame void Update() { if (_target == null) { GameObject target = targetArea.GetObstacle(); if (target) { _target = target.transform; } } else { AIUtilities.LookAtTarget(transform, _target.position, maxRotation); AIUtilities.ClampTurretRotation(transform, minRotationAngle, maxRotationAngle); float angleToPosition = AIUtilities.GetAngleToTarget(transform, _target.position); if (Mathf.Abs(angleToPosition) < 1) { if (coRunning == false) { StartCoroutine(coShoot()); } } } }