• 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 hihacker · Feb 05, 2012 at 07:13 PM · score

problem with getting a point system to work

I'm having problems with the code below for some reason I cant get a point system to work in my games. the tag is "tangerine" and what I'm trying to do is have a gui show how many points the player has and I want the object to be destroyed once collided with which works but the points are never displayed please help!


static var currentScore : int = 0;

 // A function specifically for detecting collisions with colliders

 // that have had the Is Trigger flag set in the inspector

 function OnTriggerEnter(collisionInfo : Collider){



     // if the current gameObject of the collider stored in the collisionInfo

     // variable has a tag of "tangerine" 

     if(collisionInfo.gameObject.tag == "tangerine"){



         // Increment the global score variable declared in the by 1

         



         currentScore++;


     



         // Remove this particular battery from the scene (the object whose collider we have hit)

         Destroy(collisionInfo.gameObject);

     }

 }

function OnGUI () {

 GUI.Label (Rect (10, 10, 100, 20), currentScore);

}

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 IMTRIGGERHAPPY9 · Feb 05, 2012 at 09:49 PM

do gameObject.CompareTag(Tangerine") instead of .tag heres the reference http://unity3d.com/support/documentation/ScriptReference/GameObject.CompareTag.html

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 IMTRIGGERHAPPY9 · Feb 05, 2012 at 09:50 PM 0
Share

so it would be

if(collisionInfo.gameObject.CompareTag("tangerine"){ // Do stuff here }

avatar image hihacker · Feb 08, 2012 at 05:23 AM 0
Share

but how do I show The Gui because the on gui I did isn't working

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

6 People are following this question.

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

Related Questions

Trying to get score counter... 2 Answers

Problem with duplicated score! 1 Answer

Problem at add Score+1 When Pass rocks 0 Answers

[SOLVED] Problem with script camera SmoothFollow 1 Answer

Black Screen (Android) Even Newly Made Project 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