using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
public class Ray_Shoot : MonoBehaviour
{
private Camera _camera;
void Start()
{
}
void Update()
{
if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject())
{
Vector3 point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0);
Ray ray = _camera.ScreenPointToRay(point);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
Reactive_Target target = hit.transform.gameObject.GetComponent<Reactive_Target>();
if (target!=null)
{
target.ReactToHit();
} else
{
StartCoroutine(SphereIndicator(hit.point));
}
}
}
}
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), "*");
}
private IEnumerator SphereIndicator(Vector3 pos)
{
GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
sphere.transform.position = pos;
yield return new WaitForSeconds(1);
Destroy(sphere);
}
}
Выдает ошибку <
Ray_Shoot.Update () (at Assets/#Scripts/Ray_Shoot.cs:15)>>.