45 lines
1.1 KiB
C#
45 lines
1.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class UI_Trigger: MonoBehaviour
|
|
{
|
|
public GameObject uiPanel;
|
|
public GameObject Icon;
|
|
public float range;
|
|
|
|
Transform target;
|
|
|
|
private void Start()
|
|
{
|
|
target = GameObject.FindWithTag("Player").transform;
|
|
InvokeRepeating("UpdateTarget", 0f, 0.25f);
|
|
}
|
|
|
|
private void UpdateTarget()
|
|
{
|
|
Collider[] cols = Physics.OverlapSphere(transform.position, range, 1<<6);
|
|
|
|
if (cols.Length > 0)
|
|
{
|
|
for (int i = 0; i < cols.Length; i++)
|
|
{
|
|
//print("Collider");
|
|
if (cols[i].tag == "Player")
|
|
{
|
|
//print("Player");
|
|
uiPanel.GetComponent<UI>().Active();
|
|
Icon.GetComponent<Icon>().Destroy();
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//print("Collider none");
|
|
uiPanel.GetComponent<UI>().Destroy();
|
|
Icon.GetComponent<Icon>().Active();
|
|
}
|
|
|
|
}
|
|
}
|