|
I am making a game of Battleship, and I came across a problem, I created a script so that the ship can fire projectiles, but it happens that whenever a projectile shooting, I create a clone of the prefab I'm shooting. So I created a script so that after some time he was self distruted. but I'm having a little problem: he destroy the point where the projectile firing, not the "bullet"! anyone have any idea how I can only destroy the prefab I'm shooting? this is my scpript: var lifetime = 1.0; function Awake () { Destroy(gameObject.Find("bufabola(Clone)").lifetime); }
(comments are locked)
|
|
Hi, Firstly I would make a small script that is to be added to the original prefab. Then you can call "this" like so: This should work so long as the script is attached to the prefab. One caveat:
May 10 '12 at 06:15 PM
rutter
Oh yes, Forgot about that!
May 10 '12 at 06:22 PM
David C
well, now it destructs the entire script, and I just want it to destroy the clone of the bullet i'm making when i'm shooting... this is my cenario, i have a bullet prefab called "bufabola", and i have put it in a sphere that is my point where the bullets are spwan, so i made a script to shot my bullets, and so far no problem, but now when i shoot unity creates a clone of the prefab that i'm shooting, so my hierarchy gains a lot of clones that can slow my game... Do not now what to do.. any sugestion?
May 11 '12 at 02:09 PM
ruifernandes01
No, no, you put that script on the bullet!
May 11 '12 at 02:11 PM
syclamoth
Making clones of the prefab is how Unity works, if its a fast moving bullet you can do away with the prefab and use raycasting and particles to fake a bullet object
May 11 '12 at 03:02 PM
David C
(comments are locked)
|
|
instantiating and destroying objects is very heavy, you should try to SetRecusivelyFalse your object that you want to delete, and then push them in a array to reuse them later.
(comments are locked)
|
|
tanks guyz! it is working! :D next stept create an explosion when colliding with the other boats and then sink slowly. wish me luck! and again tanks a lot! :D
(comments are locked)
|
