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 Natzely_legacy · Jul 17, 2012 at 06:57 PM · c#referencescalls

A better way to stop sending updates to another object.

This is what I'm currently doing. I have two GUITexts as children of a GUITexture that gets updates from a gameobject that is clicked on. When the gameobject gets clicked on, it uses a reference I've set up in the Inspector to send its information to the GUITexture. The GUITexture then updates its children with the information that was provided. The gameobject keeps updating the information by calling a public function in the GUITexture's script.

The problem is that when a different gameobject is clicked I want the old one to stop updating the GUITexture so the new one can. I'm not sure how to do this easily and my solution doesn't seems quite right.

The way I'm fixing this is setting up references to every thing that can update the GUITexture, having a "menu number" being sent to the GUITexture and checking them to grab the correct information from the reference script. You can also click on objects that are initiated later in the game by also sending the object's name and then looking it up with gameobject.find, then grabbing it's script and then grabbing the information for the two GUITexts.

My hopes were that it's somehow possible to send a reference of the last script that called the public function and using that reference to tell it to to stop.

Any ideas? The scripts below don't have the fixes I mention above as I just thought of them and wanted to check with you guys before I implemented them.

Some C# script: The GUITexture

public class GUIInfo : MonoBehaviour { public DisasterArea disasterArea; public Hospital hospital; public ScoutTeam scoutTeam; public MedicSite medicSite;

 public GUIText type;
 public GUIText data;
 
 private int currentNumber;
 private string currentName;
 
 void Start()
 {
     currentNumber = -1;
 }
 // Update is called once per frame
 public void ChangeTypeData(string msgName, int msgNumber, string msgType, string msgData)
 {
     if(currentNumber != msgNumber && currentNumber != -1)
     {
         if(currentNumber == 0)
             disasterArea.StopSendInfo();
         if(currentNumber == 1)
             scoutTeam.StopSendInfo();
     }
     currentName = msgName;
     currentNumber = msgNumber;
     type.text = msgType;
     data.text = msgData;
 }

} -----The object that calls-------

public class DisasterArea : MonoBehaviour { public GUIInfo guiInfo; public int wounded;

 private bool sendInfo;
 private int tempWounded;

 void Start () 
 {
     sendInfo = false;
     tempWounded = 0;
 }
 
 void Update()
 {
     if(sendInfo && tempWounded != wounded)
     {
         guiInfo.ChangeTypeData(gameObject.name, 0, "Wounded", wounded.ToString());
         tempWounded = wounded;
     }
 }
 
 void OnMouseDown()
 {
     guiInfo.ChangeTypeData(gameObject.name, 0, "Wounded", wounded.ToString());
     sendInfo = true;
 }
 
 public void StopSendInfo()
 {
     sendInfo = false;
 }

}

edit: Hazaa! I figured out the code snippet stuff!

edit2: Updated Code to show the fixes, it seems to work well. Gonna try the vehicles next as they are instantiated.

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 Bovine · Jul 17, 2012 at 07:44 PM 0
Share

Hard to say, but it looks like you're updating the GUI constantly. I'd be tempted to try and make it event driven, but it's hard to say how this might look for you, without understanding your situation better.

Here's an example of what we do: We have health and power in our GUI and ins$$anonymous$$d of constantly watching the value of the players health, we subscribe to C# events on the player's PlayerCharacter class which are triggered when the health or power change and we only update the GUI when some change has occurred.

I don't know if that might help you think of a different way to do what you're doing, but otherwise if you can describe what is going one from the player's perspective, that might help my understanding a bit.

avatar image Natzely_legacy · Jul 17, 2012 at 08:21 PM 0
Share

Yeah, I know I'm not explaining myself too well. The game would be close to a Sim's type game, very loosely though. There isn't a "player" but you use types of currency to buy and upgrade stuff. This part of the code deals with getting that objects information and having it update it and stop when a new item is clicked.

I did add a check to only send the message if the variable changes. Thanks.

0 Replies

· Add your reply
  • Sort: 

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Is it possible to access a variable in a different script without reference? 2 Answers

Reference to player won't sustain in same script 1 Answer

Script never seems to get the reference passed as param. 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