- Home /
Help with calling and naming functions!
hey :)
iv been having trouble with this..im probably going over the top and/or over thinking it. but this is basically what im trying to do:
on my "Death.js"
function CreateDeathGUI() { GUI.Box(Rect(Screen.width/2, Screen.height/2, 150,75), "You died"); };
function Die() { CreateDeathGUI(); transform.position = GameObject.Find('Player').GetComponent('Spawn Pos').SpawnPos; };
for the button that kills the player:
// Kill Player shit
if (GUI.Button(Rect(10,25,130,30), "Die")){
GameObject.Find('Player').GetComponent('Death').Die();
}
now..it sets the players location back to spawn and everything....BUT it doesnt show the Deathgui
can help D:?
Just a curious question: Have you programmed for UnrealScript prior to Unity? :) I notice you use ' for names and " for strings.
Answer by Statement · Mar 17, 2011 at 12:26 PM
You could probably make some minor changes to your code to show the gui on death.
// Added. var showGui = false;
// Added. function OnGUI() { if (showGui) { CreateDeathGUI(); } }
// Same as before. function CreateDeathGUI() { GUI.Box(Rect(Screen.width/2, Screen.height/2, 150,75), "You died"); };
// Replaced call to CreateDeathGUI with this assignment instead function Die() { showGui = true;
transform.position = GameObject.Find('Player').GetComponent('Spawn Pos').SpawnPos;
};
Then you can have your calling code unaltered.
// Same as before.
if (GUI.Button(Rect(10,25,130,30), "Die"))
{
GameObject.Find('Player').GetComponent('Death').Die();
}
If you would want to wait a bit before setting the position so the gui shows a bit before, then you can do something like this:
function Die() { showGui = true; Invoke("Respawn", 3); // Wait 3 seconds to allow text to show a while Invoke("HideGui", 5); // And 2 seconds after respawn we should hide the gui };
function Respawn() { transform.position = GameObject.Find('Player').GetComponent('Spawn Pos').SpawnPos; }
function HideGui() { showGui = false; }
However I have a feeling you want to show the message "you died" a little while before positioning the player? You can delay such calls with Invoke. I'll actually make an edit to show just how.
This is true. However, you should probably rename the CreateDeathFunction in this example since it is misleading. Something like ShowDeathGui would be better imo :)
Yeah I could go into a debate about na$$anonymous$$g conventions and such but I have very little time. I'm prepped for a holiday in a skiresort so I try to make only the point and not so much more :)
Facebook told me that you where going to "slen". Have a nice trip ;)
Answer by Uzquiano · Mar 17, 2011 at 12:12 PM
You have to call your GUI functions from the OnGUI() function, or show your GUI components in the OnGUI() function
Your answer
Follow this Question
Related Questions
GUI not counting Player Deaths 3 Answers
Javascript GUI and deathscript weird compiler errors 1 Answer
Character losing life event not firing 1 Answer
Enemy Death and Respawn?? 3 Answers
Respawn after going past Y Height 1 Answer