Zombie Shooter VR
.png)
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.
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);
}
}