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 tomeromero · Nov 22, 2010 at 03:53 PM · physicscollidergraphicsdestroy

Collect some coins for Points

Hi... I have a terain and the 3rd Person Controller in my scene. There is no problem on them i can press play and walk,run and jumb on my terain.

I want to make a Coin system so when my player collect some coins(every coin is 5 points) to be able to show on the top right of my screen "Score:points here".

So far i have a Sphere as Coin with the Sphere Collider and the collider is set to Trigger. The name of my Sphere in Hierarchy is Coin. I have this script

var score = 0;

function OnTriggerEnter( other : Collider ) { if (other.tag == "Coin") { score += 5; Destroy(other.gameObject); } }

Finally i have this script attached on my 3rd Person Controller. When i press play and go to my coin to catch it and then destroy it none of this things is happening. Also i don't know if i caught the Coin because I have no Script to show me how many points i have. Please a little help here. I thing its easy to fix this. Thank you.

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

Answer by Jesse Anders · Nov 22, 2010 at 04:01 PM

You said the name of the 'coin' object is 'Coin'. Is it also tagged as 'Coin'? (Because you're checking the tag, not the name.)

If that's not the problem, try using the debugger (if you're using Unity 3), or add some debug output to help determine what's actually going on. Specifically, I would add some calls to Debug.Log() to your OnTriggerEnter() function, e.g.:

function OnTriggerEnter( other : Collider ) {
    Debug.Log("OnTriggerEnter() was called");
    if (other.tag == "Coin") {
        Debug.Log("Other object is a coin");
        score += 5;
        Debug.Log("Score is now " + score);
        Destroy(other.gameObject);
    }
}
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 tomeromero · Nov 22, 2010 at 04:20 PM 0
Share

well i got only the "OnTriggerEnter() was called" so its not tagged. Can you explain me how to tag it as Coin? Please?

avatar image tomeromero · Nov 22, 2010 at 04:27 PM 0
Share

ok thank you i tagged it and now the gameobject is destoyed when i touch it and i get "Score is now 5"

thank you very match.

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

1 Person is following this question.

avatar image

Related Questions

Creating a SIMPLE car. 1 Answer

Manual collision check 2 Answers

Same reaction with different number of objects colliding 2 Answers

How to destroy Terrain grass using colliders? 1 Answer

how to destroy an object permanently ? 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