You've already forked zumbi-game
add basic UI to player
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private TMP_Text statsDispaly;
|
||||
|
||||
private float time;
|
||||
private int kills;
|
||||
|
||||
public void IncrementKills()
|
||||
{
|
||||
kills++;
|
||||
}
|
||||
|
||||
void FixedUpdate()
|
||||
{
|
||||
time += Time.fixedDeltaTime;
|
||||
statsDispaly.SetText($"Time: {time:F0}s | Kills: {kills}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6f30135307ff0ec4cb878cac80d60090
|
||||
@@ -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