Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Gambit · Mar 17, 2011 at 11:44 AM · guirespawndeath

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:?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Statement · Mar 17, 2011 at 12:34 PM 0
Share

Just a curious question: Have you programmed for UnrealScript prior to Unity? :) I notice you use ' for names and " for strings.

2 Replies

· Add your reply
  • Sort: 
avatar image
2

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; }

Comment
Add comment · Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Statement · Mar 17, 2011 at 12:29 PM 0
Share

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.

avatar image Niklas · Mar 17, 2011 at 12:29 PM 0
Share

This is true. However, you should probably rename the CreateDeathFunction in this example since it is misleading. Something like ShowDeathGui would be better imo :)

avatar image Statement · Mar 17, 2011 at 12:32 PM 0
Share

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 :)

avatar image Niklas · Mar 17, 2011 at 12:35 PM 1
Share

Facebook told me that you where going to "slen". Have a nice trip ;)

avatar image Gambit · Mar 17, 2011 at 12:35 PM 0
Share

thanks heaps :D

Show more comments
avatar image
1

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges