Hello, im creating just another boring island survival game. I have created partially working hunger and thirst and a working hole in Unity terrain to gain acces to cave so far. Now, im trying to do death of hunger/thirst or other things that i might implement in future. I want death to immobilize the player and show him a big bad red text “You died”. The second thing i got done without problems, but the first one did provide a entertainment for me. I decided to immobilize the player by turning off script ‘First Person Controller’ so he cannot move. Here is my script:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class licznikHP : MonoBehaviour {
public int HP = 100;
public Text Licznik; //HP counter
public GameObject Zgon; //Death screen
public GameObject Gracz; //Player object containing First Person Controller script that i want to deactivate, to make playing impossible after death.
private Component Kontroler; //Just to make things clear.
void Start() {
Kontroler = Gracz.GetComponent("FirstPersonController"); //Works
}
void FixedUpdate () {
Licznik.text = HP.ToString();
if(HP <= 0)
{
Zgon.SetActive(true); //Works
Kontroler.enabled = false; //<--- This gives an error
}
}
void min(int ile) //taking from overall HP using SendMessage from other script.
{
HP = HP - ile;
}
}
Thanks in advance.