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 Conect11 · Dec 17, 2013 at 03:17 AM · guioverlap

Choose which GUItext to display

Hi, it's me again.

So I've got a treasure chest. Several of them, actually, and all of them contain different amounts of gold. Decided to make a script where I could enter how much gold in the inspector. I also have a script attached that displays a GUItext when you open the chest, giving the amount of gold you just earned. However, it appears to my eyes that the GUItext is actually combining the amounts from ALL the chests with that script. (so that it always overlap the amount of gold - kir in this game - from ALL the chests with that script attached) Am wondering if anyone knows a solution to that. Bonus round: I'm sure there's a way to combine the scripts, but every time I try to run OnGui from within the openchest script, I never trigger the GUI, so good on ya if you're able to help this noob figure out how to do this in one script. Thanks, and God bless.

alt text

Script 1: Chest open

 var    chestSound : AudioClip; //chest opening sound clip goes here
 var treasureChest : GameObject; //treasure chest prefab goes here
 var moneyinchest : int;
 
 
  
 // function Start(){
  //if(PlayerPrefs.GetInt("Opened Chest", 0) == 1){
  //Destroy(gameObject);
 // }
 // }
  
 function OnTriggerEnter (col : Collider) {
 //PlayerPrefs.SetInt("Opened Chest", 1);
 if(col.gameObject.tag == "Player") { //checks to see that our character controller with tag "Player" has entered the trigger
 Playermoney.curMoney += moneyinchest;
 openmoneychestgui.openchest = true;
 AudioSource.PlayClipAtPoint(chestSound, transform.position); //plays our soundclip at position of collider/trigger
 treasureChest.animation.Play(); //plays the default animation applied to our treasureChest model
 Destroy(gameObject);// destroys the gameobject that has this script, so our collider in this case
  
  
 }
 }

Script 2: Display GUI

 static var openchest:Boolean=false;
 var moneybox : GameObject;
 var chestopenmoneyScript : chestopenmoney;
 
 
 //function Start (){
 //chestopenmoneyScript = moneybox.GetComponent("chestopenmoney");
 //}
 
 
 function OnGUI () {
      
      
      if(openchest == true) 
      if(GUI.Button(Rect(800,700,400,175),"You found" +   chestopenmoneyScript.moneyinchest +   "kir!"));{
      
       }
     }
     
     function Update () {
     if(Input.GetButtonDown("Action"))
      openchest = false;
      }


kirchest.png (116.5 kB)
Comment
Add comment · Show 2
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 Tomer-Barkan · Dec 17, 2013 at 08:56 AM 0
Share

what is openmoneychestgui?

avatar image Conect11 · Dec 18, 2013 at 02:04 AM 0
Share

that's the name of the gui script that the first script fires to. As it were, praise God, I figured out last night that what I needed to do was start the game with the GUI script disabled, and then simply enable it when the chest is opened. =)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Conect11 · Dec 18, 2013 at 02:05 AM

So, as I suspected the issue was that ALL instances of the GUI script were running when one chest was opened. The answer was simply to start the game with each GUI script disabled, and enable them individually when a chest is opened.

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

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

Related Questions

Resizable GUI box how to? 1 Answer

Strange GUITexture prefab problem with pixelInset.width 1 Answer

How do I change the text of a gui image text 1 Answer

Gui overlapping camera on camera 1 Answer

Why does my slide out menu not work when i translate from JS to C#? 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