#Projectiles is not dissapearing
1 messages · Page 1 of 1 (latest)
Google how to detect collisions in Unity.
Just add Destroy(gameobject) in the function responsible for the collision with the wall or with someone
so i need to write this for ever ssingle 3d object and etity?
No.
You need to write one single script that reacts to collisions and destroys the object it is attached to.
Then you attach that script to your projectiles.
Or add this code in the script that is attach to the projectile, in the script now eeh, add the code lastly in the function (OnTriggerEnter or OnCollisionEnter) that is responsible for the collision with the walls or ennemies
do i add the script into the "projectile model" or the enemy
i made a script looking like this
private void OnCollisionEnter(Collision collision);
{
Destroy(collision.gameObject);
}
which gameobject do i add the script to
Do yourself a favour and think about this for a moment.
collision is the object that was collided with (ergo not the object that the script is attached to).
Taking it a step further, this means that whatever object you attach the script to, will indiscriminatorily destroy everything it collides with.
I do not think that this is what you want, necessarily.
yea
cos when i use this script and put it in the projectile which is a 3d model
it destroyed everything
wait im braindead
If you want to destroy the projectile when it touches something, then in the script that is attach to the projectile model simply type Destroy(gameObject) in the OnCollisionEnter function
Just destroy it on touch
CollisionOnEnter( Collision other) {
Destroy( gameObject );
}
do i put the script in the projectile model because when i do it destroy anything it touches not the projectile
Please @paper osprey, read the Unity documentation on the OnCollisionEnter message and think about how to implement it with the information given there.
"How to destroy objects on collision" is an incredibly simple problem, one that several tutorials (and likely also StackOverflow threads) would have talked about.
I certainly do not mean to discourage you. But programming is about problem solving. You need to be able to look things like that up for yourself. Or at least be able to figure out how to use something - more so after several people have pretty much given you the code you need, and somewhat explained what to do with it.
sorry
Ok i will start back
Destroy(collision.gameObject) This gameobject having this code can destroy other gameobject during collision but it will not destroy the gameobject having this code.
Destroy(gameObject) The gameobject having this code will be destroy during collision but will not destroy the other gameobject on collision
Understood now ?
i see