查看: 2094|回复: 0
打印 上一主题 下一主题

[Unity 组件参考手册]脚本概念之什么是标签

[复制链接]
.    

3797

主题

11

听众

5万

积分

首席设计师

Rank: 8Rank: 8

纳金币
32328
精华
41

活跃会员 优秀版主 荣誉管理 论坛元老

跳转到指定楼层
楼主
发表于 2013-2-26 17:39:47 |只看该作者 |倒序浏览
A Tag is a word which you link to one or more GameObjects. For instance, you might define Player and Enemy Tags for player-controlled characters and non-player characters respectively; a Collectable Tag could be defined for items the player can collect in the Scene; and so on. Clearly, Tags are intended to identify GameObjects for scripting purposes. We can use them to write script code to find a GameObject by looking for any object that contains our desired Tag. This is achieved using the GameObject.FindWithTag() function.一个标签是你用来索引一个或一组游戏对象的词。例如,你可以为玩家控制的角色定义Player和Enemy标签,区分出非玩家控制角色;一个Collectable标签能被用于定义玩家能在场景中收集的物体;等等。简单来说,标签是为了编程的目的而对游戏对象的标注。我们能使用标签来书写脚本代码通过搜索找到包含我们想要的标签的对象。通过GameObject.FindWithTag() 我们可以实现这个功能。For example 例如 :// Instantiates respawnPrefab at the location
// of the game object with tag "Respawn"
// 在标签为"Respawn"的游戏对象的位置实例化预设var respawnPrefab : GameObject;
var respawn = GameObject.FindWithTag ("Respawn");
Instantiate (respawnPrefab, respawn.position, respawn.rotation);This saves us having to manually add our GameObjects to a script抯 exposed properties using drag and drop -- a useful timesaver if the same script code is being used in a number of GameObjects. Another example is a Trigger Collider control script which needs to work out whether the player is interacting with an enemy, as opposed to, say, a random prop or collectable item. Tags make this kind of test easy.这可以让我们拥有通过鼠标拖放来扩展我们使用脚本添加对象时自定义位置的能力 -- 如果同样的脚本被多次使用,可以节约很多时间。另一个例子是一个碰撞触发器控制脚本, 它需要计算出角色是和一个敌方角色交互呢,还是相反,对话,随机道具的使用或是整理物品,标签将使这类的测试变的简单。
【Applying a Tag 应用一个标签】The Inspector will show the Tag and Layer drop-down menus just below any GameObject's name. To apply a Tag to a GameObject, simply open the Tags drop-down and choose the Tag you require:在检视面板任意游戏物体名字的下面显示Tag和Layer下拉菜单。来应用一个标签给一个游戏物体,打开标签下拉菜单并选择一个标签:The GameObject will now be associated with this Tag.
该游戏物体将于这个标签相关联。
【Creating new Tags 创建新的标签】To create a new Tag, click the Add new tag... option at the end of the drop-down menu. This will open up the Tag Manager in the Inspector. The Tag Manager is described here.要创建一个新的标签,在下拉菜单的末尾,点击Add tag...选项,这将在检视面板打开标签管理器。在这里看标签管理器的描述。Layers appear similar to Tags, but are used to define how Unity should render GameObjects in the Scene. See the Layers page for more information.层类似于标签,但用来定义Unity怎样在场景渲染游戏物体。参见Layers页面的更多信息。
【Hints 提示】    A GameObject can only have one Tag assigned to it.
    一个游戏物体只能指定一个标签。
    Unity includes some built-in Tags which do not appear in the Tag Manager:
    Unity包含一些内置标签,没有显示在标签管理器:
        "Untagged"
        "Respawn"
        "Finish"
        "EditorOnly"
        "MainCamera"
        "layer"
        and "GameController".
    You can use any word you like as a Tag. (You can even use short phrases, but you may need to widen the Inspector to see the tag's full name.)
    可以使用任意单词作为标签。(你甚至可以使用短句,但名称太长的话会撑开下拉菜单)
【来源:互联网】
更多精彩教程,尽在web3D纳金网http://www.narkii.com/college/
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

手机版|纳金网 ( 闽ICP备2021016425号-2/3

GMT+8, 2024-11-16 01:52 , Processed in 0.164688 second(s), 32 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部