- Home /
If health = 0, show a GUI.button C#
I want to know the lines of script to add on in order that when the player health = 0 or is destroyed, a GUIbutton is shown. I have tried to do this but it does not work. Here are the exerpts from my script- Thanks,
void Update(){
health += Input.GetAxisRaw("Horizontal");
if (health < 0){
health = 0;
destroy = true;
Destroy();
}
void Destroy(){
if(GUI.Button(new Rect(100, 100, 100, 100),"Level Complete")){
Application.LoadLevel(1);
}
Answer by namekaw · Apr 19, 2013 at 07:54 PM
Did this and worked (did not use Destroy()):
void OnGUI() {
if(destroy == true){
GUI.Box(new Rect(400,150,500,300), "Level Complete!");
if(GUI.Button(new Rect(100,100,80,80),"Next level")){
Application.LoadLevel(1); } }
Answer by DaveA · Mar 10, 2013 at 07:48 PM
The code would be the same in both languages. Just paste your js code into your c# class. Except instead of function OnGUI() it's void OnGUI()
Your answer
Follow this Question
Related Questions
Why don't my send messages work? 2 Answers
Remove self from gameObject before instantiate 1 Answer
C# issue, health, and destroying affect other objects. 3 Answers
Enemy Health Problems 1 Answer
Distribute terrain in zones 3 Answers