- Home /
Health script
Hi guys, I'm having an issue with my health script. I've been following the BurgZerg tuts on nGUI vital bars and I have everything working except for the parts I want to add. For example and "game over" state and reducing scores (playerPrefs) when you are dead. Any suggestions?
using UnityEngine;
using System.Collections;
public class VitalBarBasic : MonoBehaviour {
public UISlider _slider;
public float _maxWidth;
void Awake()
{
_slider = GetComponent<UISlider>();
if (_slider == null)
{
Debug.LogError("Could not find UISlider");
return;
}
_maxWidth = _slider.foreground.localScale.x;
}
// Use this for initialization
void Start () {
UpdateDisplay(1);
}
void Update()
{
}
// Update is called once per frame
public void UpdateDisplay ( float x ) {
if( x < 0)
{
Debug.Log ("Game Over");
PlayerPrefs.SetInt("High Score", PlayerPrefs.GetInt("High Score") - 25);
x = 0;
}
else if( x > 1 )
x = 1;
}
public void DamageTaken ( float x ) {
_slider.sliderValue -= x;
if( x < 0)
PlayerPrefs.SetInt("High Score", PlayerPrefs.GetInt("High Score") - 25);
}
}
Comment
Your answer
Follow this Question
Related Questions
Trying to get 2 floats synced up. 2 Answers
Calling a c# script from js [for NGUI] 1 Answer
Public Health Var C# 1 Answer
health problem 1 Answer
Script Wont Take away health from my player when hit by enemy bullet. 0 Answers