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 twoface262 · Jun 28, 2011 at 07:41 PM · timerbulletshootdelete

How to delete things with a timer

I'm trying to make a timer to where after a certain amount of time the bullet gets deleted that way there arnt a billion bullets just going and using up cpu and ram

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

5 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Borgo · Jun 28, 2011 at 07:59 PM

You can create a simple script that you can attach to wherever object you want:

 var secondsToDestroy: int;
 function Awake(){
     Destroy(this, secondsToDestroy);
 }

I did'n test yet. Attach this script to any object and set the "destroyOnTime", this is the time that the object will survive XD

Comment
Add comment · Show 9 · 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 twoface262 · Jun 28, 2011 at 08:01 PM 0
Share

gives me this error - Assets/destroybullet.js(7,16): BCE0023: No appropriate version of 'UnityEngine.Object.Destroy' for the argument list '()' was found.

avatar image Borgo · Jun 28, 2011 at 08:04 PM 0
Share

sorry, I have forget this: Destroy(this);

avatar image twoface262 · Jun 28, 2011 at 08:04 PM 0
Share

Also, I'm starting to have a change in $$anonymous$$d how would I do raycasting for bullets?

avatar image DaveA · Jun 28, 2011 at 08:04 PM 0
Share

You didn't look at that link I posted. Go look. Destroy takes some arguments.

avatar image Borgo · Jun 28, 2011 at 08:08 PM 0
Share

DaveA is right, the Destroy function supports a Time argument... Destroy(object, seconds);

Show more comments
avatar image
2

Answer by DaveA · Jun 28, 2011 at 07:47 PM

Bullets! So many questions, so few people using Raycasting instead!

Anyway, use Object.Destroy when you are done with them. Example here: http://unity3d.com/support/documentation/ScriptReference/Object.Destroy.html

Comment
Add comment · Show 2 · 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 twoface262 · Jun 28, 2011 at 07:53 PM 0
Share

How would I destroy it after a certain amount of time?

avatar image DaveA · Jun 28, 2011 at 08:05 PM 0
Share

See the example on that page: // $$anonymous$$ills the game object in 5 seconds after loading the object Destroy (gameObject, 5);

avatar image
0

Answer by FPSNOOB:D · Nov 03, 2012 at 08:29 AM

 function Update ()
 {
 Destroy (gameObject, 5) //5 is how many seconds you want before the object deletes itself
 }
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
0

Answer by Soareverix · Jun 23, 2018 at 11:52 PM

Use this function, just make a C# script. --- using System.Collections; using System.Collections.Generic; using UnityEngine;

public class ObjectDestruction : MonoBehaviour {

 public GameObject item;


 // Use this for initialization
     void Start () {
     
 }
 
 // Update is called once per frame
 void Update ()
 {
     NewMethod();

 }

 private void NewMethod()
 {
     Destroy(item, 15); //5 is how many seconds you want before the object deletes itself
 }

}


This is literally all you have to do, just input the GameObject you want to destroy into the variable in Unity. Enjoy!,Create a C# script and literally copy and paste this into into it. Afterwards, select the GameObject you want to destroy.


using System.Collections; using System.Collections.Generic; using UnityEngine;

public class ObjectDestruction : MonoBehaviour {

 public GameObject item;


 // Use this for initialization
     void Start () {
     
 }
 
 // Update is called once per frame
 void Update ()
 {
     NewMethod();

 }

 private void NewMethod()
 {
     Destroy(item, 15); //you have 15 seconds before the objects deletes itself
 }

}


This is the easiest way :)

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
0

Answer by gamerkaa · Jun 24, 2018 at 04:02 PM

When u need to delete a object say in 4 seconds, use a coroutine. Yield for 4 seconds then delete the object.

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

8 People are following this question.

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

Related Questions

Firing bullets deleats player not bullet 1 Answer

Trying to deleate bullets once they leave the screen 1 Answer

Need help with randomize attack time. Please help! 2 Answers

Bullet Effect 2 Answers

Problem With Bullet Prefab 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