当前位置:网站首页>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
//练习:查找血量最低的敌人
}
}
边栏推荐
- Ali was laid off employees, looking for a job n day, headhunters came bad news
- Ranking list of databases in July: mongodb and Oracle scores fell the most
- How did the beyond concert 31 years ago get super clean and repaired?
- unity update 协程_Unity 协程的原理
- MySQL学习笔记——数据类型(数值类型)
- 进制形式
- Deep learning neural network case (handwritten digit recognition)
- Quick introduction to automatic control principle + understanding
- PLC模拟量输入 模拟量转换FC S_ITR (CODESYS平台)
- 音视频技术开发周刊 | 252
猜你喜欢
Preliminary exploration of flask: WSGI
Live broadcast preview | PostgreSQL kernel Interpretation Series II: PostgreSQL architecture
Implementation of macro instruction of first-order RC low-pass filter in signal processing (easy touch screen)
函数计算异步任务能力介绍 - 任务触发去重
Kubernets Pod 存在 Finalizers 一直处于 Terminating 状态
Redis的4种缓存模式分享
Helix Swarm中文包发布,Perforce进一步提升中国用户体验
Force button brush question 01 (reverse linked list + sliding window +lru cache mechanism)
直播预告 | PostgreSQL 内核解读系列第二讲:PostgreSQL 体系结构
How to match chords
随机推荐
局部修改-渐进型开发
IO流:节点流和处理流详细归纳。
Kubernets Pod 存在 Finalizers 一直处于 Terminating 状态
%s格式符
产品好不好,谁说了算?Sonar提出分析的性能指标,帮助您轻松判断产品性能及表现
How to rapidly deploy application software under SaaS
Five minutes of machine learning every day: how to use matrix to represent the sample data of multiple characteristic variables?
智能客服赛道:网易七鱼、微洱科技打法迥异
Align left and right!
[local differential privacy and random response code implementation] differential privacy code implementation series (13)
LeetCode 1200 最小绝对差[排序] HERODING的LeetCode之路
unity update 协程_Unity 协程的原理
Ffmpeg Visual Studio development (IV): audio decoding
Redis publier et s'abonner
Redis 發布和訂閱
Halcon knowledge: NCC_ Model template matching
Implementation of macro instruction of first-order RC low-pass filter in signal processing (easy touch screen)
lnx 高效搜索引擎、FastDeploy 推理部署工具箱、AI前沿论文 | ShowMeAI资讯日报 #07.04
Implementation of web chat room
TechSmith Camtasia studio 2022.0.2 screen recording software