Помогите написал скрипт C# и вылезла ошибка Cs1002
Вот скрипт
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RayShooter : MonoBehaviour
{
private Camera _camera;
private void Start()
{
_camera = GetComponent<Camera>();
Cursor.lockstate = CursorLockMode.Locked;
Cursor.visible = false;
}
private void Update()
{
if (input.GetMouseButtonDown(0))
{
Vector3 screenCenter = new Vector3(Screen.width/2, Screen.height/2, 0);
Ray ray = _camera.ScreenPointToRay(screenCenter);
RaycastHit hit;
if(Physics.Raycast(ray, out hit))
{
GameObject hitObject - hit.transform.gameObject;
ReactiveTarget target - hitObject.GetComponent<ReactiveTarget>();
if (target != null)
{
target.ReactToHit();
}
else
{
StartCoroutine(SphereInicatorCoroutine(hit.point));
Debug.DrawLine(this.transform.position, hit.point, Color.green, 6);
}
}
}
}
private void OnGUI()
private IEnumerator SphereInicatorCoroutine(Vector3 pos)
{
GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
sphete.transform.position = pos;
yield return new WaitForSeconds(6);
Destroy(sphere);
}
}
Ошибка CS1002 означает, что компилятор обнаружил отсутствие точки с запятой. Точка с запятой требуется в конце каждого оператора в C#. Оператор может занимать более одной строки.
В вашем скрипте есть несколько ошибок, которые могут вызвать ошибку CS1002:
В строке 15 Cursor.lockstate должно быть Cursor.lockState.
В строке 24 input.GetMouseButtonDown(0) должно быть Input.GetMouseButtonDown(0).
В строке 38 GameObject hitObject - hit.transform.gameObject; должно быть GameObject hitObject = hit.transform.gameObject;.
В строке 39 ReactiveTarget target - hitObject.GetComponent<ReactiveTarget>(); должно быть ReactiveTarget target = hitObject.GetComponent<ReactiveTarget>();.
В строке 57 private void OnGUI() не завершен и не имеет тела.
В строке 63 sphete.transform.position = pos; должно быть sphere.transform.position = pos;.
Попробуй, я не тестировал
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RayShooter : MonoBehaviour
{
private Camera _camera;
private void Start()
{
_camera = GetComponent<Camera>();
Cursor.lockstate = CursorLockMode.Locked;
Cursor.visible = false;
}
private void Update()
{
if (input.GetMouseButtonDown(0))
{
Vector2 screenCenter = new Vector2(Screen.width/2, Screen.height/2);
Ray ray = _camera.ScreenPointToRay(screenCenter);
RaycastHit hit;
if(Physics.Raycast(ray, out hit))
{
GameObject hitObject = hit.transform.gameObject;
ReactiveTarget target = hitObject.GetComponent<ReactiveTarget>();
if (target != null)
{
target.ReactToHit();
}
else
{
StartCoroutine(SphereInicatorCoroutine(hit.point));
Debug.DrawLine(this.transform.position, hit.point, Color.green, 6);
}
}
}
}
private void OnGUI()
private IEnumerator SphereInicatorCoroutine(Vector3 pos)
{
GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
sphete.transform.position = pos;
yield return new WaitForSeconds(6);
Destroy(sphere);
}
Должно работать