官方教程:https://docs.unity3d.com/2017.2/Documentation/Manual/HOWTO-UIWorldSpace.html
第一步:Set the Canvas to World Space
創建一個Canvas,渲染模式選擇World Space
第二步:Decide on a resolution
設置Canvas大小,越大顯示的越清晰,位置最好重置為(0,0,0)
第三步:Specify the size of the Canvas in the world
根據公式 meter_size / canvas_width 控制像素大小或者縮放
第四步:Position the Canvas
主UI Canvas和世界空間UI Canvas都放置在原點時,操作界面如下顯示:
讓UI一直顯示在人物頭上固定位置(這里height應該比人物身高還要高一點,可以把角色身高寫進配置表,從配置表里讀身高信息)
第二句是讓UI保持平面角度,讓UI朝向攝像機前方(這個攝像機是跟隨人物的攝像機)
this.transform.position = owner.position + Vector3.up * height; this.transform.forward = Camera.main.transform.forward;