using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class TestCHpBar : MonoBehaviour {
private RectTransform rectTrans;
public Transform target;
public Vector3 offsetPos;
void Start () {
rectTrans = GetComponent<RectTransform>();
}
// Update is called once per frame
void Update () {
if (target == null) return;
var col = target.GetComponent<Collider>();
var topAhcor = new Vector3(col.bounds.center.x, col.bounds.max.y, col.bounds.center.z);
Vector3 tarPos = topAhcor;
var viewPos = Camera.main.WorldToViewportPoint(tarPos);
Vector2 screenPos;
if (viewPos.z > 0f && viewPos.x > 0f && viewPos.x < 1f && viewPos.y > 0f && viewPos.y < 1f)
{
//获取屏幕坐标
screenPos = Camera.main.WorldToScreenPoint(tarPos
u3d 制作ugui 血条
最新推荐文章于 2023-03-15 23:35:54 发布
本文详细介绍了如何在Unity3D中利用UGUI系统制作角色血条的步骤,包括创建UI元素、设置血条图像、实现血量动态更新等功能,适合初学者学习游戏UI开发。
摘要由CSDN通过智能技术生成