You've already forked zumbi-game
add basic UI to player
This commit is contained in:
@@ -29,7 +29,7 @@ public class ZombieController : MonoBehaviour
|
||||
[SerializeField] private AudioClip[] sfx;
|
||||
[SerializeField] private int sfxDelay = 5; // seconds
|
||||
|
||||
private Transform player;
|
||||
private PlayerController player;
|
||||
private Animator animator;
|
||||
private AudioSource audioSource;
|
||||
private float lastSfxPlay;
|
||||
@@ -40,7 +40,7 @@ public class ZombieController : MonoBehaviour
|
||||
{
|
||||
currentHealth = maxHealth;
|
||||
animator = GetComponent<Animator>();
|
||||
player = GameObject.FindGameObjectWithTag("Player").transform;
|
||||
player = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerController>();
|
||||
audioSource = GetComponent<AudioSource>();
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public class ZombieController : MonoBehaviour
|
||||
|
||||
PlaySfx();
|
||||
|
||||
float distance = Vector3.Distance(transform.position, player.position);
|
||||
float distance = Vector3.Distance(transform.position, player.transform.position);
|
||||
|
||||
if (distance <= attackDistance)
|
||||
{
|
||||
@@ -92,9 +92,9 @@ public class ZombieController : MonoBehaviour
|
||||
|
||||
private void MoveToPlayer(float speed)
|
||||
{
|
||||
Vector3 direction = (player.position - transform.position).normalized;
|
||||
Vector3 direction = (player.transform.position - transform.position).normalized;
|
||||
transform.position += speed * Time.deltaTime * direction;
|
||||
transform.LookAt(new Vector3(player.position.x, transform.position.y, player.position.z));
|
||||
transform.LookAt(new Vector3(player.transform.position.x, transform.position.y, player.transform.position.z));
|
||||
}
|
||||
|
||||
private void StopMoving()
|
||||
@@ -129,7 +129,10 @@ public class ZombieController : MonoBehaviour
|
||||
private void Die()
|
||||
{
|
||||
Debug.Log($"{gameObject.name} is dead");
|
||||
|
||||
animator.SetTrigger(DieHash);
|
||||
player.IncrementKills();
|
||||
|
||||
Destroy(gameObject, 2f);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user