using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Fl : MonoBehaviour
{
// 人物头顶的点,血条的位置,这个点,可以是空物体,也可以通过计算得到
public Transform head;
// 血条UGUI里的图片
public Image img;
// 控制缩放
float distance;
// Use this for initialization
void Start ()
{
distance = Vector3.Distance (head.position, Camera.main.transform.position);
}
// Update is called once per frame
void Update ()
{
// 计算缩放比例
float newDistance = distance / Vector3.Distance (head.position, Camera.main.transform.position);
Vector2 position = Camera.main.WorldToScreenPoint (head.position);
img.rectTransform.position = position;//位置
img.rectTransform.localScale = Vector3.one * newDistance;
}
}
太匆忙了,急急忙忙乱写了一个...以后有时间再改吧,先做个记录