Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
This question was closed Jan 22, 2019 at 02:55 AM by Deathhound for the following reason:

stupid question

avatar image
0
Question by Deathhound · Sep 02, 2013 at 04:08 PM · instantiatedestroybullet

Destroy (Clone)

I'm creating a bullet script and the only thing that I cant figure out is destroying multiple cloned objects. Ive gotten as far as destroying one of them but after more are spawned the script cannot catch up.

bullet.js

 var bullet : Rigidbody;
 var speed : float = 10.0f;
 var muzzlePoint : Transform;
  
 function Update() {
     if(Input.GetButtonDown("Fire1")) {
         var instance : Rigidbody = Instantiate(bullet, muzzlePoint.position, muzzlePoint.rotation);
         instance.velocity = muzzlePoint.forward * speed;
         Destroy(GameObject.Find("Bullet(Clone)"), 5);
     }
 }

alt text

1.jpg (512.2 kB)
Comment
Add comment · Show 1
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 prashantkachhwaha · Nov 21, 2020 at 07:08 AM 0
Share

ParticleSystem $$anonymous$$yPS = Instantiate(YourParticle, position, Quaternion.identity); Destroy($$anonymous$$yPS.gameObject, 1f);

1 Reply

  • Sort: 
avatar image
4
Best Answer

Answer by bubzy · Sep 02, 2013 at 04:18 PM

 GameObject[] killEmAll;
 killEmAll = GameObject.FindObjectsWithTag("Bullet");
 for(int i = 0; i < killEmAll.Length; i++)
 {
 Destroy(killEmAll[i].gameObject);
 }

i think (c#)

ORRRR you could have

 float bulletLife = 5.0f;
 Destroy(gameObject,bulletLife); //pretty sure this will destroy it after 5 seconds.

attach this to the bullet.

Comment
Add comment · Show 7 · 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 Deathhound · Sep 02, 2013 at 04:25 PM 0
Share

hey, the second script worked! thanks so much!

but there's a problem; it deletes the original bullet also so when I shoot again, there is nothing to clone or spawn. is there a way that I can only delete or shoot the clones?

avatar image bubzy · Sep 02, 2013 at 04:30 PM 0
Share

you would have to use prefabs.

avatar image Deathhound · Sep 02, 2013 at 04:39 PM 0
Share

I did it without using prefabs using this code

 function Update() {
     if(gameObject.name == "Bullet(Clone)"){
         Destroy(gameObject, 5);
     }
 }
avatar image bubzy · Sep 02, 2013 at 05:14 PM 0
Share

sure, that will work. better to use prefabs though :)

avatar image Bunny83 · Sep 02, 2013 at 05:34 PM 0
Share

Actually all he needs is:

 Destroy(instance.gameObject, 5);

This will autodestruct the bullet after 5 seconds. Using any "Find" method where is just a waste of cpu power.

Show more comments

Follow this Question

Answers Answers and Comments

20 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

Related Questions

Issues with destroying a game object 2 Answers

Cannot destroy instantiated objects 2 Answers

Bullet not dissapearing after time ? 3 Answers

when prefabs are spawned I want to touch them to destroy. help? 0 Answers

Shoot an object and have it move based on rotation 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