29 lines
811 B
C#
29 lines
811 B
C#
|
|
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];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
}
|