using UnityEngine;
using System.Collections;
public class soul : MonoBehaviour
{ void OnTrigger2D(Collider2D col)
{ if (col.gameObject.tag == “soul”) { Destroy (gameObject); }
}
}
When I make the collider a trigger the object just falls through my platforms.
`` I have tried placing the object right above my character to see if the collision works but it doesn’t.
First of all, I don’t think OnTrigger2D is the right function, there is OnTriggerEnter2D, OnTriggerStay2D, and OnTriggerExit2D, but there is no OnTrigger2D.
Second, if you make the collider a trigger, then it doesn’t collide with other colliders, it triggers things, so that is why it falls through platforms. You might wanna remove the rigidbody component from those coins, if you need the coins to be with a rigidbody, but don’t want them to fall through, you can also make the rigidbody isKinematic and then manipulate the physics manually through script.
There is no method called “OnTrigger2D”. I think you want to use OnTriggerEnter2D();
using UnityEngine;
using System.Collections;
public class soul : MonoBehaviour {
void OnTriggerEnter2D(Collider2D col) {
if (col.gameObject.tag == "soul") {
Destroy (gameObject);
}
}
}