Question by
TayhaJoy · Sep 18, 2016 at 07:39 AM ·
characterliveshealth-deduction
I'm trying to create a life system for my player but my codes not working, anyone got any ideas?
I'm really new to coding so i got this from a tutorial but its just not liking me.
public class LifeManager : MonoBehaviour {
public int startingLives;
private int lifeCounter;
private Text theText;
public GameObject gameOver;
public PlayerControl player;
// Use this for initialization
void Start () {
theText = GetComponent<Text> ();
lifeCounter = startingLives;
player = FindObjectOfType<Player>();
}
// Update is called once per frame
void Update () {
if (lifeCounter < 0) {
gameOver.SetActive (true);
player.gameObject.SetActive (false);
}
theText.text = "x " + lifeCounter;
}
public void GiveLife()
{
lifeCounter++;
}
public void TakeLife()
{
lifeCounter--;
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612093019im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Problem With a Multi-Jump C# script, robot 2d character controller 1 Answer
Can I ignore part of a vector3 for physics reasons? 0 Answers
Animation loop of the character 0 Answers
Rigidbody Stop when no key pressed 1 Answer
Changing characters 0 Answers