Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
-1
Question by Zitoox · Oct 25, 2016 at 03:41 PM · destroybullet

Deleting a bullet

Hi! I have a machine gun in my game that have a FireRate of 0.1 (waits 100 milliseconds before shooting), and it shoots bullets with the speed of 100 (i guess Kmph).

My bullets are PLANES and they have rigidbody AND colliders, and i am using a script to delete them at any cost, here it is:

 #pragma strict
 
 var Coll = false;      //Ignore this var, i don't even know why i made this, i am going to delete it soon...
 function update()
 {
     yield WaitForSeconds (10);
     Destroy (gameObject);
 }
 
 
 function OnCollisionEnter(collision: Collision) {
     if (Coll == true) {
         Destroy (gameObject);
     }
 }
 
     function OnCollisionExit(collision: Collision) {
         Coll = true;
     }
     
 
      

Sorry for the poor explanation, i sincerely don't know how to explain this properly. As you see in my script, it is supposed to make my bullets be destroyed when they touch ANY collider, and even if they don't, after 10 seconds they were supposed to be destroyed. The problem is that the bullets are ignoring the script. The bullets aren't being destroyed after 10 seconds, and some of them still continue existing even after hitting a collider. I have set the bullet prefab's collision detection to continuous dynamic and STILL it doesn't do anything. Can someone help me here? What am i missing?

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

Answer by JincSoft · Oct 25, 2016 at 06:36 PM

 #pragma strict
  
 function Start()
 {
     Destroy (gameObject, 10f);
 }
 
  function Update()
  {
          
  }
  
  function OnCollisionEnter(collision: Collision) {
          Destroy (gameObject);
  }

The code currently requires the bullet to collide with something, exit the collision bounds, then collide with something else before it would be destroyed. The Update function needs a capital letter (Update() not update()) and you can move all that code to the Start() function since it only needs to be called once.

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 Zitoox · Oct 25, 2016 at 09:53 PM -1
Share

Nice! I didn't even noticed that i typed u ins$$anonymous$$d of U. I expected Unity to give me some error or something if it was wrong. I deleted and rewrited the script so fast that i didn't noticed the error. Anyway, thanks!

avatar image
1

Answer by hexagonius · Oct 25, 2016 at 03:49 PM

Update, not update

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 ScaniX · Oct 25, 2016 at 04:19 PM 0
Share

Correct. In addition: Your code will only destroy the bullet on its second collision as it is only deleted when Coll is true which it becomes when exiting a collision.

avatar image
0

Answer by JoshDangIt · Oct 25, 2016 at 04:25 PM

Don't use Update(), put this in Start()

 Destroy(gameObject, 10f); //destroy after 10 secs
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

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

Related Questions

Bullet Destroy 1 Answer

The bullet never destroyed!!! 2 Answers

Firing bullets ( Tnx for the help ) 1 Answer

Destroying Bullet (Impact Effect) 1 Answer

MY effect dont destroy 0 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