Search Unity

How to generate destroyed game object in unity?

Discussion in 'Scripting' started by huseyinbaba58, Aug 5, 2020.

  1. huseyinbaba58

    huseyinbaba58

    Joined:
    Feb 12, 2020
    Posts:
    146
    I want to that generate destroyed Unity prefabs.How can I ensure it?
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    Are you talking about a "destroyed" version of another object? It's just like any other prefab. Make it look how you want to look, and then Instantiate it when the original object is destroyed.
     
  3. huseyinbaba58

    huseyinbaba58

    Joined:
    Feb 12, 2020
    Posts:
    146
    Actually ,I want to copy destroyed game objects and when game object completed purpose of itself,I want to destroy its.
     
  4. Tecnofire89

    Tecnofire89

    Joined:
    Aug 5, 2020
    Posts:
    7
    You can have like a timer or something like that, I think this is called Living time
     
  5. huseyinbaba58

    huseyinbaba58

    Joined:
    Feb 12, 2020
    Posts:
    146
    Good suggestion .How can I apply to my script?
     
  6. Tecnofire89

    Tecnofire89

    Joined:
    Aug 5, 2020
    Posts:
    7
    First you have to add an Idd or a Float
     
  7. Tecnofire89

    Tecnofire89

    Joined:
    Aug 5, 2020
    Posts:
    7
    Then make the the number of the Idd or Float is the time that you want that this object live
     
  8. Tecnofire89

    Tecnofire89

    Joined:
    Aug 5, 2020
    Posts:
    7
    This step should look like this public float livingTime = 3f;
     
  9. Tecnofire89

    Tecnofire89

    Joined:
    Aug 5, 2020
    Posts:
    7
    And also put this code in your script private float _startingTime;
     
  10. Tecnofire89

    Tecnofire89

    Joined:
    Aug 5, 2020
    Posts:
    7
    And you put this last code
    float _timeSinceStarted = Time.time - _startingTime;
    float _percentageCompleted = _timeSinceStarted / livingTime;
     
  11. Tecnofire89

    Tecnofire89

    Joined:
    Aug 5, 2020
    Posts:
    7
    With that it should work
     
  12. huseyinbaba58

    huseyinbaba58

    Joined:
    Feb 12, 2020
    Posts:
    146
    Thanks for code explaining.Have a nice day.