unity3d血条的制作

unity3d血条的制作_第1张图片

HPgroup 空物体
HP image 黑色
fill image 绿色

unity3d血条的制作_第2张图片

参考
https://www.bilibili.com/video/BV18e411s7NU?from=search&seid=9409549270261559632

血条面向摄像头

using UnityEngine;

public class UILookatplayer : MonoBehaviour {
    private Camera refCamera;
    private bool isFace = true;
    private Transform mRoot;

    private void Awake() {
        refCamera = Camera.main;
        mRoot = transform;
    }
    void Start() {

    }

    // Update is called once per frame
    void Update() {

    }
    private void LateUpdate() {
        Vector3 targetPos = mRoot.position + refCamera.transform.rotation * (isFace?Vector3.back:Vector3.forward);
        Vector3 targetOrientation = refCamera.transform.rotation * Vector3.up;
        mRoot.LookAt(targetPos, targetOrientation);
    }
}

你可能感兴趣的:(unity3d,unity,unity3d)