- Home /
The question is answered, right answer was accepted
error CS1525: Unexpected symbol `}'
Hi just need a little help with this error. I have had it before due to the incorrect number of brackets and have thus been able to sort it but this time I have the correct number of opening and closing brackets but its still coming up.
The origin of this script is from this tutorial http://stormtek.geek.nz/rts_tutorial/part6.php and these errors have come at the end of part 6.
Assets/Player/UserInput.cs(130,41): error CS1525: Unexpected symbol `}'
using UnityEngine; using System.Collections; using RTS;
public class UserInput : MonoBehaviour {
private Player player;
// Use this for initialization
void Start ()
{
player = transform.root.GetComponent< Player >();
}
// Update is called once per frame
void Update ()
{
if(player.human)
MoveCamera ();
RotateCamera ();
MouseActivity ();
}
private void MoveCamera ()
{
float xpos = Input.mousePosition.x;
float ypos = Input.mousePosition.y;
Vector3 movement = new Vector3 (0, 0, 0);
//horizontal camera movement
if (xpos >= 0 && xpos < ResourceManager.ScrollWidth)
{
movement.x -= ResourceManager.ScrollSpeed;
} else if (xpos <= Screen.width && xpos > Screen.width - ResourceManager.ScrollWidth)
{
movement.x += ResourceManager.ScrollSpeed;
}
//vertical camera movement
if (ypos >= 0 && ypos < ResourceManager.ScrollWidth)
{
movement.z -= ResourceManager.ScrollSpeed;
}
else if (ypos <= Screen.height && ypos > Screen.height - ResourceManager.ScrollWidth)
{
movement.z += ResourceManager.ScrollSpeed;
}
//make sure movement is in the direction the camera is pointing
//but ignore the vertical tilt of the camera to get sensible scrolling
movement = Camera.main.transform.TransformDirection (movement);
movement.y = 0;
//away from ground movement
movement.y -= ResourceManager.ScrollSpeed * Input.GetAxis ("Mouse ScrollWheel");
//calculate desired camera position based on received input
Vector3 origin = Camera.main.transform.position;
Vector3 destination = origin;
destination.x += movement.x;
destination.y += movement.y;
destination.z += movement.z;
//limit away from ground movement to be between a minimum and maximum distance
if (destination.y > ResourceManager.MaxCameraHeight)
{
destination.y = ResourceManager.MaxCameraHeight;
}
else if (destination.y < ResourceManager.MinCameraHeight)
{
destination.y = ResourceManager.MinCameraHeight;
}
//if a change in position is detected perform the necessary update
if (destination != origin) {
Camera.main.transform.position = Vector3.MoveTowards (origin, destination, Time.deltaTime * ResourceManager.ScrollSpeed);
}
}
private void RotateCamera ()
{
Vector3 origin = Camera.main.transform.eulerAngles;
Vector3 destination = origin;
//detect rotation amount if ALT is being held and the Right mouse button is down
if ((Input.GetKey (KeyCode.LeftAlt) || Input.GetKey (KeyCode.RightAlt)) && Input.GetMouseButton (1)) {
destination.x -= Input.GetAxis ("Mouse Y") * ResourceManager.RotateAmount;
destination.y += Input.GetAxis ("Mouse X") * ResourceManager.RotateAmount;
}
//if a change in position is detected perform the necessary update
if (destination != origin) {
Camera.main.transform.eulerAngles = Vector3.MoveTowards (origin, destination, Time.deltaTime * ResourceManager.RotateSpeed);
}
}
private Vector3 FindHitPoint() {
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast (ray, out hit))
return hit.point;
return ResourceManager.InvalidPosition;
}
private void MouseActivity()
{
if (Input.GetMouseButtonDown (0)) LeftMouseClick();
else if (Input.GetMouseButtonDown(1)) RightMouseClick();
}
private void LeftMouseClick() {
if (player.hud.MouseInBounds ()) {
GameObject hitObject = FindHitObject ();
Vector3 hitPoint = FindHitPoint ();
if (hitObject && hitPoint != ResourceManager.InvalidPosition) {
if (player.SelectedObject)
player.SelectedObject.MouseClick (hitObject, hitPoint, player);
else if (hitObject.name != "Ground") {
WorldObject worldObject = hitObject.transform.root.GetComponent< WorldObject > ();
if (worldObject) {
//we already know the player has no selected object
player.SelectedObject = worldObject;
worldObject.SetSelection (true);
player.hud.GetPlayingArea()
}
}
}
}
}
private void RightMouseClick(){
if (player.hud.MouseInBounds () && !Input.GetKey (KeyCode.LeftAlt) && player.SelectedObject) {
player.SelectedObject.SetSelection (false);
player.SelectedObject = null;
player.hud.GetPlayingArea()
}
}
private GameObject FindHitObject() {
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast (ray, out hit))
return hit.collider.gameObject;
return null;
}
}
This error also comes up - Assets/Player/UserInput.cs(142,17): error CS1525: Unexpected symbol `}'
You have one } too many or too few. Indent your code next time.
Answer by tanoshimi · Jul 05, 2015 at 10:40 AM
Error messages are written to help you. When you get an error that says "Unexpected symbol", it's worth looking at your code and thinking "Well, if "}" wasn't what Unity was expecting, what was it expecting?".
Look at the sections of code indicated by the error messages. You'll see that you have the same line of code, with the same mistake in it, in both cases:
player.hud.GetPlayingArea()
Statements need to be terminated by a semicolon. So, Unity was expecting to find a ; after GetPlayingArea(), but the next character it found (which is on the following line) was a }. That's what Unexpected symbol `}' means.
Follow this Question
Related Questions
unexpected symbol 'private' 0 Answers
CS1525: 60,68 Unexpected symbol MatchMaxPlayers 1 Answer
Quill18's Tutorial Scripts: Unexpected Symbols 1 Answer
Error unexpected symbol 'internal' What is wrong with this? 0 Answers
Unexpected symbol, "Projectile" while attempting to delete gameObject.Projectile 1 Answer