- Home /
change collision to trigger
Hi, can someone tell me how the following code would work if I would use triggers instead of collision? I want the Objects to be kinematic. Thanks.
void OnCollisionEnter2D(Collision2D collision)
{
foreach(ContactPoint2D contact in collision.contacts)
{
if(count == 0){
count++;
}
}
}
Answer by jann1 · Apr 02, 2014 at 08:02 PM
Yeah I copy pasted this and didnt really know what I was doing. However I figured it out myself. I just wanted to spawn something and when it is destroyed spawn it again and count lets something else know if it has to spawn or not. This is the way I did it now:
void OnTriggerEnter2D(Collider2D collision)
{
if(collision.gameObject.tag == "Object")
{
if(spawnCount == 0){
spawnCount++;
}
}
}
Answer by sparkzbarca · Apr 02, 2014 at 06:00 PM
maybe you could state what your actually trying to do in non code terms?
I get that yoru trying to count the number of points in range of a collider.
the thing is I BELIEVE your only going to end up with 2 contact points and you seem to not understand the docs on that well. One of those contact points is the point on the object that collided, the other is the point of the object it collided with.
what are you trying to do exactly?