当前位置:网站首页>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
//练习:查找血量最低的敌人
}
}
边栏推荐
- 31年前的Beyond演唱会,是如何超清修复的?
- LeetCode 58. 最后一个单词的长度
- On the implementation plan of MySQL explain
- hexadecimal
- Deep learning 7 transformer series instance segmentation mask2former
- Force button brush question 01 (reverse linked list + sliding window +lru cache mechanism)
- Guitar Pro 8win10 latest guitar learning / score / creation
- 音视频技术开发周刊 | 252
- Openresty redirection
- Korean AI team plagiarizes shock academia! One tutor with 51 students, or plagiarism recidivist
猜你喜欢
![Leetcode 1200 minimum absolute difference [sort] the way of leetcode in heroding](/img/4a/6763e3fbdeaf9de673fbe8eaf96858.png)
Leetcode 1200 minimum absolute difference [sort] the way of leetcode in heroding

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

Why do domestic mobile phone users choose iPhone when changing a mobile phone?

Redis publish and subscribe
Redis sentinel mode realizes one master, two slave and three Sentinels

Helix Swarm中文包发布,Perforce进一步提升中国用户体验

Go zero micro service practical series (IX. ultimate optimization of seckill performance)

Weibo and Huya advance into interest communities: different paths for peers
![[local differential privacy and random response code implementation] differential privacy code implementation series (13)](/img/fe/f6a13dcf31ac67633ee5a59d95149d.jpg)
[local differential privacy and random response code implementation] differential privacy code implementation series (13)

对话龙智高级咨询顾问、Atlassian认证专家叶燕秀:Atlassian产品进入后Server时代,中国用户应当何去何从?
随机推荐
Redis sentinel mode realizes one master, two slave and three Sentinels
从0到1建设智能灰度数据体系:以vivo游戏中心为例
Align left and right!
【学习笔记】拟阵
Openresty current limiting
夜天之书 #53 Apache 开源社群的“石头汤”
微博、虎牙挺进兴趣社区:同行不同路
js平铺数据查找叶子节点
每周招聘|高级DBA年薪49+,机会越多,成功越近!
PXE网络
2022 financial products that can be invested
Width and alignment
华为云数据库DDS产品深度赋能
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?
Flutter reports an error no mediaquery widget ancestor found
Graduation season - personal summary
TechSmith Camtasia studio 2022.0.2 screen recording software
CentOS 6.3 下 PHP编译安装JSON模块报错解决
Ffmpeg Visual Studio development (IV): audio decoding
They are all talking about Devops. Do you really understand it?