字幕列表 影片播放 列印所有字幕 列印翻譯字幕 列印英文字幕 Tags are a way of identifying game objects in Unity. 標籤(Tag)是Unity用來辨識遊戲物件的一個功能 As a name of a single object could identify it, 作為單一物件的名稱識別 物件標籤是非常有用的 it can be useful to set tags also. 舉例來說, 你有個物件叫Ork或Tank 他們都被貼上敵人(Enemy)標籤 For example you may have an object called Ork or Tank 然後你可以在程式裡用標籤 來判斷物件是否為敵人 but these could all be tagged Enemy, 同理, 敵人身上的程式腳本也可以 搜尋被貼上Player標籤的物件 and in your code you could check for any objects 要對物件貼標籤, 先選取物件 然後從檢視上的標籤下拉選單指定標籤 that have the tag Enemy. 如果選單內沒有你要的標籤也可以新增一個 Likewise a script on an enemy could check for a player character 使用標籤選單最後的新增選項(Add Tag) 然後在標籤管理裡新增一個標籤 by looking for a player tag. 完成之後, 重新點選你要標籤的物件 然後替物件貼上新增的標籤 To assign a tag to an object, select it and use the 在程式腳本裡有幾種方式 可以用標籤來搜尋物件 drop-down menu at the top of the inspector. 其中最簡單的方式就是 用GameObject.FindWithTag If the tag you want isn't already present then add a new tag. 這方法允許你指定一個標籤名稱 You can add a tag by clicking the option at the bottom of the menu 我將這個程式腳本放到敵人身上 這樣它就可以找到有Player標籤的物件 and then entering it in the list of tags at the top 然後我將機器人的標籤設定為Player 這樣一來,遊戲播放後敵人就會看著機器人 of the tag manager. 你也可以用FindGameObjectsWithTag 來搜尋標籤相同的物件群組 Once you've done this, return to the object you 更多範例請參照官網的Scripting Reference wish to place the tag on and select it from the drop-down. There are a number of functions in code, which will allow you to find objects with tags, the simplest one of these is GameObject.FindWithTag, which allows you to specify a string with the name of the tag inside it. This script is attached to my enemy object and I can use that to find an object with the tag Player. So I'll set my robot to be tagged Player and when the game starts my enemy is seeking out that object and looking at it. Likewise you could find multiple objects with the same tag by using FindGameObjectWithTag. See the scripting reference for more examples of this.
B1 中級 中文 英國腔 標籤 物件 敵人 腳本 程式 搜尋 標籤 - Unity官方教程 (Tags - Unity Official Tutorials) 57 4 朱瑛 發佈於 2021 年 01 月 14 日 更多分享 分享 收藏 回報 影片單字