Accessing Components

  The most common case is where a script needs access to other Components attached to the same GameObject.A Component is actually an instance of a class so the first step is to get a reference to the Component instance you want to work with. This is done with theGetComponent function. Typically, you want to assign the Component object to a variable, which is done in C# using the following syntax:

  

  Once you have a reference to a Component instance, you can set the values of its properties much as you would in the Inspector:

  

  An extra feature that is not available in the Inspector is the possibility of calling functions on Component instances:

  
Finding Objects by Name or Tag
  It is always possible to locate GameObjects anywhere in the scene hierarchy as long as you have some information to identify them. Individual objects can be retrieved by name using the GameObject.Find function:
  
  An object or a collection of objects can also be located by their tag using the GameObject.FindWithTag and GameObject.FindGameObjectsWithTag functions:
 
  
 
   

Controlling GameObjects Using Components的更多相关文章

  1. Unity3D用户手册

    Unity Manual 用户手册 Welcome to Unity. 欢迎使用Unity. Unity is made to empower users to create the best int ...

  2. 从Unity引擎过度到Unreal4引擎(最终版)

    原文地址:http://demo.netfoucs.com/u011707076/article/details/44036839 前言 寒假回家到现在已经有十多天了,这些天回家不是睡就是吃....哎 ...

  3. Unity3D开发之查找面板上某个脚本(包括Missing)

    原地址:http://blog.csdn.net/lihandsome/article/details/24265411 有时候我们需要知道某个脚本在场景上面哪里用到,或者那个脚本被删除了但又没有把相 ...

  4. Unity 4.3 2D 教程:新手上路

    这篇文章译自 Christopher LaPollo 先生的 Unity 4.3 2D 教程的第一部分 Unity 4.3 2D Tutorial: Getting Started 感谢这套优秀教程的 ...

  5. Unity 5 Game Optimization (Chris Dickinson 著)

    1. Detecting Performance Issues 2. Scripting Strategies 3. The Benefits of Batching 4. Kickstart You ...

  6. Unity3D开发之查找面板上某个脚本(包含Missing)

    有时候我们须要知道某个脚本在场景上面哪里用到,或者那个脚本被删除了但又没有把相关游戏场景的关联东西删掉,那样我们就要一个脚本来查找一下了: PS:以下两个脚本都要放到assets/Editor以下哦. ...

  7. Unity资源管理机制

    转载:https://unity3d.com/learn/tutorials/topics/best-practices/assets-objects-and-serialization Assets ...

  8. General-Purpose Operating System Protection Profile

    1 Protection Profile Introduction   This document defines the security functionality expected to be ...

  9. unity如何查找某个脚本挂在了哪些物体上

    在开发中往往会遇到一个问题:不知道整个场景中究竟有哪些物体挂载了某一个脚本.如果挨个查找太麻烦了,下面有一种方法可以快速找到解决这个问题. 在unity的Window里有一项Editor tests ...

随机推荐

  1. NPOI导出Excel表功能实现(多个工作簿)(备用)

    Excel生成操作类: 代码 using System; using System.Collections.Generic; using System.Text; using System.IO; u ...

  2. 51nod1711 平均数

    二分答案.check有多少个区间的平均数>xbi=ai-x;将sm离散化.然后logn求出有多少个小于sm[i].类似于求逆序对的思路. 一直WA一个点...所以我就下载数据特判了TAT #in ...

  3. UVALive 3415 Guardian of Decency(二分图的最大独立集)

    题意:老师在选择一些学生做活动时,为避免学生发生暧昧关系,就提出了四个要求.在他眼中,只要任意两个人符合这四个要求之一,就不可能发生暧昧.现在给出n个学生关于这四个要求的信息,求老师可以挑选出的最大学 ...

  4. js二级下拉被flash档住的解决办法

    在<object></object>及以内的代码加入到<script>标签对内 <script language="javascript" ...

  5. [转载] FFMpeg的码率控制

    mediaxyz是一位研究ffmpeg有三年的高人了,这几天一直在折腾ffmpeg中的x264,就是不知道该如何控制码率,主要是参数太多,也不知道该如何设置,在google上search了一下,这方面 ...

  6. IOS设计模式之三(适配器模式,观察者模式)

    本文原文请见:http://www.raywenderlich.com/46988/ios-design-patterns. 由 @krq_tiger(http://weibo.com/xmuzyq) ...

  7. 四 AndEngine 画线

    package com.example.AndEngineExample02; import org.anddev.andengine.engine.Engine;import org.anddev. ...

  8. 使用JQuery Mobile实现手机新闻浏览器

    jQuery Mobile项目是jQuery项目下的在移动开发方面的又一力作,在本文中,笔者将带你一步步更深入学习使用jQuery Mobile框架去实现一个能在android手机上运行的新闻浏览器, ...

  9. 请教下 Yii 和 Ajax来验证用户名是否存在

    添加一个 Custom, Model页面: CustomForm中: public function rules() { // 使用ajax 校验数据 return array( array('nam ...

  10. FontMetrics ----- 绘制文本,获取文本高度

    Canvas 绘制文本时,使用FontMetrics对象,计算位置的坐标. public static class FontMetrics { /** * The maximum distance a ...