• 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 Didymos · Jan 13, 2011 at 04:41 AM · javascriptprojectiledisable

How do I make a projectile disappear seconds after it is fired? The projectile stays within the game forever. How do I disable it, 3 seconds after it has been fired?

var bullitPrefab:Transform;

function Update ()

{

if(Input.GetKeyDown("e"))

 {

     var bullit = Instantiate(bullitPrefab, GameObject.Find("SummonEscape_Spawn").transform.position, Quaternion.identity);



     bullit.rigidbody.AddForce(transform.forward * 100);



 }

}

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 Justin Warner · Jan 13, 2011 at 04:55 AM

function Update() {

 if(Input.GetKeyDown("e"))
 {
 spawnBullet(grenade);
 }

} var grenade; spawnBullet() { Instantiate(grenade, GameObject.Find("SummonEscape_Spawn").transform.position, Quaternion.identity);

 grenade.rigidbody.AddForce(transform.forward*100);
 yield WaitForSeconds(3);
 Destroy(grenade);

}

Not tested, but should work.

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 Didymos · Jan 13, 2011 at 04:59 AM 0
Share

Does it spawn an actual gernade or is that part of the coding which is used in the script?

avatar image Didymos · Jan 13, 2011 at 05:00 AM 0
Share

Thanks for the help. I think this is going to be best answer.

avatar image Didymos · Jan 13, 2011 at 05:00 AM 0
Share

Wait I read over the script and it makes so much sense to me. Thanks for the help. I will try out the script.

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

Setting Scroll View Width GUILayout 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Projectile Firing From Floor, I Need Some Help 1 Answer

projectile issue please help me its annoying mme badly 1 Answer

Object reference not set to an instance of an object 1 Answer

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