激活游戏对象

Tutorial

Beginner

+0XP

5 mins

208

Unity Technologies

激活游戏对象

如何使用 SetActive 和 activeSelf/activeInHierarchy 单独处理以及在层级视图中处理场景内部游戏对象的活动状态。

本教程包含在“初级编程”项目中。

上一教程:启用和销禁用游戏对象

下一教程:Translate 和 Rotate

Languages available:

1. 激活游戏对象

ActiveObjects

using UnityEngine;
using System.Collections;

public class ActiveObjects : MonoBehaviour
{
    void Start ()
    {
        gameObject.SetActive(false);
    }
}

CheckState

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);
    }
}

Complete this Tutorial