请教关于人物采访问题头顶名称显示的问题

1. Unity学习笔记(13)
using UnityE
using System.C
public class wenzi : MonoBehaviour {
//主摄像机对象
//主角对象
//NPC模型高度
float npcH
//默认NPC血值
private int HP = 100;
void Start ()
//得到主角对象
hero = this.gameO
//得到摄像机对象
camera = Camera.
//得到模型原始高度
float size_y = collider.bounds.size.y;
//得到模型缩放比例
float scal_y = transform.localScale.y;
//它们的乘积就是高度
npcHeight = (size_y *scal_y) ;
void OnGUI()
//得到NPC头顶在3D世界中的坐标
//默认NPC坐标点在脚底下,所以这里加上npcHeight它模型的高度即可
Vector3 worldPosition = new Vector3 (transform.position.x , transform.position.y + npcHeight,transform.position.z);
//根据NPC头顶的3D坐标换算成它在2D屏幕中的坐标
Vector2 position = camera.WorldToScreenPoint(worldPosition);
//得到真实NPC头顶的2D坐标
position = new Vector2 (position.x, Screen.height - position.y);
//计算NPC名称的宽高
Vector2 nameSize = GUI.skin.label.CalcSize (new GUIContent(this.name));
//根据tag设置显示颜色
if (this.tag == &green&)
GUI.color = Color.
else if(this.tag == &red&)
GUI.color = Color.
GUI.skin.label.fontSize = 18;//字体大小
//绘制NPC名称
GUI.Label(new Rect(position.x - (nameSize.x/2),position.y - nameSize.y ,nameSize.x,nameSize.y), name);
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:164373次
积分:7197
积分:7197
排名:第2449名
原创:571篇
转载:42篇
评论:58条
文章:85篇
阅读:41359
(3)(2)(18)(9)(53)(6)(4)(5)(8)(19)(21)(25)(60)(47)(20)(31)(1)(15)(57)(47)(106)(49)(5)}

我要回帖

更多关于 moto请教您一个问题 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信