Geting error: CS1525 Unexpected symbol `private' lines (34/15)
Hello guys, I started learning Unity today with help of the book: Unity in Action by Joshep Hocking.
The book concentrates on making an FPS game, so when I get to the part were I have to code the hit detection for the enemies, everytime that I type or copy/paste the example code to get a console log when the engine registers a hit on the enemies, I get the error in the title.
It's obvious that Joseph didn't make a mistake. I mean... I'm the stupid one here that's learning. Anybody's willing to give me a hand? I'm having a blast learning C# and Unity.
Here's the code:
using UnityEngine;
using System.Collections;
public class Rayshoot : MonoBehaviour {
private Camera _camera;
void Start() {
_camera = GetComponent<Camera>();
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
void OnGUI() {
int size = 12;
float posX = _camera.pixelWidth/2 - size/4;
float posY = _camera.pixelHeight/2 - size/2;
GUI.Label(new Rect(posX, posY, size, size), "*");
}
void Update() {
if (Input.GetMouseButtonDown(0)) {
Vector3 point = new Vector3(_camera.pixelWidth/2, _camera.pixelHeight/2, 0);
Ray ray = _camera.ScreenPointToRay(point);
RaycastHit hit;
if (Physics.Raycast(ray, out hit)) {
GameObject hitObject = hit.transform.gameObject;
ReactiveTarget target = hitObject.GetComponent<ReactiveTarget>();
if (target != null) {
Debug.Log("Target hit");
} else {
StartCoroutine(SphereIndicator(hit.point));
}
}
}
private IEnumerator SphereIndicator(Vector3 pos) {
GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
sphere.transform.position = pos;
yield return new WaitForSeconds(1);
Destroy(sphere);
}
}
Answer by Denvery · Oct 09, 2015 at 10:13 PM
It seems you've missed }. Try paste additional } in the 31th line
Your answer
Follow this Question
Related Questions
Enemy ragdoll 0 Answers
Basic Enemy follow script for Unity five, desperately needed! 0 Answers
Ennemy don't lose life [C#] 1 Answer
Attaching objects to scripts without dragging and dropping 0 Answers
play a death animation when a the gameobject is destroyed But Please I want it JS Script 0 Answers