Created
January 2, 2017 01:28
-
-
Save nikhilsinha/fcfb2c42a9913ec6124c607863f17197 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public class UiUnitAttacher : MonoBehaviour | |
{ | |
public GameObject Target; | |
private RectTransform _rectTransform; | |
// Use this for initialization | |
void Start() | |
{ | |
_rectTransform = GetComponent<RectTransform>(); | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
Vector3 pos = Target.transform.position; | |
Vector3 vp = Camera.main.WorldToViewportPoint(pos); | |
vp.x = vp.x * Screen.width; | |
vp.y = vp.y * Screen.height; | |
_rectTransform.position = vp; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment