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 Spencer 1 · Nov 26, 2010 at 04:16 PM · scoringgui-text

Score with gui-Text

I need help with scoring in gui-text. I'm trying to make the gui-text count up when it hits a cube. I'm having trouble with this script.

var Counter : int = 0;

function OnCollisionEnter (myCollision : Collision) { if(myCollision.gameObject.name == ("Cube")); Counter++;{ guiText.text : "Score: "+Counter; } }

Please help.

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

Answer by oliver-jones · Nov 26, 2010 at 05:12 PM

Clean up of your code:

var Counter : int = 0;

function OnCollisionEnter (myCollision : Collision) { if(myCollision.gameObject.name == ("Cube")) { Counter++; guiText.text : "Score: "+Counter; } }

Try that, your code was messy, so I believe I have put things in the right place. Give it ago

---EDIT--- Okay, for this, I would suggest making 2 scripts, 1 where all your GUI functions go, and another for the cube.

Script GUI:

function OnGUI(){
   guiText.text : "Score: "+CubeScript.Counter;
}

CubeScript:

static var Counter : int = 0;

function OnCollisionEnter (myCollision : Collision) { if(myCollision.gameObject.name == ("Cube")) { Counter++; } }

Place the ScriptGUI into a game empty within your scene. For now on: Everything to do with your GUI should be placed within that script - makes everything really easy.

Comment
Add comment · Show 6 · 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 Spencer 1 · Nov 26, 2010 at 06:58 PM 0
Share

Thank you, that sort of helped, the eror mesages are gone. but the script won't work.

avatar image oliver-jones · Nov 26, 2010 at 07:37 PM 0
Share

What are you trying to get the script to do? If you want to display GUI text then you need to put it into a function OnGUI, and then place this function on top of a game empty - I'll update the post>

avatar image Spencer 1 · Nov 30, 2010 at 07:04 PM 0
Share

For the moment it says it's still compilling

avatar image Spencer 1 · Nov 30, 2010 at 10:03 PM 0
Share

It all works but the counter wont count up when it hits the cube.

avatar image oliver-jones · Nov 30, 2010 at 10:10 PM 0
Share

Does the variable 'count' itself move? Print the count variable and see if it goes up. If it doesn't then you have a problem in your count script somewhere - hard to tell as you haven't uploaded it

Show more comments
avatar image
0

Answer by Jesse Anders · Nov 26, 2010 at 04:27 PM

Please use code formatting (the little button with 1s and 0s on it) when posting code. It doesn't always work correctly (IMX), but it will be better than what you have now. (You can edit your post and make this change.)

In any case, it looks like you have an errant semicolon after your 'if' statement. I'm not quite clear on what happens after that though. Is this your actual code? If so, does it compile, or are you getting compiler errors? (You can edit your original post to add additional information as needed.)

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 Spencer 1 · Nov 30, 2010 at 06:46 PM 0
Share

I can't find a button with 1's and 0's on it. what are you talking about

avatar image Jesse Anders · Nov 30, 2010 at 07:01 PM 0
Share

It's probably no longer relevant for this thread, but for future reference, when you create or edit a post, there should be a row of buttons/controls right above the content area. One is a little icon of the earth with an arrow (hyperlink), one is a double-quote mark (quote), and one has 1s and 0s on it. The one with 1s and 0s is the one to which I'm referring.

avatar image
0

Answer by Jay_Adams · Nov 27, 2010 at 01:07 AM

I've been having problems getting this to work for about a week.

Just wanted to say thanks Oliver, I'm now up and running.

@Jesse,

I don't know if it's required, but I also put a component/rendering/GUIText onto my ingame object that contains GUI stuff (my health meter [guitexture]) That let me type, pick font, size, and place it on screen where I wanted.

Olivers "score" showed in game instead of the text I wrote (a cuss word, lol), but in the same spot/font/etc..

(I think if you don't put the guiText on there you have to specify placement/font via script, not as easy IMO)

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 Spencer 1 · Nov 30, 2010 at 06:54 PM 0
Share

Could you show me your script

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

Score Not Adding Up..? 1 Answer

create a box that player can type in it ( only type numbers ) 1 Answer

My GUItext does not display when an object is rotated, and ideas? 0 Answers

How to set your numbers to expand the opposite direction? 1 Answer

Score System? 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