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 lemdi · Jun 12, 2011 at 11:32 AM · guitextscoring

scoring sing guiText

i have now tried coding but the counter on the guiText score dose not work:

 static var Counter : int = 0;

my other cube script

 function OnCollisionEnter (myCollision : Collision)
 {
    if(myCollision.gameObject.name == ("fireBall (Clone)"))
    {
       Counter++;  
    }
 }
  my guiText script
 function OnGUI(){
     guiText.text = "Score: "+CubeScript.Counter;
 }


   
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 Anxo · Jun 12, 2011 at 11:55 AM

that's better, did you delete your other question?

in the future please make sure you format your text using the 1010 button.

First of all, I would not really go the route of editing the variable directly from your collision object. but if you wanted to do that you need to tell it where Counter is. your line Counter++; does not know where to go. an easier way to go about it is to have this on your collider.

 var guiController : GameObject;
 
 function OnCollisionEnter(myCollision : Collision){
    if(myCollision.gameObject.name == ("fireBall(Clone)"))
    {
       guiController.BroadcastMessage("AddPoints",1);
     }
 }

you drag your guiController game Object into the slot guiController so that is assigned. then on your guiController you have this function

 function AddPoints(incPoint : int){
     Score += incPoint;
 }

that adds the score sent from your collider to the gui controller. You also don't want to search for name in your gui controller its slower than searching for tag so you could use myCollision.CompareTag("fireball"); instead of myCollision.gameObject.name. You will have to assign the fireball prefab to have the tag fireball.

in gui you have the right idea, just change guiText.text = "Score: "+ Score; or change my variable score to counter.

I hope that gets you on the right track.

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 lemdi · Jun 12, 2011 at 04:13 PM 0
Share

thank you it all works exept it says $$anonymous$$ identifier: 'Score'.

avatar image
0

Answer by FLASHDENMARK · Jun 12, 2011 at 11:53 AM

It looks fine and should work fine if the name is "fireBall (Clone)"

But if you do use OnCollisionEnter() then note it will only work on rigidbodys and static objects, but it will NOT work if you are using a trigger or a CharacterController.

  • So if you are using a characterController use OnControllerColliderHit().

  • If using a rigidbody use OnCollisionEnter().

  • if using triggers use OnTriggerEnter().

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

GUI Text not displaying/updating correctly (C#) 1 Answer

GUITextures not lining up correctly 2 Answers

GUI Text Showing Gameobjects information 3 Answers

Simple Point system 3 Answers

Gizmo-like GUi text? 2 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