버튼을 눌러 토글로 UI 메뉴를 active/deactive 변경하기.
1. 버튼들 생성.
2. <MenuOpen.c#> 스크립트 생성.
- 여기서 추가되는 gameObject는 버튼이 눌렸을때 visible/invisible 되는 하위 버튼들임.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MenuOpen : MonoBehaviour {
public GameObject mainButton;
public GameObject reStartButton;
public void showMenu()
{
bool isActive = mainButton.activeSelf;
mainButton.SetActive(!isActive);
reStartButton.SetActive(!isActive);
}
}
|
cs |
3. 버튼(visible/invisible 의 기준이 되는 버튼)에 스크립트 추가 후 아래와 같이 설정.

4. 하위 버튼들 deActive 설정.
끗!!
결과물
'개발 > Unity' 카테고리의 다른 글
[Unity] cannot click button (0) | 2019.05.23 |
---|---|
[Unity] UICamera (1) | 2019.05.22 |
[Unity] occlusion culling (0) | 2019.05.16 |
[Unity] Screen position out of view frustum (screen pos 0.000000, 0.000000, 2000.000000) (Camera rect 0 0 1019 744) (0) | 2019.05.09 |
[Unity] particle size control (0) | 2019.05.09 |