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 JimNix · Mar 24, 2010 at 02:04 AM · inheritanceonguigui-text

Inheritance (Printing a toString for subclasses)

My apologies. Could this thread please be removed. Or at the very least the code posted.

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

3 Replies

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

Answer by qJake · Mar 24, 2010 at 03:13 AM

Looking it over again... you said the problem was "flickering" text, like multiple text objects were being drawn at the same time, correct?

When using inheritance, if you create an "Adult", for example, it also creates a "Person". So if you have two "Adults", then, technically, you also have two "Person" objects (programming objects, not game objects). I'm assuming that if you have multiple villagers, then you have multiple instances of the "Person" class, and therefore, multiple text objects all trying to draw in the same position, at the same time.

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 qJake · Mar 24, 2010 at 02:28 AM

I'm not exactly clear on what's going on... but my best suggestion is: are you sure you're using OnMouseDown() properly? Are you sure you don't want to be using this instead?:


function Update()
{
     if(Input.GetKeyDown("mouse 0"))
     {
          toString();
     }
}

Additionally, you should look into using String.Format() instead of just concatenating everything. It makes your code a lot easier to read. (The code is in .NET languages (like C#), but it can be used with Javascript in the same way.) Just a suggestion ;)

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 qJake · Mar 24, 2010 at 08:13 PM

What you probably need to do is have some sort of flag (read: boolean variable) to determine whether or not the GUIText should draw or not. Here's one way of doing it:

  • In the Person class, have a bool variable, something like "drawDebugText". Make sure it's false to start with.
  • When the user clicks on a villager, loop through every villager and set "drawDebugText" to false. Then set the one that you just clicked on, to true.
  • In OnGUI(), have something like if(drawDebugText) { // draw here // }

If you're not sure about how to loop through all villagers, consider adding a tag or component that will allow you to find all of them at once.

(Also, hooray for 3 answers :) )

Comment
Add comment · Show 1 · 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 qJake · Mar 25, 2010 at 04:26 AM 0
Share

It doesn't matter, either way it sounds like you're going to have to end up looping through all the game objects. If I were you, I would just end up using the console and Debug.Log() or print(), it's a hell of a lot easier than doing all this work just for debug information. ;)

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

An OS design issue: File types associated with their appropriate programs 1 Answer

Visual Studio Code Mac (1.29.1) problem with class inheritance Unity (2018.2.17f1) 0 Answers

Unity exports my derived class, but not its base class (C# OOP) - Is there a workaround? 0 Answers

How to work with a list of base class, if a variable is only found in some subclasses? 2 Answers

How to handle different GUI.Toogles in one GUI-Script to execute a specific function? 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