Tasharen Entertainment Forum

Support => Misc Archive => Topic started by: Littlenorwegians on March 31, 2017, 04:09:11 PM

Title: Floating Text Almost Works Perfectly
Post by: Littlenorwegians 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? :)
Title: Re: Floating Text Almost Works Perfectly
Post by: Littlenorwegians on March 31, 2017, 04:15:58 PM
https://dl.dropboxusercontent.com/u/11238180/CombustionVids/UIProblem.mp4[/b]]https://dl.dropboxusercontent.com/u/11238180/CombustionVids/UIProblem.mp4 (http://[b)
A video showcasing the problem.