关闭

unity3d开源Ultimate MMORPG插件技术文档渣翻译第4页

标签: MMORPGunity3d文档网络游戏插件
231人阅读 评论(0) 收藏 举报
分类:


Page4

 

It has this syntax: if(<condition>){ <Do something>}.

它的语法如下:if(<条件>){<执行>}

Previous examples were too boring, so let’s create an NPC Cube. ThePlayer will be able to set its name and its side: a friend or an enemy. Socreate new C# script and paste this (be sure you understand how it happens):

   之前的例子太枯燥了。让我们来创建一个NPC立方体。玩家将能设置他的名字和选边:友军或敌军。那来创建一个新的C#脚本并粘贴它吧(务必要理解它是如何产生的):

 

 

C# code:

public string NPC_name;  // This variable is public, so it can be setfrom the inspector

                      // 此变量是公用的,所以它可以在检视面板(inspector)设置

public bool enemy;      // Also set from inspector. False -friend, true – enemy

                     // 可以在检视面板设置

 

void Start(){

gameObject.name = NPC_name; // Set GameObject name to the variable

                           //赋值游戏对象名称给变量

 if(enemy==false){           // Friend   友军

        // gameObject.renderer.material.color =Color.green;   //此行代码unity3d5.0不能用

        gameObject.GetComponent<Renderer>().material.color = Color.green;  //5.0代码

 }else{                         // Another way (enemy)另一面(敌军)

//gameObject.renderer.material.color = Color.red;       //此行代码unity3d5.0不能用

gameObject.GetComponent<Renderer>().material.color =Color.green;   //5.0代码        

 

 }

}

Copy&paste this. Then create a Cube, let the camera see it andadd this script.If you make all right, in the «Play» mode the Cube’s color andits name in Hierarchy will depend on the variables’ values that you can set inthe inspector.

   复制并粘贴此脚本。然后创造一个立方体,让摄像机对准它并添加此脚本。如果你所做一切都是正确的,在层级面板(Hierarchy)Play模型中立方体的颜色和名字将决定于变量值,而此变量你可以在检视面板(inspector)中设置。

 

“Arrays”        “数组”

Sometimes you will need a thing where you can “put” variables like abag. Forexample, bag’s items. And then “Arrays” will help.There are a few types of arrays.They are the similar to the types of variables— int, float, string, bool and etc. Also“ArrayList” exists but we won’t have a good look at them.

有时你需要一个能存放变量的容器。比如袋子。然后数组将提供帮助。这里有一些数组的类型。他们和变量很像—整型,浮点型,字符串型,布尔型等等。因此“列表”存在但我们不必深究它们。

An array declares like <type>[ ] <name>. There is anexample of array’s declaring and the working with it.

一组数组被可以按< 类型>[]<名称>这样的形式声明。这里可举个数组声明和执行的例子。

C# code:

 

public string [ ] bag;                        // It’s public, so set the values in theinspector

void Start(){

foreach(string item in bag){               // It is “foreach” cycle. For each element in  

  Debug.Log(string);                     // array “bag”script will dowhat is written after

}                                      // “{” andbefore”}” (Debug.Log())

                                       //并不懂此段程序

}                        

 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:2157次
    • 积分:78
    • 等级:
    • 排名:千里之外
    • 原创:0篇
    • 转载:0篇
    • 译文:6篇
    • 评论:0条
    文章分类
    文章存档