zoukankan      html  css  js  c++  java
  • 【unity3d study ---- 麦子学院】---------- unity3d常用组件及分析 ---------- 组件的使用

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

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

     1 using UnityEngine;
     2 using System.Collections;
     3 
     4 public class ComponentUse : MonoBehaviour {
     5 
     6     // Use this for initialization
     7     void 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     }
    27     
    28     // Update is called once per frame
    29     void Update () {
    30     
    31     }
    32 }
  • 相关阅读:
    前端中不同页面之间传递参数的几种方式
    js中的闭包内存图
    【JavaScript基础】js中关于声明提前的几个误区
    【面试】前端面试题
    js继承的几种方式
    原生Ajax实现异步交互
    git基本使用
    一个简单的SSM框架实例(使用IDEA)
    高安全性的JavaScript
    高性能的JavaScript
  • 原文地址:https://www.cnblogs.com/dudu580231/p/5952972.html
Copyright © 2011-2022 走看看