转 【Unity3d】 GUITexture类似Dota血条

转 【Unity3d】 GUITexture类似Dota血条_第1张图片


EnemyInfo enemyInfo;

   public GUITexture enemyBoxGUI;

   private Texture enemyBox;

   private Texture enemyHp;

   private int currentHp;

   private float hpLength;

   // Use this for initialization

   void Start ()

    {

   enemyInfo=gameObject.transform.parent.GetComponent<EnemyInfo>();

   enemyBox=enemyBoxGUI.texture;

   enemyHp=guiTexture.texture;

   currentHp=enemyInfo.Health();

   hpLength=enemyHp.width/3;

       

    }

   

   // Update is called once per frame

   void Update ()

    {

       print(currentHp);

       Vector3pos=Camera.mainCamera.WorldToViewportPoint(transform.parent.position);

       enemyBoxGUI.transform.position=newVector3(pos.x-0.05f,pos.y,pos.z-0.2f);

       guiTexture.transform.position=new Vector3(pos.x-0.05f,pos.y,pos.z-0.2f);

       enemyBoxGUI.pixelInset=newRect(10,20,enemyBox.width/6,enemyBox.height/8);

       guiTexture.pixelInset=new Rect(10,25,hpLength*currentHp/enemyInfo.AllHealth,enemyHp.height/3);

       currentHp=enemyInfo.Health();

    }


转 【Unity3d】 GUITexture类似Dota血条_第2张图片

你可能感兴趣的:(转 【Unity3d】 GUITexture类似Dota血条)