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
2
Question by SmokeTear · Aug 19, 2012 at 02:31 AM · guiplayerprefsjava

Achievement System

How to make simple achievement system.

Im thinking in making a bool "Achieved = true" after a if statement saying that I hit something for first time and also having a SendMessage to another script. So that message will be "Achived". And on the other script it wil be :

 //JavaScript
 
 var Achieved = false;
 
 function Achieved(){
    if(Achieved == true)
    OnGui()
 }
    
 function OnGui(){
    GUI.Box(Rect(1,1,Screen.widht,Screen.height),"Achievement Earned!")
    if(GUI.Button(Rect(10,10,20,10),"Close"))
    //Closes the GUI.Box
 }
    

I dont know if this works or not I´m not good in sccripting just 13. Also to close the GUI.Box what do I use there? Help me please. And one thing - So when I hit something the script will send a message to the other script and the GUI.Box should pop-up saying that we Earned the achievement and if I click the button the Box should close.

  • ST

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by landon912 · Aug 30, 2012 at 10:00 PM

Here is a free tutorial on Unity Cookie makes a complete simple achievement system.link

Also you caint put a OnGUI function in an if statement it is called anyways and will give an error.

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
avatar image
2

Answer by aldonaletto · Aug 19, 2012 at 02:53 AM

You don't call OnGUI: all On... functions are events called by Unity when the specified action happens (like OnTriggerEnter, for instance). You should instead use a boolean variable to control whether the GUI items will appear or not - like this:

private var achieved = false; private var showGui = false;

function Achieved(){ if (achieved == false){ // if not achieved yet... achieved = true; // set flag achieved to true... showGui = true; // and show GUI items } }

function OnGUI(){ if (showGui){ // if GUI enabled by showGui: // draw the controls: GUI.Box(Rect(1,1,Screen.widht,Screen.height),"Achievement Earned!") if(GUI.Button(Rect(10,10,20,10),"Close")){ showGui = false; // set showGui to false to hide these GUI items } } }

Comment
Add comment · Show 3 · 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 J.D. · Aug 19, 2012 at 02:55 AM 0
Share

Just a correction: GUI should be upper case.

OnGUI()

avatar image SmokeTear · Aug 30, 2012 at 09:12 PM 0
Share

So Basicaly when the player trigger something in his scripts like - OnCollsion or if he Jumped 10000 times. Then it sends a message to this script that you've posted. Then it should work exact as you said.

avatar image aldonaletto · Aug 31, 2012 at 12:24 AM 0
Share

Yes: you must call the function Achieved via Send$$anonymous$$essage, what will set the variables achieved and showGui - the first shows that Achieved was called, and the latter enables the GUI items. An example: the script below can be attached to a trigger object, and will call the function Achieved in any player script when the player enters the trigger

function OnTriggerEnter(other: Collider){
  if (other.tag == "Player"){ // remember to tag the player as "Player"
    other.Send$$anonymous$$essage("Achieved");
  }
}
NOTE: $$anonymous$$y answer had some errors: variable and function with the same name (Achieved) and OnGUI written as OnGui . It's fixed now.

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

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to set high score (best time) with playerprefs 1 Answer

GUI box problem? 0 Answers

Stand alone player 0 Answers

Question on playerprefs 2 Answers

GUITime and Score issue. 0 Answers


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