Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Space Shooter explosion clones not disappearing

Discussion in 'Scripting' started by Wolfgabe, Sep 8, 2016.

  1. Wolfgabe

    Wolfgabe

    Joined:
    Sep 4, 2016
    Posts:
    131
    I followed the script exactly yet when I test the explosion clones still remain after the asteroids are destroyed. I tried changing lifetime to 1 and even adjusting the script but nothing works here is the code I have

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class DestroyByTime : MonoBehaviour
    5. {
    6.     public float lifetime;
    7.  
    8.     void start()
    9.     {
    10.         Destroy(gameObject,  lifetime);
    11.     }
    12. }
    13.  
    14.  
    15.  
     
  2. Vedrit

    Vedrit

    Joined:
    Feb 8, 2013
    Posts:
    514
    Putting it in Update shouldn't matter if the DestroyByTime script is attached to each individual explosion clone or the parent. Destroy only needs to be run once.
     
  3. Wolfgabe

    Wolfgabe

    Joined:
    Sep 4, 2016
    Posts:
    131
    I did what the tutorial said an attached to each individual explosion I am guessing that's not necessary
     
  4. Gunging

    Gunging

    Joined:
    Sep 6, 2016
    Posts:
    139
    Well, I dont know why it doesnt work, but you can try makin a timer, like this:

    Code (CSharp):
    1.  
    2.     //A float value
    3.     private float Timer;
    4.     //Lifetime :B
    5.     public float lifetime;
    6.  
    7.     void Start()
    8.     {   //Set A value to the current time plus the lifetime
    9.         //If the time is 0, then it will be 0.0 + 1
    10.         Timer = Time.time + lifetime;
    11.     }
    12.  
    13.     void Update()
    14.     {       //As void Start is executed before update, then
    15.             //Time.time will be like 0.01 and Timer will be 1
    16.  
    17.         //When Time.time reaches 1.001 this will be executed
    18.         if (Time.time > Timer)
    19.         {
    20.             //Destroy :P
    21.             Destroy(gameObject);
    22.         }
    23.     }
     
  5. Gunging

    Gunging

    Joined:
    Sep 6, 2016
    Posts:
    139
    I just tested it and works, (lifetime is the time it will live in seconds)
     
  6. Wolfgabe

    Wolfgabe

    Joined:
    Sep 4, 2016
    Posts:
    131
    just tried it myself and it worked for me too but now the explosions are not showing

    Nvm I redid the original code now it works fine
     
    Last edited: Sep 8, 2016
  7. Rhu

    Rhu

    Joined:
    Dec 29, 2016
    Posts:
    1
    The issue for anyone else who runs into the same is the 'start' function should have a capital 'S'.
     
    Ryiah likes this.