Activating GameObjects
Проверено с версией:: 4
-
Сложность: Базовая
How to handle the active status of gameobjects in the scene, both independently and within Hierarchies, using SetActive and activeSelf / activeInHierarchy.


Activating GameObjects
Базовая Scripting
ActiveObjects
Code snippet
using UnityEngine;
using System.Collections;
public class ActiveObjects : MonoBehaviour
{
void Start ()
{
gameObject.SetActive(false);
}
}
#pragma strict
function Start ()
{
gameObject.SetActive(false);
}
import UnityEngine
import System.Collections
public class ActiveObjects(MonoBehaviour):
private def Start():
gameObject.SetActive(false)
CheckState
Code snippet
using UnityEngine;
using System.Collections;
public class CheckState : MonoBehaviour
{
public GameObject myObject;
void Start ()
{
Debug.Log("Active Self: " + myObject.activeSelf);
Debug.Log("Active in Hierarchy" + myObject.activeInHierarchy);
}
}
#pragma strict
public var myObject :GameObject;
function Start ()
{
Debug.Log("Active Self: " + myObject.activeSelf);
Debug.Log("Active in Hierarchy" + myObject.activeInHierarchy);
}
import UnityEngine
import System.Collections
public class CheckState(MonoBehaviour):
public myObject as GameObject
private def Start():
Debug.Log(('Active Self: ' + myObject.activeSelf))
Debug.Log(('Active in Hierarchy' + myObject.activeInHierarchy))
Дополнительная документация
- Set Active (Справка по скриптам)
- Active Self (Справка по скриптам)
- Active In Hierarchy (Справка по скриптам)
- Deactivating GameObjects (Руководство)