- Home /
Heath system need help
So i have a "Main Menu" when you click "play" it takes you to a Level selector Screen with all the levels, and you can click on any level and play it. When u play a Level you have 5 heart's that you go threw and if u have zero heart's it restarts the level.
HOW DO I MAKE IT SO WHEN YOU ARE AT 0 HEART'S IT takes 1 out of 3 golden hearts away, and when u have 0 golden hearts you can't play until the golden hearts regenerate. 1 golden heart takes 20 min to generate. BUT I ONLY WANT THE GOLDEN HEARTS TO APPEAR ON THE LEVEL SELECT SCREEN.
heres my code in #c for the level 5 hearts:
using UnityEngine; using System.Collections;
public class EnemyDamage : MonoBehaviour {
public GameManager gameMananger;
int damageValue = 1;
void OnTriggerEnter(Collider col){
if(col.gameObject.tag == "Player"){
gameMananger.SendMessage("PlayerDamaged", damageValue, SendMessageOptions.DontRequireReceiver);
}
}
} Also here my Level select Screen in #c
/// /// Level Select. /// Attached to Main Camera /// using UnityEngine; using System.Collections;
public class LevelSelect : MonoBehaviour {
public Texture backgroundTexture;
void OnGUI(){
//Display our Background Texture
GUI.DrawTexture (new Rect (0, 0, Screen.width, Screen.height), backgroundTexture);
//Displays our Buttons
if (GUI.Button (new Rect (Screen.width * .1f, Screen.height * .15f, Screen.width * .1f, Screen.height * .1f), "1")) {
print ("Clicked 1");
UnityEngine.Application.LoadLevel("Level1");
}
if (GUI.Button (new Rect (Screen.width * .2f, Screen.height * .15f, Screen.width * .1f, Screen.height * .1f), "2")) {
print ("Clicked 2");
}
} }
What do i add to make these changes or how do i make a new script for those new changes?
Answer by zharik86 · Jan 03, 2014 at 08:17 AM
On how many I understood when HEARTS OF GOLD ended, the player can't restart level. Therefore it should pass into the main menu. Otherwise there will be a restart. So, for example, for HEARTS OF GOLD it is necessary to create a separate class. In it to add static variable:
public class myData {
public static int myGoldHeart = 3;
//metod change count your gold heart
public static changeGoldHeart(int ch) {
myGoldHeart = ch;
}
}
After that, in that script where there is a restart, it is necessary to add the following condition:
if (myData.myGoldHeart > 0) {
Application.LoadLevel("myLevel1"); //restart level
} else {
Application.LoadLevel("MainMenu"); // go to the main menu
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613125409im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Apply Damage To Player On Collison With Specific Game Object 1 Answer
Damage taking? 1 Answer
Official Unity Space Shooter Tutorial 1 Answer
health system problems 0 Answers