Skip to content
Snippets Groups Projects
Commit c2d32524 authored by dethaa's avatar dethaa
Browse files

fix(skeleton shooting): only shoot when player is in range

parent ed9c8482
1 merge request!22Develop
......@@ -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;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment