Hi Rick and All,
Firstly, really loving this part of the course. But I had a heap of problems with this one. Mainly, the Try Again button would only work randomly.
It seemed the First Person Controller was causing issues. Disabling it was not straight forward either, because it seems as part of the standard asset pack it has its own namespace.
But I finally came up with the answer, you need to add the 'using UnityStandardAssets.Characters.FirstPerson; ’ at the top of the script.
Disabling the First Person Controller also means that you don’t need to use ‘Time.timeScale = 0’, which might be fun later to watch the enemies keep moving after you’re dead. But then you might need to disable the Weapon Script.
I also didn’t like that the gun was still showing when the death canvas came up. The gun is made up of a heap of components so I disabled it with a for each loop. Check out my code below.
I hope this helps.
Cheers
James
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.Characters.FirstPerson;
public class DeathHandler : MonoBehaviour
{
[SerializeField] Canvas gameOverCanvas;
void Start()
{
gameOverCanvas.enabled = false;
}
public void HandleDeath()
{
GetComponent<FirstPersonController>().enabled = false;
MeshRenderer[] meshRenderers = GetComponentsInChildren<MeshRenderer>();
foreach (MeshRenderer mesh in meshRenderers)
{
mesh.enabled = false;
}
Time.timeScale = 0;
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
gameOverCanvas.enabled = true;
}
}