Unity 点击Button改变Text的显示内容

本文介绍了如何在Unity中通过创建Button和Text组件,并编写C#脚本来实现点击Button动态改变Text显示的内容。具体步骤包括在Canvas上设置元素以及为Button分配事件监听器。
摘要由CSDN通过智能技术生成
  1. 在Canvas中创建Button和Text
  2. 写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
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值