当前位置:网站首页>Unity脚本API—GameObject游戏对象、Object 对象
Unity脚本API—GameObject游戏对象、Object 对象
2022-07-04 14:13:00 【@夜魅】
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// GameObject 游戏对象
/// </summary>
public class GameObjectDemo : MonoBehaviour
{
private void OnGUI()
{
//在场景中物体激活状态(物体实际激活状态)
//this.gameObject.activeInHierarchy;
//物体自身激活状态(物体在Inspector面板中的状态)
//this.gameObject.activeSelf
//设置物体启用/禁用
//this.gameObject.SetActive();
if (GUILayout.Button("添加光源"))
{
//this.gameObject.AddComponent<Light>();
//创建物体
GameObject lightGO= new GameObject();
//添加组件
Light light = lightGO.AddComponent<Light>();
light.color = Color.red;
light.type = LightType.Point;
}
//在场景中根据名称查找物体(慎用)
//GameObject.Find("游戏对象名称");
//获取所有使用该标签的物体
GameObject[] allEnemy = GameObject.FindGameObjectsWithTag("Enemy");
foreach (GameObject enemy in allEnemy)
{
Debug.Log("Enemy"+enemy.name);
}
//获取使用该标签的物体(单个)
GameObject playerGo = GameObject.FindWithTag("Player");
Debug.Log("Player"+playerGo.name);
//Object
//根据类型查找对象
Object.FindObjectOfType<MeshRenderer>();
FindObjectsOfType<MeshRenderer>();
//销毁对象
//Object.Destroy
//练习:查找血量最低的敌人
}
}
边栏推荐
- Guitar Pro 8win10 latest guitar learning / score / creation
- I plan to teach myself some programming and want to work as a part-time programmer. I want to ask which programmer has a simple part-time platform list and doesn't investigate the degree of the receiv
- Go zero micro service practical series (IX. ultimate optimization of seckill performance)
- %S format character
- MySQL组合索引(多列索引)使用与优化案例详解
- 直播预告 | PostgreSQL 内核解读系列第二讲:PostgreSQL 体系结构
- Openresty current limiting
- Preliminary exploration of flask: WSGI
- Building intelligent gray-scale data system from 0 to 1: Taking vivo game center as an example
- Temperature control system based on max31865
猜你喜欢
直播预告 | PostgreSQL 内核解读系列第二讲:PostgreSQL 体系结构
31年前的Beyond演唱会,是如何超清修复的?
力扣刷题01(反转链表+滑动窗口+LRU缓存机制)
Dialogue with ye Yanxiu, senior consultant of Longzhi and atlassian certification expert: where should Chinese users go when atlassian products enter the post server era?
MySQL组合索引(多列索引)使用与优化案例详解
Expose Ali's salary and position level
Helix Swarm中文包发布,Perforce进一步提升中国用户体验
lnx 高效搜索引擎、FastDeploy 推理部署工具箱、AI前沿论文 | ShowMeAI资讯日报 #07.04
LeetCode 1200 最小絕對差[排序] HERODING的LeetCode之路
Korean AI team plagiarizes shock academia! One tutor with 51 students, or plagiarism recidivist
随机推荐
从0到1建设智能灰度数据体系:以vivo游戏中心为例
selenium 浏览器(2)
Cann operator: using iterators to efficiently realize tensor data cutting and blocking processing
Redis publish and subscribe
Ranking list of databases in July: mongodb and Oracle scores fell the most
Enter the width!
.Net 应用考虑x64生成
They are all talking about Devops. Do you really understand it?
局部修改-渐进型开发
[differential privacy and data adaptability] differential privacy code implementation series (XIV)
selenium 元素交互
SAIC Maxus officially released its new brand "mifa", and its flagship product mifa 9 was officially unveiled!
输入宽度!
Temperature control system based on max31865
力扣刷题01(反转链表+滑动窗口+LRU缓存机制)
华为云数据库DDS产品深度赋能
CentOS 6.3 下 PHP编译安装JSON模块报错解决
都在说DevOps,你真正了解它吗?
Memory management summary
Helix Swarm中文包发布,Perforce进一步提升中国用户体验