202202042317Unity如何找一個inactive的物件

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ItemEdit : MonoBehaviour
{
	public GameObject parentPanel;

	public void ItemEditAction()
	{
		//parentPanel = GameObject.Find("PanelItemInputParent");

		PanelItemInputParent[] activeAndInactive = GameObject.FindObjectsOfType(true);
		
		parentPanel = activeAndInactive[0].gameObject;
		parentPanel.SetActive(true);
	}
}


GameObject.Find找不到inactive的物件,必須在此物件先賦予一個script(component),再用GameObjet.FindObjectOfType去找,再獲得它的gameObject。

Reference:

How to find inactive objects using GameObject.Find(" ") in Unity3D?

PS:其實還有一Button的Click事件,呼叫一個inactive的GameObject,將它設成Active。

回應
Blogger ADS
kiss radio
關鍵字
    沒有新回應!