using System.Collections;
using System.Collections.Generic;
using UnityEngine;
///<summary>
///
///</summary>
public class GameObjectDemo : MonoBehaviour
{
//GameObject:场景中的所有实体的类型(即Hierarchy面板)
// 包含isStatic,layer,scene,tag,transform变量
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
private void OnGUI()
{
this.gameObject.activeInHierarchy; //场景中的物体是否激活(物体实际激活状态,即Hierarchy面板)
this.gameObject.activeSelf(true);//物体自身激活状态(即Inspector面板中的状态)
设置物体禁用和启用
this.gameObject.SetActive(true);
if (GUI.Button(new Rect(0, 100, 50, 30), "light"))
{
//Light light = new Light();//新建但不能使用,无法用于物体
Light light = this.gameObject.AddComponent<Light>();//方法内部会生成light组件
light.color = Color.red;
light.type = LightType.Point;
}
GameObject[] allEnemy= GameObject.FindGameObjectsWithTag("enemy");//获取所有使用该标签的物体
GameObject playGo = GameObject.FindWithTag("player");//获取使用该标签的物体(单个)
Object
Object.FindObjectsOfType<MeshRenderer>();//根据类型查找对象
FindObjectsOfType<MeshRenderer>();
}
}
unity中Gameobject组件
猜你喜欢
转载自blog.csdn.net/weixin_51235620/article/details/115298457
今日推荐
周排行