You've already forked zumbi-game
add zombie controller and implement damage system; update gun controller for raycasting; modify prefab and scene settings
This commit is contained in:
@@ -9,6 +9,11 @@ public class GunController : MonoBehaviour
|
||||
[SerializeField] private AudioSource audioSource;
|
||||
[SerializeField] private AudioClip triggerSoundEffect;
|
||||
|
||||
[Header("Raycast")]
|
||||
[SerializeField] private Transform muzzlePoint;
|
||||
[SerializeField] private float maxRange = 100f;
|
||||
[SerializeField] private float damage = 25f;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
rightTriggerAction.action.Enable();
|
||||
@@ -28,7 +33,22 @@ public class GunController : MonoBehaviour
|
||||
|
||||
private void HandleShoot()
|
||||
{
|
||||
Debug.Log("Shoot!");
|
||||
audioSource.PlayOneShot(triggerSoundEffect);
|
||||
|
||||
Vector3 origin = muzzlePoint != null ? muzzlePoint.position : transform.position;
|
||||
Vector3 direction = muzzlePoint != null ? muzzlePoint.forward : transform.forward;
|
||||
|
||||
if (Physics.Raycast(origin, direction, out RaycastHit hit, maxRange))
|
||||
{
|
||||
if (hit.collider.CompareTag("Zombie"))
|
||||
{
|
||||
if (hit.collider.TryGetComponent(out ZombieController zombie))
|
||||
{
|
||||
zombie.TakeDamage(damage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Debug.DrawRay(origin, direction * maxRange, Color.red, 0.5f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class ZombieController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private float maxHealth = 100f;
|
||||
private float currentHealth;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
currentHealth = maxHealth;
|
||||
}
|
||||
|
||||
public void TakeDamage(float amount)
|
||||
{
|
||||
currentHealth -= amount;
|
||||
Debug.Log($"{gameObject.name} dostal {amount} damage. HP: {currentHealth}/{maxHealth}");
|
||||
|
||||
if (currentHealth <= 0)
|
||||
{
|
||||
Die();
|
||||
}
|
||||
}
|
||||
|
||||
private void Die()
|
||||
{
|
||||
Debug.Log($"{gameObject.name} je mŕtvy!");
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9e6afdd2619c6db4e9c079733c664364
|
||||
Reference in New Issue
Block a user