BCE0043: Unexpected token: GUI

I am fairly new to Unity. Im working with the OnGUI controls but have been running into problems. Heres my code

        function OnGUI()
    GUI.Button (Rect (560,25,140,35), CameraView)
    		if(CameraView < 7)
    var CameraView = 1;       	
    (GUI.Label (Rect (20,40,140,35), "Speed: " + Speed + " MPH")
            // Displays "Speed: -- MPH.".

I have already made the variable before in the class and this is just the OnGUI side of the code
For some reason it comes up with the error “BCE0043: Unexpected token: GUI.”
Im sure that its just something simple but ive looked around the internet and unity answers but havent been able to find exactly the solution
Any help will be appreciated
Thank You
P.S. CameraView and Speed are variables. Also this is written in Javascript

The specific error you are getting is because you did not put a ‘{’ after the ‘function OnGUI()’ on line 1. There are a number of other problems as well:

  • GUI.Button code has to be inside an ‘if’ in order to function.
  • CameraView is undeclared at this point. And if it is an ‘int’ it needs to be converted to a string before use in a GUI.Button.
  • You need to have declared ‘CameraView’ at the top of the file, so the use of ‘var’ on line 9 is wrong.
  • You don’t need the extra ‘(’ and ‘)’ on line 12/14.

Here is some code that compiles that I think is in the general direction you were going with your code.

#pragma strict

 private var CameraView = 1;
 var Speed = 55.0;
 function OnGUI() {
    if (GUI.Button (Rect (560,25,140,35), CameraView.ToString())) {
		if(CameraView < 7)
			CameraView = 1;         
    GUI.Label (Rect (20,40,140,35), "Speed: " + Speed + " MPH");