Zombie Shooter VR

Shooting a Zombie in VR game
Shooting a Zombie in VR game

A VR game with unique concept to convert exercises into game actions e.g lifting your controller to certain height to shoot pistols in game.

https://youtu.be/cCHkLojpqJM?si=2ZQCISZqXHnHb3A6&t=25
https://youtu.be/cCHkLojpqJM?si=2ZQCISZqXHnHb3A6&t=25

CODE

There are multiple scripts attached to run this game smoothly but here's the code snippets that mainly contribute in game mechanics.

public class ZombieController : MonoBehaviour
{
    
    [SerializeField] PuppetMaster puppetMaster;
    public float health;
    [SerializeField] private Slider healthBar;
    private NavMeshAgent zombieAI;
    GameObject player;
    public bool isDead;
    AudioSource audioSource;
    public string difficultyLevel;
    void Start()
    {

        audioSource = GetComponent<AudioSource>();
        zombieAI = GetComponent<NavMeshAgent>();
        player = GameObject.FindWithTag("Player");
        health = 100;
        isDead = false;


        difficultyLevel = PlayerPrefs.GetString("Game Level");
        if (difficultyLevel == "Easy") { zombieAI.speed = 0.35f;}
        else if (difficultyLevel == "Medium") { zombieAI.speed = 0.7f;}
        else if (difficultyLevel == "Hard") { zombieAI.speed = 1f;}
    }
    void Update()
    {
        healthBar.value = health;
        zombieAI.SetDestination(player.transform.position);

        if (health < 1)
        {
            ZombieisDeadNow();
        }

    }
    void ZombieisDeadNow()
    {
        isDead = true;
        if (puppetMaster != null)
        {
            puppetMaster.state = PuppetMaster.State.Dead;
        }
        if (!audioSource.isPlaying)
        {
            audioSource.Play();
        }
        
        zombieAI.Stop();
        Invoke("RemoveDeadbody", 3f);
    }
    void RemoveDeadbody()
    {
        Destroy(gameObject);
    }

    }

Now, Zombie death will be controlled by below script and Ragdoll will be handled by Puppet Master.

public class ZombieDeathController : MonoBehaviour
{
    [SerializeField] PuppetMaster PuppetMaster;
    [SerializeField] GameObject zombieObject;
    ZombieController zombieControllerScript;
    void Start()
    {
        zombieControllerScript = zombieObject.GetComponent<ZombieController>();     
    }
    private void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.CompareTag("Ball"))
        {
            zombieControllerScript.health -= 10;
            if (zombieControllerScript.health < 1)
            {
                PuppetMaster.state = PuppetMaster.State.Dead;
            }
            StartCoroutine(HitEffect(collision.gameObject));
            
        }
    }
    public IEnumerator HitEffect(GameObject fireball)
    {
        yield return new WaitForSeconds(0.15f);
        Destroy(fireball);
    }
}

Made in UNITY