Commit f88983d5 authored by 15박보승's avatar 15박보승

적이 피격당할시 적의 체력바 UI를 띄우도록 구현

parent 2314940d
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &3062086774773215764
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 3062086774773215765}
- component: {fileID: 3062086774773215763}
- component: {fileID: 3062086774773215762}
m_Layer: 5
m_Name: Fill
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &3062086774773215765
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3062086774773215764}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 3062086775269430480}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 10, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &3062086774773215763
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3062086774773215764}
m_CullTransparentMesh: 0
--- !u!114 &3062086774773215762
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3062086774773215764}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 0, b: 0, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_Sprite: {fileID: 10905, guid: 0000000000000000f000000000000000, type: 0}
m_Type: 1
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!1 &3062086775062663198
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 3062086775062663199}
- component: {fileID: 3062086775062663196}
m_Layer: 5
m_Name: EnemyHealthUI
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &3062086775062663199
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3062086775062663198}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 3062086775248920219}
- {fileID: 3062086775269430480}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 1000, y: 200}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &3062086775062663196
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3062086775062663198}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 67db9e8f0e2ae9c40bc1e2b64352a6b4, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Navigation:
m_Mode: 3
m_SelectOnUp: {fileID: 0}
m_SelectOnDown: {fileID: 0}
m_SelectOnLeft: {fileID: 0}
m_SelectOnRight: {fileID: 0}
m_Transition: 1
m_Colors:
m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1}
m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608}
m_ColorMultiplier: 1
m_FadeDuration: 0.1
m_SpriteState:
m_HighlightedSprite: {fileID: 0}
m_PressedSprite: {fileID: 0}
m_SelectedSprite: {fileID: 0}
m_DisabledSprite: {fileID: 0}
m_AnimationTriggers:
m_NormalTrigger: Normal
m_HighlightedTrigger: Highlighted
m_PressedTrigger: Pressed
m_SelectedTrigger: Selected
m_DisabledTrigger: Disabled
m_Interactable: 1
m_TargetGraphic: {fileID: 0}
m_FillRect: {fileID: 3062086774773215765}
m_HandleRect: {fileID: 0}
m_Direction: 0
m_MinValue: 0
m_MaxValue: 1
m_WholeNumbers: 0
m_Value: 1
m_OnValueChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.Slider+SliderEvent, UnityEngine.UI, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null
--- !u!1 &3062086775248920218
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 3062086775248920219}
- component: {fileID: 3062086775248920217}
- component: {fileID: 3062086775248920216}
m_Layer: 5
m_Name: Background
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &3062086775248920219
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3062086775248920218}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 3062086775062663199}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0.25}
m_AnchorMax: {x: 1, y: 0.75}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &3062086775248920217
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3062086775248920218}
m_CullTransparentMesh: 0
--- !u!114 &3062086775248920216
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3062086775248920218}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0.26415092, g: 0, b: 0, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_Sprite: {fileID: 10907, guid: 0000000000000000f000000000000000, type: 0}
m_Type: 1
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!1 &3062086775269430483
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 3062086775269430480}
m_Layer: 5
m_Name: Fill Area
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &3062086775269430480
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3062086775269430483}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 3062086774773215765}
m_Father: {fileID: 3062086775062663199}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0.25}
m_AnchorMax: {x: 1, y: 0.75}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: -10, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
fileFormatVersion: 2
guid: 235a2d94312e86a42bbadc5591dce379
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
......@@ -959,10 +959,10 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3}
m_Name:
m_EditorClassIdentifier:
m_UiScaleMode: 0
m_UiScaleMode: 1
m_ReferencePixelsPerUnit: 100
m_ScaleFactor: 1
m_ReferenceResolution: {x: 800, y: 600}
m_ReferenceResolution: {x: 1920, y: 1080}
m_ScreenMatchMode: 0
m_MatchWidthOrHeight: 0
m_PhysicalUnit: 3
......@@ -1026,6 +1026,8 @@ MonoBehaviour:
targetLockedUIPrefab: {fileID: 5037612186728958095, guid: 04d7a8bd5b7afea418585e2d9e55c109,
type: 3}
heightText: {fileID: 369112312}
enemyHealthUIPrefab: {fileID: 3062086775062663198, guid: 235a2d94312e86a42bbadc5591dce379,
type: 3}
--- !u!1 &519663054
GameObject:
m_ObjectHideFlags: 0
......@@ -1443,7 +1445,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: d71b4c543a96dc645a771f6d62a28989, type: 3}
m_Name:
m_EditorClassIdentifier:
health: 100
maxHealth: 50
curHealth: 0
bloodEffect: {fileID: 1345154483}
--- !u!54 &850429691
Rigidbody:
......@@ -1977,7 +1980,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: d71b4c543a96dc645a771f6d62a28989, type: 3}
m_Name:
m_EditorClassIdentifier:
health: 100
maxHealth: 50
curHealth: 0
bloodEffect: {fileID: 1443389647}
--- !u!54 &1219641837
Rigidbody:
......
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Enemy : MonoBehaviour
{
[SerializeField]
private int health;
private int maxHealth;
[SerializeField]
private int curHealth;
private MeshRenderer meshRenderer;
[SerializeField]
private ParticleSystem bloodEffect;
private RectTransform healthUIRect;
private Slider healthUI;
private Collider col;
private void Start()
{
meshRenderer = GetComponent<MeshRenderer>();
col = GetComponent<Collider>();
curHealth = maxHealth;
}
private void Update()
{
UpdateHealthUIRect();
}
public void GetDamaged(int dmg)
{
health -= dmg;
curHealth -= dmg;
StartCoroutine(DamageRoutine());
if (health <= 0)
UpdateHealthUI();
if (curHealth <= 0)
{
Dead();
}
......@@ -32,6 +49,8 @@ public class Enemy : MonoBehaviour
Debug.Log(gameObject + " : DEAD!");
GetComponent<Rigidbody>().useGravity = false;
GetComponent<Collider>().enabled = false;
if (healthUI != null)
Destroy(healthUI.gameObject);
Destroy(gameObject, 5);
}
......@@ -40,4 +59,27 @@ public class Enemy : MonoBehaviour
bloodEffect?.Play();
yield return null;
}
private void UpdateHealthUI()
{
if (healthUI == null)
{
healthUI = IngameUIManager.inst.CreateNewHealthUI();
healthUIRect = healthUI.GetComponent<RectTransform>();
}
IngameUIManager.inst.UpdateEnemyHealthUI(healthUI, maxHealth, curHealth);
}
private void UpdateHealthUIRect()
{
if (healthUI == null)
return;
float distance = Vector3.Distance(Camera.main.transform.position, transform.position);
healthUIRect.localScale = new Vector3(1,1,1) / distance;
Vector2 viewportPoint = Camera.main.WorldToViewportPoint(transform.position + new Vector3(0,col.bounds.extents.y * 1.5f));
healthUIRect.anchorMax = viewportPoint;
healthUIRect.anchorMin = viewportPoint;
}
}
......@@ -12,6 +12,9 @@ public class IngameUIManager : SingletonBehaviour<IngameUIManager>
[SerializeField]
private Text heightText;
[SerializeField]
private GameObject enemyHealthUIPrefab;
public void UpdateTargetLockedUIs(Vector3[] pos)
{
int tmp, i = 0;
......@@ -44,4 +47,19 @@ public class IngameUIManager : SingletonBehaviour<IngameUIManager>
{
heightText.text = string.Format("{0:F1}", height) + " M";
}
public Slider CreateNewHealthUI()
{
Slider ui = Instantiate(enemyHealthUIPrefab, transform).GetComponent<Slider>();
Destroy(ui.gameObject, 5);
return ui;
}
public void UpdateEnemyHealthUI(Slider ui, int maxHealth, int curHealth)
{
if (ui == null)
Debug.LogError("There's no health ui available");
ui.value = curHealth / (float)maxHealth;
Debug.Log(ui.value);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment