12.16 토글 버튼 만들기

C#/과제 2019. 12. 16. 17:53
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class UIToggleBtnMessage : UIToggleBtn
{
    public InputField inputField;    
    public override void Start()
    {
 
        btn.onClick.AddListener(() =>
        {
            toggle = !toggle;
            if (toggle)
            {
                string text = this.inputField.textComponent.text;
                image.gameObject.SetActive(toggle);
                this.image.gameObject.transform.GetChild(0).GetComponent<Text>().text = text;
                Debug.Log(text);
                this.gameObject.transform.GetChild(0).GetComponent<Text>().text = "Hide";
 
            }
            else
            {
                image.gameObject.SetActive(toggle);
                this.gameObject.transform.GetChild(0).GetComponent<Text>().text = "Show";
            }
        });                
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UIToggleBtn : MonoBehaviour
{
    public Button btn;
    public Image image;
    public bool toggle = false;
    // Start is called before the first frame update
    public virtual void Start()
    {
        btn.onClick.AddListener(() =>
        {
            toggle = !toggle;
            if(toggle)
            {
                image.gameObject.SetActive(toggle);
                this.gameObject.transform.GetChild(0).GetComponent<Text>().text = "Hide";
 
            }
            else
            {
                image.gameObject.SetActive(toggle);
                this.gameObject.transform.GetChild(0).GetComponent<Text>().text = "Show";
            }
        });
    }
 
    // Update is called once per frame
    void Update()
    {
        
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 

'C# > 과제' 카테고리의 다른 글

2019.12.08 드래곤플라이트 과제  (0) 2019.12.08
: