53 lines
1.6 KiB
C#
53 lines
1.6 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class CrosshairUI : MonoBehaviour
|
|
{
|
|
[Header("Элементы прицела")]
|
|
public Image dotImage;
|
|
public Image outlineImage;
|
|
|
|
[Header("Цвета курсора")]
|
|
public Color normalColor = new Color(1f, 1f, 1f, 0.9f);
|
|
public Color enemyTargetColor = new Color(1f, 0.25f, 0.25f, 1f); // Красный при наведении на врага
|
|
public Color interactTargetColor = new Color(0.3f, 0.85f, 1f, 1f); // Голубой при наведении на интерактивный предмет
|
|
|
|
[Header("Дистанция проверки")]
|
|
public float detectRange = 25f;
|
|
private Camera mainCamera;
|
|
|
|
void Start()
|
|
{
|
|
mainCamera = Camera.main;
|
|
if (dotImage != null) dotImage.color = normalColor;
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (dotImage == null) return;
|
|
if (mainCamera == null)
|
|
{
|
|
mainCamera = Camera.main;
|
|
if (mainCamera == null) return;
|
|
}
|
|
|
|
Ray ray = new Ray(mainCamera.transform.position, mainCamera.transform.forward);
|
|
if (Physics.Raycast(ray, out RaycastHit hit, detectRange))
|
|
{
|
|
if (hit.collider.GetComponentInParent<MutantHealth>() != null)
|
|
{
|
|
dotImage.color = enemyTargetColor;
|
|
return;
|
|
}
|
|
|
|
if (hit.collider.CompareTag("Throwable"))
|
|
{
|
|
dotImage.color = interactTargetColor;
|
|
return;
|
|
}
|
|
}
|
|
|
|
dotImage.color = normalColor;
|
|
}
|
|
}
|