|
Hi ! All i want to do is when the function OnDestroy is called i want to know if the object that is colliding with it has the same tag, but if i do like this: function OnDestroy () {
} it's totally wrong right ? HELP ?
(comments are locked)
|
|
OnDestroy doesn't just happen, it is called after you call Object.Destroy. (Or when the scene is unloaded.) Assuming you call Object.Destroy from your OnCollisionEnter, either check the tags then, or save the Collision in a class variable so you'll have it during OnDestroy. check bellow please
Apr 29 '11 at 08:18 PM
Lumart
(comments are locked)
|
Once again, haven't tested this, but using a boolean to test for a mouse click may be the simplest way to go. check bellow please
Apr 29 '11 at 08:18 PM
Lumart
its better thanks !! but still doesnt work because if 2 balls collide and then they separate themselves if i click in one of them, when they get together again they destroy themselves.. i've spent the whole night with it... going to sleep now :D I'll try again later Thanks Anyway ;)
Apr 30 '11 at 10:23 AM
Lumart
Guess I'm still not clear on what you're trying to achieve. I thought you wanted balls with the same tag to destroy themselves on collision.
May 01 '11 at 07:04 AM
tool55
(comments are locked)
|
|
let me make myself clear: for example you have 3 blue and 3 red and 3 yellow balls all colliding. What i really want is when i click in a ball it has to check if the collider has the same tag and destroy the two or three colliders. For example : i click in a blue ball and if there is another blue ball colliding with it they will be destroyed. All the code that i've got in each ball it's :
} function OnDestroy (){
} And i'm getting "An instance of type 'UnityEngine.Collision' is required to access non static member 'collider'."
(comments are locked)
|
|
In each ball, keep a set of currently intersecting balls with the same tag. Add to this list in OnCollisionEnter and remove from it in OnCollisionExit. In OnMouseDown, delete all balls in that list. sorry but how do you "keep a set of currently intersecting balls" ? they have to be colliding so i can destroy them, for instance, if the 2 balls colide at the begining and after they decolide i cant destroy them
Apr 29 '11 at 09:08 PM
Lumart
Just like you'd keep around any other information: in a class variable for the behavior. You can use an ArrayList.
Apr 29 '11 at 09:47 PM
sneftel
I modified my answer above using a boolean to test for the mouse click. Is this what you want?
Apr 30 '11 at 01:07 AM
tool55
Kind of the opposite.
May 03 '11 at 05:38 PM
sneftel
(comments are locked)
|
