Unity 血条同步

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI; // 血条显示需要

public class Health : MonoBehaviour
{
    
       // 血条变量 血条数值变量
    public Slider playerSlider3D;
    private Slider playerSlider2D;
    public int health;

    void Start()
    {
    
       // 获取屏幕上的血条 玩家和屏幕上的血条都等于血条数值
        playerSlider2D = GetComponent<Slider>();
        playerSlider2D.maxValue = health;
        playerSlider3D.maxValue = health;
    }


    void Update()
    {
    
       // 屏幕血条数值通过血条数值改动 玩家数值和屏幕数值同步
        playerSlider2D.value = health;
        playerSlider3D.value = playerSlider2D.value;
    }
}

猜你喜欢

转载自blog.csdn.net/qq_60839745/article/details/128737537