| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.AI;
- using UnityEngine.UI;
- namespace ShotSimulator.Target
- {
- public class HumanoidShotTarget : MonoBehaviour
- {
- public bool IsRunning { get; set; }
- private float m_Health;
- public float m_MaxHealth;
- [SerializeField]
- private Canvas m_Canvas;
- [SerializeField]
- private Slider healthBar;
- public Image healthBarImage;
- [SerializeField]
- protected List<HumanoidPartShotTarget> m_HumanoidParts = new List<HumanoidPartShotTarget>();
- public List<HumanoidPartType> m_CauseHumanoidPartReduceHPOrder = new List<HumanoidPartType>();
- public float Health
- {
- get { return m_Health; }
- protected set
- {
- m_Health = value;
- if (m_Health > 1)
- {
- healthBarImage.color = new Color(0, 1, 1);
- }
- else
- {
- healthBarImage.color = Color.red;
- }
- healthBar.value = m_Health / m_MaxHealth;
- }
- }
- public void InitHumanoidShotTarget(float health, Vector3 origin)
- {
- m_MaxHealth = health;
- Health = health;
- m_CauseHumanoidPartReduceHPOrder.Clear();
- gameObject.transform.position = origin;
- foreach(var part in m_HumanoidParts)
- {
- part.IsRunning = true;
- }
- IsRunning = true;
- }
- protected void Update()
- {
- if (!IsRunning) return;
- m_Canvas.gameObject.transform.LookAt(Camera.main.transform);
- }
- public virtual void CauseHumanoidPartReduceHP(HumanoidPartShotTarget part)
- {
- switch (part.PartType)
- {
- case HumanoidPartType.Head:
- Health = 0f;
- break;
- case HumanoidPartType.Body:
- Health--;
- break;
- }
- m_CauseHumanoidPartReduceHPOrder.Add(part.PartType);
- }
- }
- }
|