100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > 【unity3d study ---- 麦子学院】---------- unity3d常用组件及分析 ---------- 组件的使用...

【unity3d study ---- 麦子学院】---------- unity3d常用组件及分析 ---------- 组件的使用...

时间:2022-08-15 05:05:06

相关推荐

【unity3d study ---- 麦子学院】----------  unity3d常用组件及分析 ----------  组件的使用...

unity中的组件可以可视化添加,删除

unity 中组件也可以通过代码添加

1 using UnityEngine; 2 using System.Collections; 3 4 public class ComponentUse : MonoBehaviour { 5 6// Use this for initialization 7void Start () { 8 9 // add component 添加10 gameObject.AddComponent<ParticleSystem> (); // 效率是最高的 最好的11 // gameObject.AddComponent (typeof(ParticleSystem)); // c# 的反射机制 不推荐12 // gameObject.AddComponent ("ParticleSystem"); // 字符串 类名 13 14 // query component 查询15 ParticleSystem ps = gameObject.GetComponent<ParticleSystem> (); // 获取 自己的这个组件16 ParticleSystem[] pss = gameObject.GetComponents<ParticleSystem>(); // 获取 自己的所有这个组件17 ParticleSystem ps_child = gameObject.GetComponentInChildren<ParticleSystem> (); // 获取 第一个找到的孩子身上的这个组件 并不是规律的18 ParticleSystem[] pss_child = gameObject.GetComponentsInChildren<ParticleSystem> (); // 获取所有孩子身上的这个组件19 ParticleSystem[] pss_parent = gameObject.GetComponentsInParent<ParticleSystem> (); // 获取所有父节点上的这个组件20 21 // delete component 删除22 if (ps)23 Destroy (ps); // 其实 unity 里面有判断是否为空,但是我感觉还是最好在外面判断一下24 25 26}2728// Update is called once per frame29void Update () {3031}32 }

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。