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


/// 禁用物体,启用物体,创建物体,添加组件,查找物体,销毁物体
///

public class GameObjectDemo : MonoBehaviour
{
private void OnGUI()
{
//在场景中物体激活状态(物体实际激活状态)
//this.gameObject.activeInHierarchy;
//物体自身激活状态(物体在Inspector面板中的状态)
//this.gameObject.activeSelf;
//设置物体启用/禁用
//this.gameObject.SetActive();

    if (GUILayout.Button("添加光源"))
    {
        //创建物体
        GameObject LightGO = new GameObject();
        //添加组件
        Light light = this.gameObject.AddComponent<Light>();
        light.color = Color.green;
        light.type = LightType.Point;
    }

    //在场景中根据名称查找物体(慎用)
    //GameObject.Find("游戏对象名");

    //获取所有使用改标签的物体
    GameObject [] allEnemy = GameObject .FindGameObjectsWithTag ("Enemy");
    //获取使用改标签的物体(单个)
    GameObject playerGO = GameObject.FindWithTag("Player");

    //object
    //根据类型查找对象
    //Object. FindObjectOfType<MeshRenderer>();
    //FindObjectsOfType<MeshRenderer>();
    //销毁对象
    //Object.Destroy(this.gameObject ,5);//5秒后销毁
}

}