механики
This commit is contained in:
1 parent
dd5a95a4d3
commit
11d57bec19
129 files changed
+21889
-62
No files matched your search
@@ -0,0 +1,52 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user