Regarding the production of UI health bars, a simple method and a simple script method

For specific reference, a blog https://blog.csdn.net/qq_42461824/article/details/85117312
is actually converting the position of the UI to the position under the screen, so that it can be easily operated. Attach mine below. Unity code `insert here using UnityEngine;
using System.Collections;

public class SpriteController : MonoBehaviour
{ public Transform XuePosition;

public Transform XueTiaoTransform;
// Use this for initialization
void Start()
{
    XuePosition = this.transform.Find("XuePosition").transform;

    XueTiaoTransform = this.transform.Find("Canvas/XueTiao").transform;

}

// Update is called once per frame
void Update()
{
    SetMyHealthBar();
}

private void SetMyHealthBar()
{
    Vector3 pos = Camera.main.WorldToScreenPoint(XuePosition.position);

    XueTiaoTransform.position = pos;
}

}
code slice`

Guess you like

Origin blog.csdn.net/charlsdm/article/details/123578579