- Home /
unity error error CS1525: Unexpected symbol `(', expecting `identifier'
Hi, as you can see I got a problem. Here's the code:
using UnityEngine; using System.Collections;
public class GUITest : MonoBehaviour {
void OnGUI () {
if (GUI.Button (new Rect (25, 25, 100, 30), "Button"))
{
Application.LoadLevel.(1);
}
}
}
Thanks for helping. (I am new in Unity)
Answer by Benproductions1 · Dec 21, 2013 at 08:42 AM
Hello,
Firstly you should format your code when posting questions on Unity Answers. If you don't know how to do that, there's a link to the Unity Answers tutorial video
on the right of this webpage.
In C# a .
as a piece of code is compiled as one of two things:
Either as a literal for float
's or double
's such as
6.0 //double precision floating point
8.83f //floating point
Or as a separator for sub-"fields" of certain data structures such as classes
Application.LoadLevel //The static LoadLevel function of the static Application class
GUI.Button //The static Button function of the static GUI class
When you used it in your script like so:
LoadLevel.(1);
The C# compiler thinks that you are trying to access a sub-"field" of the LoadLevel function, but you follow that with a (
. Since (
is not a valid name character, the C# compiler throws a Compiler Error
with "Unexpected Symbol".
To call functions in C# (and in most other languages) you use a ()
pair, directly after the function reference, containing the arguments for the function like so:
function(arguments)
You must use the correct syntax when writing code or it will not work.
I suggest you do some (a whole lot) of reading about C# syntax and language features so that you understand how to use the language before you post 50 questions about syntax errors.
Hope this helps,
Benproductions1
Answer by KellyThomas · Dec 21, 2013 at 08:39 AM
Application.LoadLevel.(1);
Should be:
Application.LoadLevel(1);