How to detect collision?


I’m new in Unity. I’m doing my first game ever and I don’t know how to detect collision. Collision must load level named “Game Over”.

I found code to do this:

public class GameOver : MonoBehaviour {
		void OnCollisionEnter(Collision collision) {
			foreach (ContactPoint contact in collision.contacts) {
				if( == "Fail"){;
					Application.LoadLevel("Game Over");

Code works, but I have warning that “The variable `contact’ is assigned but its value is never used”.

Get rid of the foreach-loop and just use the ‘if…’

The warning is telling you that in your foreach loop you are assigning the variable [contact] and never using it… because you aren’t using it for anything.

Edit : Guess I’ll convert this to an answer since the topic got pushed through the mod queue after I sent it as a message to resolve without publishing.