- 在Canvas中创建Button和Text
- 写C#script代码
// To use this example, attach this script to an empty GameObject. // Create three buttons (Create>UI>Button). Next, select your // empty GameObject in the Hierarchy and click and drag each of your // Buttons from the Hierarchy to the Your First Button, Your Second Button // and Your Third Button fields in the Inspector. // Click each Button in Play Mode to output their message to the console. // Note that click means press down and then release. using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class Button : MonoBehaviour { //Make sure to attach these Buttons in the Inspector public Button m_YourFirstButton, m_YourSecondButton, m_YourThirdButton; public Text m_MyText; void Start() { //Calls the TaskOnClick/TaskWithParameters/ButtonClicked method when you click the Button m_MyText.text = "This
Unity 点击Button改变Text的显示内容
最新推荐文章于 2024-03-25 18:28:06 发布
本文介绍了如何在Unity中通过创建Button和Text组件,并编写C#脚本来实现点击Button动态改变Text显示的内容。具体步骤包括在Canvas上设置元素以及为Button分配事件监听器。
摘要由CSDN通过智能技术生成