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 /
avatar image
0
Question by cgartist4jc · Jun 23, 2011 at 02:35 PM · multipleclonedeletebulletsclones

Deleting Bullets after a few seconds

Hi

I'm making an FPS multiplayer game. I know that alot of objects will slow down the game, and since there will be alot of shooting, I thought that it would be good to delete the bullets after about four seconds. I didn't want to delete them after collision because I thought they might just go through the floor or other objects...

My question is how do I delete each cloned bullet four seconds after it was shot? Can you send me in a direction (a tutorial or article) or maybe post the rough out line of a script? Thanks for all the help!!!

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

2 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by Milad · Jun 23, 2011 at 03:08 PM

Just do it:

 void Start()
 {
   Destroy(gameObject,DeathTime);
 }

OR

 void Start()
 {
   Invoke("Kill",DeathTime); 
 }
 void Kill()
 {
   Destroy(gameObject);
 }

It is easy!

And the best is that do not Instantiate the bullet with Mesh rendere On.make Mesh rendere Off to reduse the Draw Call and use a particle for bullet trace like Bootcamp.

Regards.

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

Answer by Jason B · Jun 23, 2011 at 02:44 PM

Something like this is very simple, so if you intend to make a full-blown multiplayer first-person shooter, you have some serious work ahead of you.

I only say this to help, because beginners often take on projects that are far beyond the scope of their abilities right out of the gate, then they feel hopeless and quit.

As to the question at hand, you want a variable to hold some sort of timer.

 public float timer;

Then in your Update function, you'll want something to increment the timer.

 timer += 1.0F * Time.deltaTime;

(1 gets added to timer per second)

Then you'll need a conditional check to destroy the bullet.

 if (timer >= 4)
 {
 GameObject.Destroy(gameObject);
 }
Comment
Add comment · Show 3 · 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 flaviusxvii · Jun 23, 2011 at 02:49 PM 0
Share

I do the opposite. I have a script called Perishable that I use for lots of things. I set lifeInSeconds to whatever and decrement it by Time.deltaTime. When there is no more life I Destroy.

$$anonymous$$ato $$anonymous$$ahto

avatar image Jason B · Jun 23, 2011 at 02:53 PM 0
Share

Yep. Either way works. Ideally I would also have the time that it takes for something to be destroyed a public variable so that it can be changed inside the prefabs themselves, but this way may be simpler for someone learning the basics (not sure, just a guess).

avatar image Jip1912 · Apr 13, 2016 at 03:11 PM 0
Share

Look, this is the simple and useful answer I was searching for.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Deleting Multiple Bullets after Set Time 1 Answer

Deleted sub-object causing lag 1 Answer

Why are multiple objects being instantiated when I use clone, but not regular instantiation? 1 Answer

Gun script not working in 5.6 0 Answers

shooting multiple projectiles at enemies 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