게임 엔진/Unity

[Unity] Hp Bar 만들기

AlgorFati 2020. 7. 13. 10:26

Hp Bar

유니티 Hp Bar 제작 방법이다.

https://www.youtube.com/watch?v=BLfNP4Sc_iA&t=1118s

 

 

HpBar.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

using UnityEngine.UI;

public class HpBar : MonoBehaviour
{
	[SerializeField]
	private Slider _slider;

	public void SetValue(float value)
	{
		_slider.value = value;
	}
}

 

 

BillBoard.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BillBoard : MonoBehaviour
{
	private Transform cam;

	private void Start()
	{
		cam = Camera.main.transform;
	}

	// Update is called once per frame
	void LateUpdate()
    {
		transform.LookAt(transform.position + cam.forward);
    }
}

 

 

HpBar Prefab

Hp Bar를 GameObject Prefab으로 제작한다.

다음 리소스를 이용한다.

 

 

 

 

 

 

 

 

 

 

 

 

결과 화면