Im working on 2018.3.12f1 and C#
Hi, I have a script and I have 2 problems…
- If (Health == 0) doesnt work (see on image)
- Playerprefs doesnt work (see on image)
I have other scripts that both off these problems is working.
I cant upload the script image so I need to just copy and paste the text…
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class HealthSystem : MonoBehaviour
{
Text text;
public int health;
// Start is called before the first frame update
void Start()
{
text = GetComponent<Text>();
health = PlayerPrefs.GetInt("Health");
}
// Update is called once per frame
void Update()
{
text.text = health.ToString();
if (health < 0)
{
health = 0;
}
if (health == 0)
{
CoinScript.coins -= 50;
Debug.Log("You Died");
}
PlayerPrefs.SetInt("Health", health);
if (Input.GetKeyDown(KeyCode.V))
{
health -= 10;
}
}
}