Script behaves strangely
Hello, I have a script that does this: I have a moving object which at some point is put in place, then I enable attached script (PersistentColliding.cs
) with OnCollisionStay2D
, and if there are touching objects with 2D box colliders attached, they fire OnCollisionStay2D
. In OnCollisionStay2D
I collect all the touching colliding objects in a Hashtable and invoke a method GrabScores
after 0.3 secs. All collected in a Hashtable unique objects are counted, processed and points they give are gathered. So far so good. I attach this script to several moving objects and expect every time a figure is placed to gather all the objects points from all the touching objects. But the case is PersistentColliding.cs
works only first time. So when my first figure is placed it works as expected, but for every sequential figure it is not working. Does anyone have an Idea what can be the problem ? All the objects that have to be collected have a script called ScoreProperties
which contains all the necessary properties for score, collectable type etc.
Answer by kpetkov · May 08, 2018 at 12:54 PM
I manage to fix it, it needs RegidBody in order to work properly. Now I see other problem with Collision stay it is -> Not every time OnCollisionStay2D
is triggered! But I suppose it is related to Unity phisycs system.