using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Character : MonoBehaviour
{
public RectTransform transformIcon;
public RectTransform transformTarget;
public Transform hpPoint;
public UIHealthBar uiHealthBar;
void Update()
{
Get_MouseInput();
Update_Moving();
}
private void Get_MouseInput()
{
if (Input.GetMouseButtonUp(0))
{
Vector3 point = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x,
Input.mousePosition.y, -Camera.main.transform.position.z));
this.transformTarget.position = point;
string message = point.ToString();
Debug.Log(message);
}
this.AddHealthBar(this.uiHealthBar);
}
private void Update_Moving()
{
this.transformIcon.position = Vector3.Lerp(this.transformIcon.position, this.transformTarget.position, 0.02f);
}
Vector2 screenPoint;
public void AddHealthBar(UIHealthBar uiHealthBar)
{
this.uiHealthBar = uiHealthBar;
this.SetHealthBarLocation();
}
public void SetHealthBarLocation()
{
this.screenPoint = RectTransformUtility.WorldToScreenPoint(Camera.main, this.hpPoint.position);
this.uiHealthBar.GetComponent<RectTransform>().position = this.screenPoint;
}
}