Skip to content

Instantly share code, notes, and snippets.

@nikhilsinha
Created January 2, 2017 01:40
Show Gist options
  • Save nikhilsinha/0dd61fa78243d3c994df5b82e7f48692 to your computer and use it in GitHub Desktop.
Save nikhilsinha/0dd61fa78243d3c994df5b82e7f48692 to your computer and use it in GitHub Desktop.
With the hack
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;
vp.x -= 50;
vp.y += 100;
_rectTransform.position = vp;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment