1、创建物体

2、加载物体

3、寻找物体

4、添加脚本

1、创建物体

  GameObject go;
// Use this for initialization
void Start () {
go = new GameObject("New");
}

find 方法查找对应的组件(找到第一个匹配的组件)

  GameObject go;
GameObject goLight;
Light light;
// Use this for initialization
void Start () {
go = new GameObject("New");
goLight = GameObject.Find("Directional Light");//页面组件
light = goLight.GetComponent<Light>();
light.color = Color.red;
}

两个灯光

    GameObject go;
GameObject goLight;
GameObject goLight2;
Light light1;
Light light2;
// Use this for initialization
void Start () {
go = new GameObject("New");
goLight = GameObject.Find("1/2/DirectionalLight");
light1 = goLight.GetComponent<Light>();
light1.color = Color.red; goLight2 = GameObject.Find("1 (1)/2/DirectionalLight");
light2 = goLight2.GetComponent<Light>();
light2.color = Color.green;
}

第二种写法(两个灯光)

    public Transform transRoot;

    Transform translight1;
Transform translight2; // Use this for initialization
void Start () { FindChild(transRoot,"RLight",ref translight1);
FindChild(transRoot, "GLight", ref translight2);
translight1.GetComponent<Light>().color = Color.red;
translight2.GetComponent<Light>().color = Color.green;
} /// <summary>
/// 寻找物体
/// </summary>
/// <param name="trans">作为父物体的transform</param>
/// <param name="findName">寻找的物体名称</param>
/// <param name="_trans">找到的物体</param>
void FindChild(Transform trans,string findName,ref Transform _trans)
{
if (trans.name.Equals(findName))
{
_trans = trans.transform;
return;
} if (trans.childCount!=)
{
for (int i = ,lenght=trans.childCount; i < lenght; i++)
{
FindChild(trans.GetChild(i),findName,ref _trans);
}
}
}

2、Awake() & Start()   做初始化

 Update、LateUpdate、FixedUpdate   更新逻辑

   GetComponent 找到其他脚本

   Gameobject.Find 找到其他物体

3、游戏输入

在Edit → Project Settings → Input 设置游戏输入

在脚本中利用Input类来检测输入状态

Input.GetAxis 返回的值是 -1到1之间,0表示没有输入

Unity3d 常用的方法的更多相关文章

  1. WebAPi添加常用扩展方法及思维发散

    前言 在WebAPi中我们通常需要得到请求信息中的查询字符串或者请求头中数据再或者是Cookie中的数据,如果需要大量获取,此时我们应该想到封装一个扩展类来添加扩展方法,从而实现简便快捷的获取. We ...

  2. StringUtils中的常用的方法

    org.apache.commons.lang.StringUtils中常用的方法,这里主要列举String中没有,且比较有用的方法: 1. 检查字符串是否为空: static boolean isB ...

  3. JOptionPane类提示框的一些常用的方法

    JOptionPane类提示框的一些常用的方法 XMLOracleSwing 最近在做swing程序中遇到使用消息提示框的,JOptionPane类其中封装了很多的方法. 很方便的,于是就简单的整理了 ...

  4. 常用js方法

    function dateGetter(name, size, offset, trim) { offset = offset || 0; return function (date) { var v ...

  5. jQuery操作Table tr td常用的方法

    虽然现在DIV+CSS进行页的布局大行其道,但是很多地方使用table还是有很多优势,用table展示数据是比较方便的,下面汇总了jQuery操作Table tr td常用的方法,熟记这些操作技巧,下 ...

  6. iOS常用公共方法

      iOS常用公共方法 字数2917 阅读3070 评论45 喜欢236 1. 获取磁盘总空间大小 //磁盘总空间 + (CGFloat)diskOfAllSizeMBytes{ CGFloat si ...

  7. Unity3d中Update()方法的替身

    在网上看到一些资料说Unity3d的Update方法是如何如何不好,影响性能.作为一个菜鸟,之前我还觉得挺好用的,完全没用什么影响性能的问题存在.现在发现确实有很大的问题,我习惯把一大堆检测判断放在U ...

  8. org.apache.commons.lang.StringUtils中常用的方法

    org.apache.commons.lang.StringUtils中常用的方法,这里主要列举String中没有,且比较有用的方法: 1. 检查字符串是否为空: static boolean isB ...

  9. 常用js方法整理common.js

    项目中常用js方法整理成了common.js var h = {}; h.get = function (url, data, ok, error) { $.ajax({ url: url, data ...

随机推荐

  1. Linux中Readlink命令

    原文地址:http://blog.csdn.net/liangxiaozhang/article/details/7356829 readlink是Linux系统中一个常用工具,主要用来找出符号链接所 ...

  2. python3内置函数大全(顺序排列)

    python3内置函数大全 内置函数 (1)abs(),   绝对值或复数的模 1 print(abs(-6))#>>>>6 (2)all() 接受一个迭代器,如果迭代器的所有 ...

  3. 如何减少block的嵌套层次?

    1.首先了解一个概念 函数式反应型编程(FRP) —— 实时互动应用开发的新思路 http://www.infoq.com/cn/articles/functional-reactive-progra ...

  4. 轮廓的查找、表达、绘制、特性及匹配(How to Use Contour? Find, Component, Construct, Features & Match)

    http://www.cnblogs.com/xrwang/archive/2010/02/09/HowToUseContour.html 作者:王先荣 前言    轮廓是构成任何一个形状的边界或外形 ...

  5. eigen 笔记1

    c++ 的 eigen 类似于 python 的 numpy, 还有一个类似的库是 Armadillo, 当然还有 opencv. Armadillo 与 matlab 在函数名称上更接近, 但是 T ...

  6. Python os.path.dirname(__file__) 与 Python os.path.abspath(__file__) 与 os.system() 函数

    Python  os.path.dirname(__file__) 与 Python os.path.abspath(__file__) 的区别 os.path.abspath(__file__)返回 ...

  7. jmeter bean shell断言加密的响应信息(加密接口测试二)

    断言加密的响应信息 1.在http请求-->添加-->断言-->bean shell 断言 import com.changfu.EncryptAndDecryptInterface ...

  8. 一个新人对于DW标签的理解

    标签呢分为 一.一般标签 一般标签内又分为 ① 格式控制标签 格式控制标签的书写格式是: <font .....></font>  以font为开头以/font为结尾 font ...

  9. mongodb权限

    1.在无密码模式下添加账号 db.createUser( { user: "user", pwd: "pwd", roles: [ { role: " ...

  10. zw版【转发·台湾nvp系列Delphi例程】HALCON MirrorImage2

    zw版[转发·台湾nvp系列Delphi例程]HALCON MirrorImage2 procedure TForm1.Button1Click(Sender: TObject);var op: HO ...