- Home /
Lives = play
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?
Would be great if you could re-format that code and get rid of that caps stuff. Anyway, if you know how to check if your 5 hearts are at 0 you should be able to decrease the amount of golden hearts. Something like.. (pseudo code)
int regularHeart = 5;
int goldHeart = 3;
if(regularHeart < 1 && goldHeart > 0){
goldHeart -= 1; //is the same as goldHeart = goldHeart - 1;
}
regularHeart = 5;
Generating goldHearts would be a matter of checking the time that has passed and if 20 $$anonymous$$ have gone by you'd add 1 gold heart as long as you don't already have 3.
Depending on what type of game your making you would also have to make sure that the player can't cheat by simply setting the clock on his device to get the gold ones back quickly, but that's obviously up to you.
Your answer
Follow this Question
Related Questions
Energy or lives regen by time 1 Answer
Count down timer. 2 Answers
Timer not subtracting... 1 Answer
Making a Timer Out out of 3D Text using C#. 1 Answer
using player time as highscore 1 Answer