//1.实现让玩家的金币分数显示在UI文本中 2.让血量和滑动条关联起来
这一节课主要学会获取组件并改变属性,举一反三!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;//1.实现让玩家的金币分数显示在UI文本中 2.让血量和滑动条关联起来public class UImanager : MonoBehaviour
{public GameObject oneTextUI;TextMeshPro oneScoreText;//3D场景中TMP文本,3D游戏物体文本TextMeshProUGUI oneScoreTextUI;//UI中的TMP文本游戏物体文本public GameObject oneBloodSlider;Slider oneSlider;public GameObject OneInputObj;//用来存储输入框TextMeshProUGUI OneInputtext;public TextMeshProUGUI PlayerName;//玩家昵称void Awake(){oneScoreTextUI = oneTextUI.GetComponent<TextMeshProUGUI>();//从我自己身上拿到 一个TextMeshProUGUI组件oneSlider = oneBloodSlider.GetComponent<Slider>();OneInputtext = OneInputObj.GetComponent<TextMeshProUGUI>();}private void Update(){DisScoreUI();}void DisScoreUI()//自定义一个函数{oneScoreTextUI.text = ScoreManager.CurrentScore.ToString();//把分数变量赋值给我的文本内容 oneSlider.value = ScoreManager.CurrentBlood; //把血量变量赋值给滑动条中的Valuestring PlayName = OneInputtext.text;PlayerName.text = PlayName;}
}