Advertisement
halleman19

ui bar user | unity3d

Sep 24th, 2023
705
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.64 KB | Gaming | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class UserInfo : MonoBehaviour
  6. {
  7.     public Transform target;
  8.     Camera cam;
  9.     public Vector3 screenPos;
  10.  
  11.     public Vector2 hpBarSize;
  12.  
  13.     public Texture2D hpBarTexture;
  14.  
  15.     void Start()
  16.     {
  17.         cam = GetComponent<Camera>();
  18.     }
  19.  
  20.     void Update()
  21.     {
  22.         screenPos = cam.WorldToScreenPoint(target.position);
  23.     }
  24.  
  25.     private void OnGUI()
  26.     {
  27.         GUI.DrawTexture(new Rect(screenPos.x - (hpBarSize.x / 2), Screen.height - screenPos.y - 70 - (hpBarSize.y / 2), hpBarSize.x, hpBarSize.y), hpBarTexture);
  28.     }
  29. }
Tags: Unity3d
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement