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 pepefirst · Apr 20, 2011 at 06:20 PM · gui-textpoints-counter

GUI text Messages does not show and points counter do not stop at its prefixed limit

In my game the Player has to collect apples (like Penelope collects Orbs). Everything is working OK except that the the counter of apples (should stop in 5) that continues adding apples and the warning GUI message inside the function Pickup (else statement), which does not show the message "You can't carry any more apples". Thanks in advance for any help.

var carrying : int; var carryLimit : int; var deposited : int; var winScore : int; var appleCollect : AudioClip;

var carriedGui : GUIText;

var depositedGui : GUIText;

var guiMessage : GameObject;

private var timeSinceLastPlay : float;

public function Start() {

timeSinceLastPlay = Time.time;
UpdateCarryingGui();
UpdateDepositedGui();

}

function UpdateCarryingGui() { carriedGui.text = "Carrying: " + carrying + " of " + carryLimit; }

function UpdateDepositedGui() { depositedGui.text = "Deposited: " + deposited + " of " + winScore;
}

function Pickup()

{ if ( carrying < carryLimit ) { carrying++; UpdateCarryingGui();
}

else
{
    var warning : GameObject = Instantiate( guiMessage );
    warning.guiText.text = "You can't carry any more apples";
    Destroy(warning, 2);
}

} function OnTriggerEnter(collisionInfo : Collider) { if(collisionInfo.gameObject.tag == "apple") { carrying++; UpdateCarryingGui(); audio.PlayOneShot(appleCollect); Destroy(collisionInfo.gameObject); } }

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 Ben Holmes · Apr 20, 2011 at 06:28 PM

you should be calling Pickup() in OnTriggerEnter() instead of just incrementing. As for your GUIText I would guess that either your camera doesn't have a GUILayer component or the position of your text is off the screen. GUIText transforms are in screen space so if you want it in the middle of the screen you put it at 0.5, 0.5.

Comment
Add comment · Show 2 · 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 pepefirst · Apr 20, 2011 at 11:14 PM 0
Share

The GUI layer and position are O$$anonymous$$. In fact, if I write a text in the corresponding field on the Inspector the text shows up. Regarding Pickup() inside OnTriggerEnter, I will tell you the results as soon I test it.

avatar image pepefirst · Apr 22, 2011 at 01:49 AM 0
Share

According to your recommendation (and the same advice from Jesse Anders) I placed the relevant code-lines from Pickup() to OnTriggerEnter() and the 2 problems were SOLVED. Thanks a lot!

avatar image
0

Answer by burgunfaust · Apr 20, 2011 at 06:36 PM

The problem seems to be that there is no update to update the variables as you play through. You just set them and that's where they stay.

Put the following inside a function Update call:

function Update()
{
    var carrying : int;
    var deposited : int;
}

Since the limit of how many can be carried probably won't change, that can stay out. Same with win amount.

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 pepefirst · Apr 20, 2011 at 11:09 PM 0
Share

This does not resolved the problem. Thanks a lot, anyway.

avatar image burgunfaust · Apr 21, 2011 at 04:17 AM 0
Share

I'll get back to you tomorrow.

avatar image burgunfaust · Apr 21, 2011 at 01:46 PM 0
Share

You are destroying your warning gui too fast.It will pop up and then immediately be destroyed.

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

Hide GUI Text when button is pressed 1 Answer

How to set a counter to increase as an object increases on the X axis 1 Answer

Add Score for every Object inside a Box 2 Answers

Error : Expressions in statements must only be executed for their side effects. 1 Answer

Can I hide a group of GUI Text objects? 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