Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Problem with instantiate :L

(FYI: im following Brackeys tutorial on how to make a 2d shooting Game and i am using Instantiate)

I am planning to make an enormous scene, and I ran into a problem wherein, whenever the player shoots too many "raycasts" the impact effect animation is saved in the scene/hierarchy which can cause the game to lose too many frames. Can you help me such that the animation of the 'impact' gets removed after some time. check the Image for more info:

Best Answer

  • NeodecadenteNeodecadente Member
    Accepted Answer

    So I think you're missing some guidelines here. Remember to post your code and Google next time.

    You need to assign the instance of your object to a variable and then destroy the clone using that variable with the Destroy() function. Destroy() can receive 2 parameters: the first of type GameObject, which is the GameObject to be destroyed. And a second optional one, type float that delays the destroy for that amount of seconds. See the code below.

    GameObject clone = (GameObject)Instantiate(impactEffect, hitInfo.point, Quaternion.identity);
    Destroy (clone, 1.0f);
    

Answers

  • JoyfullJoyfull Member

    Thanks so much! But I already found a workaround, what I did was i added a destroyer script to the effect that got rid of it after some time. I forgot i had posted this in this forums lol. But thanks anyways :)

Sign In or Register to comment.