Author Topic: Floating Text Almost Works Perfectly  (Read 1417 times)

Littlenorwegians

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Floating Text Almost Works Perfectly
« on: March 31, 2017, 04:09:11 PM »
Hello, so I got this script

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class HoverOverGameobject : MonoBehaviour {
  6.         public GameObject target;
  7.         public GameObject UIElement;
  8.         public Camera UICamera;
  9.         public Camera WorldCamera;
  10.  
  11.         void Start() {
  12.         }
  13.  
  14.         void LateUpdate() {
  15.                 WorldCamera = NGUITools.FindCameraForLayer (target.layer);
  16.                 UICamera = NGUITools.FindCameraForLayer (gameObject.layer);
  17.  
  18.                 Vector3 pos = WorldCamera.WorldToViewportPoint (target.transform.position);
  19.                 pos = UICamera.ViewportToWorldPoint (pos);
  20.  
  21.                 transform.position = pos;
  22.         }      
  23. }

And it works perfectly at 16:9 or 16:10 aspect ratio.
But below that, it suddenly sorta lags to the side and isn't right on top of the object. I'm wondering if any of you could have some helpful advise on how to fix this? :)