- Home /
Picking up a coin in 2D
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.
Answer by fighder · May 08, 2015 at 08:45 PM
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.
Answer by hbalint1 · May 08, 2015 at 08:42 PM
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);
}
}
}
Your answer
Follow this Question
Related Questions
2d platformer, coding coin collectable? 0 Answers
cannot respawn pickup objects infinite runner / flyer 3 Answers
2D Animation does not start 1 Answer