Unity
[Unity] 배열/Tag/Foreach로 간단하게 많은 object Turn On/Off 하기
Guk-blog
2019. 4. 22. 12:46
728x90
반응형
정말 간단함.
먼저 해당 오브젝트 들에게 Tag를 달아 준다.


그리고 받을 게임 오브젝트 배열 변수 선언
GameObejct[] _GObjects;
배열 붙이기
--start()---
_GObjects = GameObject.FindGameObjectsWithTag("Rail");
FindGameObjectsWithTag는 배열
FindGameObjectWithTag는 하나
Object뒤에 -s 주의
그리고 오브젝트를 켜고 끌 부분에서
foreach(GameObject rail in _GObjects){
rail.GetComponent().enabled = true;//or =false;
}
끗
728x90
반응형