• 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 Pure Phase · May 03, 2010 at 01:43 PM · destroycolliderscount

Why does my counter keep going up after pickup is destroyed?

Hi,

I have this code which adds 1 to the OBJECTNUMBER every time someone picks up an object. Except sometimes, it adds 2 or 3 to OBJECTNUMBER. I'm not sure why this is as the object is destroyed as soon as my player comes into contact with it. I've followed a tutorial and I've got the same code as that did and it seemed to work fine on the video. Any suggestions?

else if(hit.gameObject.tag == "Helmet1") {

     soundObj.audio.PlayOneShot(pickup);
     Destroy(hit.gameObject, 0.01);
     OBJECTNUMBER += 1;
     g_Helmet.animation.Play("g_Inv_HelmetAnimation2");
     print("you now have" + OBJECTNUMBER);

 }

Thanks

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

Answer by duck · May 03, 2010 at 01:50 PM

You have a delay value specified in your Destroy function, of 0.01. This means that your object will be destroyed 0.01 seconds after the object is collected. If your game is running at a fast enough framerate, this can be enough time for another frame or two to elapse before the object is finally destroyed.

You should remove that value completely, so the line looks like this:

Destroy(hit.gameObject);
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 Pure Phase · May 03, 2010 at 02:05 PM 0
Share

Thankyou, can't believe I didn't spot this. That'll $$anonymous$$ch me for following the tutorials to the letter :)

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

onCollision Destroy 1 Answer

4 blocks destroyed - gravity true 2 Answers

count the number on enemyes entrering into a trigger 1 Answer

Destroying objects with the same name that are touching eachother. 1 Answer

Script for counting number of Turrets and when I destroy all of them I go to the YOU WIN seine 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges