- Home /
Problem Detecting 2D Collisions
The idea is that when a gameobject enters an empty gameobject's box collider, it will play a sound. However I am struggling to even detect collisions between the two objects!
Here is the setup of the empty game object:
And here is the gameobject which is colliding with it:
This is the code I am using for detecting collisions:
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(AudioSource))]
public class playEricSound : MonoBehaviour {
public AudioClip eric;
void OnCollisionEnter2D (Collision2D collide) {
print ("Collide");
audio.PlayOneShot(eric);
}
}
Thanks for your help! If you need anything else, just ask!
Answer by supericecream · Sep 07, 2014 at 05:14 AM
So hard to see clearly in the screenshot!
But from what I can see, you forgot to add the rigidbody component to either of those sprites (need that component + collider for all sprites that you want to use the physics engine with).
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Checking collision between 2 objects on 3rd object 0 Answers
Problem with collision detection 0 Answers
My weapon takes damage. help... 1 Answer
Call a Void on Collision 2 Answers