W298.dev
ProjectsPostsAbout Me
youtube
Pages
ProjectsPostsAbout Me
Posts
TAGS
All
RL-Obstacle-Avoid
RL-Competitive
Robot-Escape
Assembly Definition
ML-Agent
RL-Obstacle-Avoid
RL-Competitive
Unity
RL-Obstacle-Avoid
RL-Competitive
Robot-Escape
Assembly Definition
SERIES
RL-Obstacle-Avoid
RL-Competitive
Robot-Escape

Enemy UI

  • Player UI (HUD)
  • Enemy UI (인디케이터)
  • Turret, Laptop Hack UI

UI

EnemyRobot Prefab 에 다음과 같이 Canvas 를 붙여 주었다.
https://velog.velcdn.com/images/lutca1320/post/40cfca56-4211-4fc0-9b5e-94b6f477e8e1/image.png
노란색 아이콘은 detectLevel 을 표시하고, 아래 빨간색은 Health Bar 이다. detectLevel 이 80 이상이거나, 플레어어를 발견하면 사각형이 꽉 차게 되고, 빨간색으로 변한다.
https://velog.velcdn.com/images/lutca1320/post/5c7273f7-b92b-47d0-b28d-302fe2a57b28/image.gif

StatusIndicator.cs

1using System.Collections;
2using System.Collections.Generic;
3using UnityEngine;
4using UnityEngine.UI;
5
6public class StatusIndicator : MonoBehaviour
7{
8    private RobotStatusController robotStatus;
9    private EnemyRobotAI ai;
10    private Camera mainCam;
11
12    private RectTransform healthBarRect;
13
14    private GameObject detectBorder;
15    private Image detectFrontImage;
16    private RectTransform detectFrontRect;
17
18    private void Start()
19    {
20        robotStatus = transform.root.GetComponent<RobotStatusController>();
21        ai = transform.root.GetComponent<EnemyRobotAI>();
22        mainCam = Camera.main;
23
24        healthBarRect = transform.GetChild(0).GetChild(1).GetComponent<RectTransform>();
25
26        detectBorder = transform.GetChild(1).gameObject;
27        detectFrontImage = detectBorder.transform.GetChild(1).GetComponent<Image>();
28        detectFrontRect = detectBorder.transform.GetChild(1).GetComponent<RectTransform>();
29    }
30
31    private void LateUpdate()
32    {
33        healthBarRect.sizeDelta = new Vector2(robotStatus.health, healthBarRect.sizeDelta.y);
34
35        if (ai.detectLevel.currentLevel <= 0 && !ai.enemyObject)
36        {
37            detectBorder.SetActive(false);
38        }
39        else
40        {
41            detectBorder.SetActive(true);
42            detectFrontRect.sizeDelta = new Vector2(detectFrontRect.sizeDelta.x, ai.enemyObject ? 30 : Mathf.Clamp(ai.detectLevel.currentLevel * 0.3f * 1.25f, 0, 30));
43
44            detectFrontImage.color = ai.detectLevel.currentLevel >= 80 || ai.enemyObject ? new Color(0.735849f, 0.2249199f, 0.2662449f) : new Color(1, 0.7328318f, 0);
45        }
46
47        transform.rotation = mainCam.transform.rotation;
48
49        transform.parent.position = transform.root.position + new Vector3(-0.5f, 2, 0.5f);
50    }
51}
52
53