|
i am no sure why but whilst playing my game after shooting a certain amount of objects the game crashes any help will be appreciated. here is my shoot code.
(comments are locked)
|
|
Unity can only have so much information at the same time, like everything with computer. You should destroy those bullets after some time, or even better, recycle them. Instantiate only around 20 and shoot them one after the other. Once you shot the 20th, you start again with the first. Instantiate can be expensive. how would i go about destroying them? obviously a set time limit till destruction.
May 14 '12 at 02:26 PM
ryand444
Have a look at this guys forum thread about an Object pool for an idea of how to go about recycling them instead of destroying them like @Berenger said.
May 14 '12 at 02:52 PM
Lo0NuhtiK
(comments are locked)
|
|
To destroy the bullet after a certain amount of time, the easiest way to do that would be to have a variable in your bullet script, call it "lifetime" or something easy like that. Then make a new function called Awake() and in there, just put Destroy(gameObject,lifetime); . It'll look like this: *Don't forget this does not go in the update function because it is a whole new function itself. I forgot to show it, but declare a new variable and call it lifetime or something and set it equal to how long you want each bullet to last. Example: var LifeTime: int = 2;
May 14 '12 at 02:33 PM
timo0060
thank you very much your help is appreciated.
May 14 '12 at 02:36 PM
ryand444
is there anyway to recycle it as it now crashes the game after the set amount of time due to it is trying to accesses the script but the objects have been destroyed.
May 14 '12 at 03:35 PM
ryand444
I'm not sure how to do that unfortunately. I destroy my bullet prefabs and my game never seems to crash. Do you have a bullet script and a player script or is it all on one script?
May 14 '12 at 05:45 PM
timo0060
its a separate script
May 24 '12 at 01:14 PM
ryand444
(comments are locked)
|

