当前位置:网站首页>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
//练习:查找血量最低的敌人
}
}
边栏推荐
- Helix Swarm中文包发布,Perforce进一步提升中国用户体验
- Summer Review, we must avoid stepping on these holes!
- 局部修改-渐进型开发
- TechSmith Camtasia studio 2022.0.2 screen recording software
- openresty 限流
- [local differential privacy and random response code implementation] differential privacy code implementation series (13)
- 十六进制
- Unity update process_ Principle of unity synergy
- 对话龙智高级咨询顾问、Atlassian认证专家叶燕秀:Atlassian产品进入后Server时代,中国用户应当何去何从?
- hexadecimal
猜你喜欢
leecode学习笔记-约瑟夫问题
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
Weibo and Huya advance into interest communities: different paths for peers
Leecode learning notes - Joseph problem
Five minutes per day machine learning: use gradient descent to complete the fitting of multi feature linear regression model
.Net 应用考虑x64生成
Memory management summary
深度学习 神经网络的优化方法
【大连理工大学】考研初试复试资料分享
都在说DevOps,你真正了解它吗?
随机推荐
Implementation of web chat room
从0到1建设智能灰度数据体系:以vivo游戏中心为例
近一亿美元失窃,Horizon跨链桥被攻击事件分析
LeetCode 1200 最小绝对差[排序] HERODING的LeetCode之路
Live broadcast preview | PostgreSQL kernel Interpretation Series II: PostgreSQL architecture
Kubernets pod exists finalizers are always in terminating state
Introduction to modern control theory + understanding
MySQL学习笔记——数据类型(数值类型)
Leetcode 1200 minimum absolute difference [sort] the way of leetcode in heroding
Leetcode 1200 minimum absolute difference [sort] The Path of leetcode for heroding
Width accuracy
[local differential privacy and random response code implementation] differential privacy code implementation series (13)
.Net之延迟队列
CentOS 6.3 下 PHP编译安装JSON模块报错解决
Go zero micro service practical series (IX. ultimate optimization of seckill performance)
Align left and right!
Five minutes per day machine learning: use gradient descent to complete the fitting of multi feature linear regression model
重排数组
EventBridge 在 SaaS 企业集成领域的探索与实践
.Net 应用考虑x64生成