Firstly, your English is fine. No need to apologize. Whatever your native language is, I’m sure I’d be terrible in explaining a coding issue using that!
Second, when sharing code on the forums, please use code tags. It makes things much easier to read, and therefor, easier to spot issues. I’ve taken the liberty of pasting your code into a code tag below:
function OnCollisionEnter2D(co: Collision2D) {
if (co.gameObject.tag == "Player" && (co.contacts[0].normal == Vector3.right || co.contacts[0].normal == -Vector3.right || co.contacts[0].normal == -Vector3.up)) {
co.gameObject.SendMessage("GameOver") ;
}
}
function GameOver() {
Application.LoadLevel(2) ;
}
I haven’t done much with with SendMessage, so I’m going to tag @JoeStrout to take a look at that and make sure you’re using it correctly.
Third, what I would do is add some Debug.Log() statements in. Place them everywhere just to find where the hole is, then trim them back out until you can identify where the problem is specifically. If a message isn’t being called in the console, it means that line of code is not being run, so you’ll have to check your control statements and other factors to find out why. For example:
function OnCollisionEnter2D(co: Collision2D) {
Debug.Log("CollisionEnter: " + co.name);
if (co.gameObject.tag == "Player" && (co.contacts[0].normal == Vector3.right || co.contacts[0].normal == -Vector3.right || co.contacts[0].normal == -Vector3.up)) {
Debug.Log("Send message to co go");
co.gameObject.SendMessage("GameOver") ;
}
}
function GameOver() {
Debug.Log("Game over, man. Game over!");
Application.LoadLevel(2) ;
}
Fourth, that if statement looks like a bit of a monster. Consider breaking it down into multiple statements (adding Debug.Log messages at each level if you want to see if there’s a problem with the check) for readability alone. Remember: Readable code is preferrable 100% of the time to line-efficient code.
Lastly, if you’re not already committed to UnityScript (and don’t let Unity’s confusing messaging fool you: it is UnityScript, a separate thing from JavaScript, entirely), I do highly recommend you learn to work with C#. Most of the tutorials are written with C# now, and you’ll enjoy better error handling with it, too. Plus, C# is C#, so whatever you learn you can pretty much transfer to anything else that uses the language, unlike UnityScript. Your preference, of course, but I just wanted to make the recommendation.