B1 中級 英國腔 1473 分類 收藏
Tags are a way of identifying game objects in Unity.
As a name of a single object could identify it,
it can be useful to set tags also.
For example you may have an object called Ork or Tank
but these could all be tagged Enemy,
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
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.
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
and then entering it in the list of tags at the top
of the tag manager.
Once you've done this, return to the object you
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.


标签-Unity 官方教程 (Tags - Unity Official Tutorials)

1473 分類 收藏
朱瑛 發佈於 2014 年 5 月 2 日
  1. 1. 單字查詢


  2. 2. 單句重複播放


  3. 3. 使用快速鍵


  4. 4. 關閉語言字幕


  5. 5. 內嵌播放器


  6. 6. 展開播放器


  1. 英文聽力測驗


  1. 點擊展開筆記本讓你看的更舒服

  1. UrbanDictionary 俚語字典整合查詢。一般字典查詢不到你滿意的解譯,不妨使用「俚語字典」,或許會讓你有滿意的答案喔