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
1
Question by Devlus · Apr 30, 2011 at 03:52 AM · collisionscore

Score keeping script

I'm sorry to post another score keeping script question, but I honestly don't know why my script isn't functioning. I am try to get my GUIText score counter to increase by five every time the the game object bullet(Clone) collides with anythings... very simple, and for some reason that i am not aware of, it doesn't not work, meaning that the score counter stays at 0. Thanks in Advance

    var score : int = 0;
//when a bullet collides with anything, i want to add five to the score.
function OnCollisionEnter(theCollision : Collision) {
    if (theCollision.gameObject.name == "bullet(Clone)"){
    score += 5;
}
}
//manages the guitext that displays the score
function Update() {
    guiText.text = "Score: "+score;
}

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

3 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by sneftel · Apr 30, 2011 at 03:57 AM

I seem to recall that there's a space there... that is, the name should be "bullet (Clone)", not "bullet(Clone)". A considerably more robust way to do that, though, would be to set the bullet prefab's tag to something like "bullet", and then check theCollision.gameObject.tag instead. That's guaranteed not to be renamed.

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 Devlus · May 01, 2011 at 01:52 PM 0
Share

I am sorry to say that this isn't the solution, there isn't a space

avatar image
1

Answer by GlennHeckman · Apr 30, 2011 at 05:31 AM

If the spacing in the name wasn't the issue, try making your score variable private so that the properties panel doesn't retain control over the value.

private var score:int = 0;

Or if the score variable must remain public for use in other scripts, you can put the @HideInInspector on the line above your variable declaration to keep it hidden.

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 sneftel · Apr 30, 2011 at 02:53 PM 0
Share

The inspector doesn't "retain control" over component properties at runtime. It sets them to their initial values when the level is loaded, and can be used in the editor to view and modify them at runtime, but it doesn't prevent scripts from changing them, and it doesn't revert those changes.

avatar image
-1

Answer by extrime · Feb 10, 2013 at 07:36 PM

I have that problem to.If you find how to fix it pls tell me.

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

2 People are following this question.

avatar image avatar image

Related Questions

Javascript score problems whilst referencing scripts. 2 Answers

support not detected collision and Leasehold 0 Answers

Disable a script on collision 2 Answers

How to add the right amount of points when my player destroys a gameobject? 0 Answers

Do a collider only with certain taged objects 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