diff --git a/Assets/Scripts/Enemy/SkeletonShooting.cs b/Assets/Scripts/Enemy/SkeletonShooting.cs index 682d821a7cf825ddb054a903c9bd40cf5d4830ce..e4662eef81b45fcb33584b24aea12a08a6fc9c2f 100644 --- a/Assets/Scripts/Enemy/SkeletonShooting.cs +++ b/Assets/Scripts/Enemy/SkeletonShooting.cs @@ -4,12 +4,14 @@ using UnityEngine; public class SkeletonShooting : MonoBehaviour { - Transform player; + // Transform player; + GameObject player; PlayerHealth playerHealth; public EnemyHealth enemyHealth; public int damagePerShot = 20; public float timeBetweenBullets = 3f; public float range = 100f; + public float shootingRange = 20f; float timer; Ray shootRay = new Ray(); //* @@ -28,7 +30,7 @@ public class SkeletonShooting : MonoBehaviour gunLine = GetComponent<LineRenderer>(); gunAudio = GetComponent<AudioSource>(); gunLight = GetComponent<Light>(); - player = GameObject.FindGameObjectWithTag("Player").transform; + player = GameObject.FindGameObjectWithTag("Player"); playerHealth = player.GetComponent<PlayerHealth>(); } @@ -40,12 +42,23 @@ public class SkeletonShooting : MonoBehaviour { DisableEffects(); } - if(timer >= timeBetweenBullets && Time.timeScale != 0 && enemyHealth.currentHealth >0 && playerHealth.currentHealth >0) + if(PlayerInRange() && timer >= timeBetweenBullets && Time.timeScale != 0 && enemyHealth.currentHealth >0 && playerHealth.currentHealth >0) { Shoot(); } } + bool PlayerInRange() + { + float distance = Vector3.Distance(transform.position, player.transform.position); + if (distance <= shootingRange){ + return true; + } else { + return false; + } + + } + public void DisableEffects() { gunLine.enabled = false;