NG_/Assets/Scripts/UI/室内信息/CameraTriggerUIChange.cs

29 lines
811 B
C#
Raw Normal View History

2024-12-13 19:40:05 +08:00
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class CameraTriggerUIChange : MonoBehaviour
{
public List<TextMeshProUGUI> uiTexts; // 如果使用 TextMeshPro声明 TextMeshProUGUI 类型
public List<string> uiTextsContons;
// public Text uiText; // 如果使用普通的 UI Text声明 Text 类型
// 当摄像机进入触发区域时
private void OnTriggerEnter(Collider other)
{
// 检查是否是摄像机(可以根据标签或比较对象名判断)
if (other.CompareTag("MainCamera")) // 确保摄像机有"MainCamera"标签
{
for (int i = 0; i < uiTexts.Count; i++)
{
uiTexts[i].text = uiTextsContons[i];
}
}
}
}