Post

반응형

클릭할 때마다 다음 텍스트가 나온다


using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.UI;


public class TextPrint : MonoBehaviour {


    const int TEXT_MAX_COUNT = 5;

    string[] tempArr;

    Text strText;

    int nTextIndex = 0;


    // Use this for initialization

    void Awake()

    {

        tempArr = new string[TEXT_MAX_COUNT];

        tempArr[0] = "첫번째 텍스트";

        tempArr[1] = "두번째 텍스트";

        tempArr[2] = "세번째 텍스트";

        tempArr[3] = "네번째 텍스트";

        tempArr[4] = "다섯번째 텍스트";


        // 이름으로 게임오브젝트 찾기

        GameObject textMessage = GameObject.Find("TextMessage");

        // 게임오브젝트의 컴포넌트 가져오기

        strText = textMessage.GetComponent<Text>();

    }

    void Start ()

    {

}

// Update is called once per frame

void Update ()

    {

    

    }


    public void OnTextButtonClick()

    {

        Debug.Log("클릭");

        if (TEXT_MAX_COUNT == nTextIndex)

        {

            nTextIndex = 0;

        }


        strText.text = tempArr[nTextIndex];

        ++nTextIndex;

    }

}



반응형
▲ top