Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

Geting error: CS1525 Unexpected symbol `private' lines (34/15)

$
0
0
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(); 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(); 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); } }

Viewing all articles
Browse latest Browse all 1488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>