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 ArcherDev · Mar 12, 2014 at 01:05 AM · javascriptcountersimultaneous

My orb and gem counter are counting simultaneously?

I've been working on a platformer where the player collects orbs and gems. They are to be collected as separate objects in the game. However, when the player collects one, whether it be a gem or an orb, they count simultaneously, at least on my GUI. Here are the scripts I'm using (Javascript):

GUI

 #pragma strict
 
 var gemIcon : Texture2D;
 
 var orbIcon : Texture2D;
 
 var customSkin : GUISkin;
 
 function Start () {
 
 }
 
 function Update () {
 
 }
 
 function OnGUI()
 {
     GUI.skin = customSkin;
     
     var gemNumberName = GemCounter.gemCounter;
     var gemName = gemNumberName.ToString();
     
     var orbNumberName = OrbCounter.orbCounter;
     var orbName = orbNumberName.ToString();
     
     GUI.Box(Rect(10, 10, 90, 50), gemIcon);
     GUI.Box(Rect(10, 70, 90, 50), orbIcon);
     GUI.Label(Rect(10, 10, 100, 50), gemName);
     GUI.Label(Rect(10, 70, 90, 50), orbName);
     
 }

Orb trigger

 #pragma strict
 
 var Player : Transform;
 
 function Start () {
 
 }
 
 function Update () {
 
 }
 
 function OnTriggerEnter()
 {
         GameObject.FindWithTag("Orb");
         Destroy(gameObject);
 }

Orb Counter

 #pragma strict
 
 static var orbCounter = 0;
 
 function Start () {
 
 }
 
 function Update () {
 
 }
 
 function OnTriggerEnter()
 {
         orbCounter += 1;
 }


Gem Trigger

 #pragma strict
 
 var Player : Transform;
 
 function Start () {
 
 }
 
 function Update () {
 
 }
 
 function OnTriggerEnter()
 {
         GameObject.FindWithTag("Gem");
         Destroy(gameObject);
 }


Gem Counter

 #pragma strict
 
 static var gemCounter = 0;
 
 function Start () {
 
 }
 
 function Update () {
 
 }
 
 function OnTriggerEnter()
 {
         gemCounter += 1;
 }
 



If you can help me figure this out it would be highly appreciated.

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
Best Answer

Answer by getyour411 · Mar 12, 2014 at 01:27 AM

The empty methods in your code should be removed - since you aren't doing anything in Start or Update in a few of those, get rid of them.

Your issue here is you what these scripts are attached to. You didn't say, but it's likely its the player so your OnTriggerEnter events are firing for anything (since the GameObject.Find code is pointless/does nothing).

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 ArcherDev · Mar 12, 2014 at 01:36 AM 0
Share

The GUI is attached to an empty game object, the two counters are attached to the player. The triggers are attached to the gem/orb. Also, what do you mean by thingie.tag? lol

avatar image getyour411 · Mar 12, 2014 at 01:39 AM 0
Share

Please review http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$onoBehaviour.OnTriggerEnter.html

http://www.unity3dstudent.com/2010/07/beginner-b13-trigger-collision-detection/

avatar image ArcherDev · Mar 12, 2014 at 01:46 AM 0
Share

That doesn't really help me at all.

avatar image getyour411 · Mar 12, 2014 at 01:59 AM 0
Share

TBH: If that second link doesn't help you, I'm not sure what will.

OrbCounter

 function OnTriggerEnter(other :Collider)
 {
 if(other.name == "Orb")
 orbCounter ++;
 }

I work in C# so you might need a JS fix on syntax.

avatar image ArcherDev · Mar 12, 2014 at 02:08 AM 0
Share

The second link actually did help. I was confused cus you said thingie lol. I figured out what you meant, that it was the collider thing lol. Anyway I prefer C# but I followed a tutorial on coin collecting on youtube and it happened to be js. And since it didn't include EVERYTHING that I'm trying to do, I had to kind of wing it. But thanks, saved me a lot of frustration!

Show more comments

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

20 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 avatar image avatar image avatar image

Related Questions

pickup counter and timer help 0 Answers

ammo counter, counts wrong 1 Answer

Setting Scroll View Width GUILayout 1 Answer

GUI Counter Based on Animation or RaycastHit 0 Answers

How to display counter 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