- Home /
Unexpected Symbol 'public'
I just need a bit of help with my script. Everything is fine but I've put a public bool in a region and it comes up with a compiling error which says "Assets/Standard Assets/Scripts/MousePoint.cs(83,1): error CS1525: Unexpected symbol `public'".
Here is my script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MousePoint : MonoBehaviour {
RaycastHit hit;
public GameObject Target;
public static GameObject CurrentlySelectedUnit;
private static Vector3 mouseDownPoint;
void Awake()
{
mouseDownPoint = Vector3.zero;
}
// Update is called once per frame
void Update ()
{
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (ray, out hit, Mathf.Infinity)) {
//Store point at mouse button down
if (Input.GetMouseButtonDown (0)) {
mouseDownPoint = hit.point;
}
if (hit.collider.name == "TerrainMain") {
//When we click the right mouse button, instantiate target
if (Input.GetMouseButtonDown (1)) {
GameObject TargetObj = Instantiate (Target, hit.point, Quaternion.identity) as GameObject;
TargetObj.name = "Target Instantiated";
} else if (Input.GetMouseButtonUp (0) && DidUserClickLeftMouse (mouseDownPoint))
DeselectGameObjectIfSelected ();
} //End of the terrain
else {
//Hitting other objects
if (Input.GetMouseButtonUp (0) && DidUserClickLeftMouse (mouseDownPoint)) {
//Is the user hitting a unit?
if (hit.collider.transform.FindChild ("Selected")) {
//Found a unit we can select
Debug.Log ("Found a unit!");
//Are we selecting a different object?
if (CurrentlySelectedUnit != hit.collider.gameObject) {
//Activate the selector
GameObject SelectedObj = hit.collider.transform.FindChild ("Selected").gameObject;
SelectedObj.active = true;
//Deactivate the currently selected objects selector
if (CurrentlySelectedUnit != null)
CurrentlySelectedUnit.transform.FindChild ("Selected").GameObject.active = false;
//Replace currently selected unit
CurrentlySelectedUnit = hit.collider.gameObject;
}
} else {
//If this object is not a unit
DeselectGameObjectIfSelected ();
}
}
}
} else {
if (Input.GetMouseButtonDown (0) && DidUserClickLeftMouse ())
DeselectGameObjectIfSelected ();
}
#region Helper function
//Check if a user clicked mouse
public bool DidUserClickLeftMouse(Vector3 hitPoint)
{
float clickZone = 1.3f;
if(
(mouseDownPoint.x < hitPoint.x + clickZone && mouseDownPoint.x > hitPoint.x - clickZone) &&
(mouseDownPoint.y < hitPoint.y + clickZone && mouseDownPoint.y > hitPoint.y - clickZone) &&
(mouseDownPoint.z < hitPoint.z + clickZone && mouseDownPoint.z > hitPoint.z - clickZone)
)
return true; else return false;
}
//Deselects gameobject if selected
public static void DeselectGameObjectIfSelected()
{
if (CurrentlySelectedUnit != null)
{
CurrentlySelectedUnit.transform.Find ("Selected").gameObject.active = false;
CurrentlySelectedUnit = null;
}
}
#endregion
}
Comment
Best Answer
Answer by ShadyProductions · Aug 06, 2017 at 09:07 AM
You are missing an } to close Update()
} else {
if (Input.GetMouseButtonDown (0) && DidUserClickLeftMouse ())
DeselectGameObjectIfSelected ();
}
}
This is a common issue, and shouldn't be hard to see. I wonder if you copied all of this code..
Oh, thanks! After that's fixed though, now I have an error saying
Assets/Standard Assets/Scripts/$$anonymous$$ousePoint.cs(75,7): error CS1519: Unexpected symbol `else' in class, struct, or interface member declaration
and
Assets/Standard Assets/Scripts/$$anonymous$$ousePoint.cs(75,9): error CS9010: Primary constructor body is not allowed
Got it, accidently put it in the wrong else statement. Thanks again.
Your answer
![](https://koobas.hobune.stream/wayback/20220612132041im_/https://answers.unity.com/themes/thub/images/avi.jpg)