1、var target : Transform; / Object that this label should followvar offset = Vector3.up; / Units in world space to offset; 1 unit above object by defaultvar clampToScreen = false; / If true, label will be visible even if object is off screenvar clampBorderSize = .05; / How much viewport space to leave
2、 at the borders when a label is being clampedvar useMainCamera = true; / Use the camera tagged MainCameravar cameraToUse : Camera; / Only use this if useMainCamera is falseprivate var cam : Camera;private var thisTransform : Transform;private var camTransform : Transform;function Start () thisTransf
3、orm = transform;if (useMainCamera)cam = Camera.main;elsecam = cameraToUse;camTransform = cam.transform;function Update () if (clampToScreen) var relativePosition = camTransform.InverseTransformPoint(target.position);relativePosition.z = Mathf.Max(relativePosition.z, 1.0);thisTransform.position = cam
4、.WorldToViewportPoint(camTransform.TransformPoint(relativePosition + offset);thisTransform.position = Vector3(Mathf.Clamp(thisTransform.position.x, clampBorderSize, 1.0-clampBorderSize),Mathf.Clamp(thisTransform.position.y, clampBorderSize, 1.0-clampBorderSize),thisTransform.position.z);else thisTransform.position = cam.WorldToViewportPoint(target.position + offset);script RequireComponent(GUIText)