Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bomb

Discussion in 'Scripting' started by MetroidHunter, Jun 14, 2007.

  1. MetroidHunter

    MetroidHunter

    Joined:
    May 22, 2007
    Posts:
    213
    I was working on a bomb script to make the game object detonate after set time. I't didn't work! Can someone help.
     
  2. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    Here, try this:

    Code (csharp):
    1. var explosion : GameObject;
    2. var life = 5.0;
    3.  
    4. function Start () {
    5.      Invoke ("Kill", life);
    6. }
    7.  
    8. function Kill () {
    9.      var pos = transform.position;
    10.      var rot = transform.rotation;
    11.      if (explosion)
    12.          Instantiate (explosion, pos, rot);
    13.      Destroy (gameObject);
    14. }
     
  3. thylaxene

    thylaxene

    Joined:
    Oct 10, 2005
    Posts:
    716
    jeez got to be quick around here! :wink:

    Here is a package of my example. Which is basically exactly the same as the code supplied above. Just nice for future people with similar requests to have a working example. I know I appreciated it when I was starting out.

    Cheers.
     

    Attached Files:

  4. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    Ya, you're right. I know exactly how you feel. :)