|
hi i have a problem here i want to destroy an object that comes out of an spawn point im trying to do 3 different spawn points and so they can throw different objects from them that will hit the player the spawn is fine and everything but as i said i cant make them dissapear if i use destroy(gameobject) it will destroy the spawner and well that is not good. in any case heres my code
to make it easier what i want to do is destroy the things that come out of the spawner after a certain time and thats about all thank you (oh yeah this code is inside my spawners and i want to use Transform for this tyvm) if you cant understand what im trying to do tell me and i will try to explain >.<
(comments are locked)
|
|
Okay im not sure exactly what your after but it sounds like you could benefit from a little bit more information. In this is example lets say we have a game with a cannon that fires a cannonball every 5 seconds, the player does not control this object or its actions. In your scene First create a cylinder gameobject. This will be our cannon.Next create a new javascript. Name it something like "CannonScript". In the project window drag the CannonScript onto the Cannon in the hierarchy window. Next (with the CannonScript selected) go to "edit" in the inspector window this will open your script editor of choice. In the script paste this code. Make sure you read and understand it!
Next you need a cannonball so create a sphere in the scene,call it Cannonball, and with it highlighted in the hierarchy give it a rigidbody (Component ~> Physics ~> Rigidbody) Now create a new prefab in the project window and drag the Cannonball from the hierarchy window onto the prefab in the project window. With the Cannon selected, drag the newly made Cannonball prefab into the approriate slot under the Cannon's CannonScript component. Then create a new javascript to be attached to the Cannonball. This script is for destroying the Cannonball whenever it collides with something, for example your player or the ground.
Press play and you should now see the Cannon firing the Cannonball(Clone) in whatever direction the Y axis is pointing. If not check the debug log is there. If the debug log is not there check for error messages. If the debug log is there then adjust the Cannon's variables in the inspector while the game is running (during runtime) until you can see it. Once you can see the Cannonballs then you can start playing around with the different elements like shot speed and the mass and gravity on the rigidbody. You can also create 3 prefabs of the Cannon, the same way you made a prefab of the cannonball, and put a different type of cannonball and different shot settings on each cannon prefab. yeah i think im doing that but what i dont get is if you are telling the object to get destroyed i mean the cannonball then how can you still keep on producing them if they are not anymore on the scene because i need them to get destroyed on time and not on collision
Feb 27 '11 at 05:22 PM
Makenshi
oh wait so u can make the prefabs like that ok ty this solved the question tyvm
Feb 27 '11 at 05:29 PM
Makenshi
put the script "tool55" suggested on your cannonball prefab and that should give you the effect you want
Feb 27 '11 at 08:07 PM
AngryOldMan
(comments are locked)
|
|
put the destory object script on the prefab of what ever it is your instantiating. So something like
WARNING this is just sample code you will have to assign your own variables and such. this wont work because i dont know how to make an object from something that doesnt exists and that will delete the parent object and i wont be able to make copies of something that doesnt exists :S but ty
Feb 27 '11 at 12:15 AM
Makenshi
This should work but you don't need yield WaitForSeconds(). The Destroy function has a timer built in. Couldn't be easier. See below.
Feb 27 '11 at 03:10 AM
tool55
(comments are locked)
|
|
Your spawned objects are prefabs. Just attach the script to the prefab, then every instance will have the script attached. yeah i tried that but as i said in the top comment when i destroy the object i can no longer instantiate more of them since the object no longer exists there
Feb 27 '11 at 05:23 PM
Makenshi
(comments are locked)
|
