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 conflictbliz · Jul 21, 2011 at 04:22 AM · guiscorecounter

Score Counter Help

Ok so here is my score counter script to put on a GUI Text

  function OnGUI(){
    guiText.text =  "Score: "+CubeScript.Counter;
 }
 
 i want it so that when i collide with a cylinder it goes up by 10 so i have this script but it is not working
 
 
     static var Counter : int = 0;
 
 function OnCollisionEnter (myCollision : Collision)
 {
    if(myCollision.gameObject.name == ("Cylinder"))
    {
       Counter++;
    }
 }
Comment
Add comment · Show 8
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 Jaywalker · Jul 21, 2011 at 04:51 AM 0
Share

Hey, Ill need bit more information about where and how you're trying to impelement this. Is it all on the same object?if not do you reference the cubescript correctly? Also try to indent you code so is more readable and paste it using the 101010 button so its nicely formatted in you're question.

Cheers!

avatar image AVividLight · Jul 21, 2011 at 05:13 AM 0
Share

Like Vin said, we need a little more information about your code before we can help...

avatar image conflictbliz · Jul 22, 2011 at 04:03 AM 0
Share

o sorry the 2 scripts are seperate the GUI goes in a GUItext in a GameEmpty same as the object i am colliding with,then the cube script is to go onto the player because it's for mycollision. thanks alot (the only way i got the GUI to show up is if i put it in a GameEmpty)

avatar image Chris D · Jul 22, 2011 at 06:37 PM 1
Share

@conflictbliz please stop adding comments as answers; it's now non-trivial to look through this thread and see where things stand. In the future, either edit your original question or comment on it if you have clarifications to make.

Additionally, by deleting all your below comments and putting their details into your original question, you can make it readable (and more likely to have attention paid to it) once more.

avatar image Chris D · Jul 22, 2011 at 11:00 PM 1
Share

please stop adding comments and other questions as answers.

Show more comments

2 Replies

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

Answer by Jaywalker · Jul 22, 2011 at 06:20 AM

Hey,

I cannot check it right now but try this:

on the trigger (for example a box collider with the trigger boolean turned on)

 function OnTriggerEnter(other : Collider)
 {
     if(other.tag == "the tag for your player object")
     {
         GuiScript.Counter += 10;
     }
 
 }
 

And in your gui script (named GuiScript.js):

 static var Counter : int;
 
 function OnGUI()
 {
     GUI.Label (Rect (10, 10, 100, 20), "Score: " + Counter);
 }
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
2

Answer by crazyKnight · Jul 21, 2011 at 05:13 AM

firstly it wont be counter++ as you want the value to go up by 10 it will be counter+10

and to check the collision instead of checking with name its better you tag the cylinder and then check it

 function OnCollisionEnter(myCollision : Collision)
 {
       if(myCollision.gameObject.tag == "the name with which you tagged cylinder")
        counter+=10;
 }
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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Score/point counter system 1 Answer

GUI Text Score counter 3 Answers

GUI.box (Score counter) doesn't appear when game is on play. 1 Answer

Score count increase on hit 2 Answers

Score counter out of control, help needed. 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