- Home /
Ending my game
I'm making a parkour game that when you hit the water the game ends, so I attached this script to the water
using ;UnityEngine;
using ;System.Collections;
public class EndOflevel : MonoBehaviour {
void OnTriggerEnter3D(Collider3D)
{
Application.Quit();
}
}
The error "Assets/EndScript.js(4,25):BCE0043: Unexpected token: :." keeps on popping up everytime I try it.
Any solutions? I converted it to CSS but on error saying something about it not recognising collider3D. Can you tell me how to fix that?
Answer by Kiwasi · Jul 16, 2014 at 10:16 AM
Seriously? Try deleting the unexpected symbols and see what happens.
Also there is no call back for OnTriggerEnter3D.
Here is the fix
using UnityEngine;
using System.Collections;
public class EndOflevel : MonoBehaviour {
void OnTriggerEnter(Collider other)
{
Application.Quit();
}
}
Nothing happened, I fell through the water and fell infinitely
That's probably either because the water has no collider, or because you tested this in the editor. Application.Quit is ignored in the editor.
Do you see a Collider3D in my script?
Collider3D does not exist. Follow my answer before posting that it doesn't work.
Answer by rutter · Jul 16, 2014 at 06:12 PM
The code you posted is C#.
The error you posted is for JavaScript.
You have C# code in a .js
file. If you want to develop in C#, your file extension should be .cs
.
The other posters have noticed that your C# syntax was unusual, but fixing that won't let you compile because Unity's sending the file to the wrong compiler. Fix your extension and that part of the problem will be fixed.
Answer by ReContraChanfle · Jul 16, 2014 at 05:55 PM
you have to add the object tag
using UnityEngine;
using System.Collections;
public class EndOflevel : MonoBehaviour {
void OnTriggerEnter(Collider3D other)
{
if(other.gameobject.tag=="water")
{
Application.Quit();
}
}
}
look the answer of rutter, he have the solution i think.