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
}