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 eMs · Sep 25, 2013 at 06:01 PM · collisioncountergui-text

guitext count up when collide

what am i doing wrong here? what im trying to do is when this object collides with the object with the tag gold, the goldcouter counts +1

 var goldtext : GUIText;
 
 var goldcounter : int = 0;
 
 function OnCollisionEnter (geraakt : Collision) {
     
     if (geraakt.gameObject.tag == "gold") goldcounter++;
     var goldtext = guiText.text ;
     guiText.text = "Gold: " + goldcounter;
 
 }

there is nothing happening just says the stock GUI text on the screen.

keep in mind that im new to javascript

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by oliver-jones · Sep 25, 2013 at 06:05 PM

Try this:

 function OnCollisionEnter (geraakt : Collision) {
 
     if(geraakt.collider.gameObject.tag == "gold"){
         goldcounter++;
     }
 
     goldText.text = "Gold: " + goldcounter;
 
 }
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 eMs · Sep 26, 2013 at 01:11 PM 0
Share

this doesnt work becouse the script isnt attached to the guitext object. so i think i need to call for the guitext object, thats why i did the line var goldtext : GUIText; or is this more of a job for getcomponent?

here is the whole script. its attached to the player.

 var speed : float = 3.0;
 var rotateSpeed : float = 3.0;
 
 
 
 function Update () {
 
     var controller : CharacterController = GetComponen (CharacterController);
 
     // Rotate around y - axis
     transform.Rotate(0, Input.GetAxis ("$$anonymous$$ouse X") * rotateSpeed, 0);
         
     // $$anonymous$$ove forward / backward
     var forward : Vector3 = transform.TransformDirection(Vector3.forward);
     var right : Vector3 = transform.TransformDirection(Vector3.right);
     var curSpeed : float = speed * Input.GetAxis ("Vertical");
     var curSpeed1 : float = speed * Input.GetAxis ("Horizontal");
     controller.Simple$$anonymous$$ove(forward * curSpeed);
     controller.Simple$$anonymous$$ove(right * curSpeed1);
     
     Screen.showCursor = false;
         
 }
 
 var goldtext : GUIText;
 var goldcounter : int = 0;
 
 function OnCollisionEnter (geraakt : Collision) {
     
     var goldtext = guiText.text;
     if (geraakt.gameObject.tag == "gold");
     goldcounter++;
     
     guiText.text = "Gold: " + goldcounter;
     
 }
 
 @script RequireComponent(CharacterController)
 

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

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Scoring (i'm stuck) 3 Answers

how to keep track of bricks broken 1 Answer

Scoring/Counting how many specific objects are placed on a specific plane. 1 Answer

Collision with cube isn't working when Instantiate clone it 2 Answers

Collision Counter +1 To Counter Only Once When Collided 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