1 2 3 4 5 6 | GameObject EnemyPanel = Resources.Load( "EnemyPanel" ) as GameObject; //加载敌人血条 m_EnemyPanel = Instantiate(EnemyPanel, m_transform.position, m_transform.rotation) as GameObject; //实例化血条 m_EnemyPanel.transform.localScale = new Vector3(0.006f, 0.006f, 0.006f); //调整ui大小 m_bloodSlider =m_EnemyPanel.GetComponentsInChildren<UISlider>(); //获取物体组件 m_EnemyHeight = gameObject.collider.bounds.size.y; //通过碰撞器获取高度 m_NameLabel = m_EnemyPanel.GetComponentsInChildren<UILabel>(); //获取字体组件 |
1 2 3 4 | //获取x,y,z三个坐标的数值 Vector3 pos = new Vector3(m_transform.position.x, m_transform.position.y + m_EnemyHeight, m_transform.position.z); m_EnemyPanel.transform.position = pos; //值赋给物体位置 m_EnemyPanel.transform.rotation = Camera.main.transform.rotation; //让ui血条一直面向摄像机 |