Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 khalil · Jul 23, 2011 at 09:44 PM · guidynamicvaluehudpassing

Dynamically pass integer values into separate scripts in C#?

Hey all, I have a very simple task but can't seem to find the Answer any where. I need to pass the total amount of money remaining from the shopping GUI display into the Money HUD (guiLabel) display. The Shop display is on a different script then the HUD display. .It is this way because the shopping display only displays when you enter a shop, and the Money HUD display is always visible, so that you can always know how much money you have. I need for the shop total to dynamically update the Money HUD total when ever i go shopping. The shopping total is a labeld display and the Money Hud is also a labeled display.

 enter code here

public int Shoppingtotal;

GUI.Label(new Rect(150,80,700,20),""+Shopping total); // i need this total to dynamically update into

;

;

public int MoneyHUD;

GUI.Label(new Rect(150,80,700,20),""+MoneyHUD); // into this total which is found in another script.

thank you very much!

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

4 Replies

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

Answer by khalil · Jul 25, 2011 at 10:11 PM

The solution to this problem was found through GameObject .SendMessage.

using UnityEngine; using System.Collections;

public class BaseButtons :BaseShop { void neededYethiore(float yethiore) { print(yethiore); } void OnGUI() { GUI.Label(new Rect(100,100,100,30),""+Yethiore); if(GUI.Button(new Rect (140,100,20,20),"+")) { neededYethiore(); //adds 5 to Yethiore. gameObject.SendMessage("neededYethiore",5.0f); }
}

}

and on the receiving Display Which is attached to the scripts game object.

void On GUI()
{
     GUI.Label (new Rect (30,30,30,30)""+Yethiore);
}

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
0

Answer by Graham-Dunnett · Jul 24, 2011 at 07:34 AM

I think the documentation gives you your answer (see bottom section about global variables.)

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
0

Answer by Waz · Jul 24, 2011 at 11:33 AM

So one script needs to know about the other. The simplest way (and also the cleanest way from an architectural point of view) is to have an explicit reference which you can set, so in Shopping.cs:

 public Money money;

Drag the GameObject with the Money script on it to this variable in the inspector. Then Shoppibg can talk to Money:

 money.MoneyHUD -= ShoppingTotal;

Or whatever interaction it is that you need to have between the scripts,

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
0

Answer by khalil · Jul 24, 2011 at 01:05 PM

Thanks form both of you guys.

But your descriptions of the problem as well as the reference material, are all simply to vague and without the amount of detail that one would need to actually implement your remedies. Could you both or at least one of you be way more descriptive and a bit less short ended? Thanks again. ~K

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

CoolDown Animation on the GUI 1 Answer

Odd question... can a GUIText object be displayed upside-down? 2 Answers

"NullReferenceException" while trying to draw a texture (C#) 1 Answer

Off Screen direction indicator HUD element / wrestling with Quaternion 1 Answer

Script loads font, how do I change the color? 2 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