I have absolutely no idea if what I am trying to do even has a name at all, so please bare with me.
I want to have a UI Object on screen during the game, it is just basic text and an image behind it for contrast and it will change throughout the game, but if your character were to walk in the direction the UI is on the screen, eventually when the gameobject comes into view, you'd see the UI lock on the game object, so you know that's what is speaking etc.
Like being able to hear something from far off, but once you approach it, you can see whats actually talking. you know?
Would anyone know what this is called or how I can perform this using the new Unity UI elements? Thanks
I don't have an answer, but I think this is what you're looking for: http://answers.unity3d.com/questions/388271/offscreen-effect.html
Answer by Filhanteraren
Mar 21 at 12:43 AM
I made a simplified version of this tutorial here:
Here is the script, its not perfect but should give you an idea on how it works
public class OffScreenIndicator : MonoBehaviour
[SerializeField] private Image _uiArrow;
[SerializeField] private Image _uiIndicator;
[SerializeField] private Transform _trackingObject;
// Use this for initialization
// Update is called once per frame
private void UpdateOffscrenIndicator(Vector3 position)
// Based on code from https://www.youtube.com/watch?v=gAQpR1GN0Os
// youtube user digijin
Vector3 screenpos = Camera.main.WorldToScreenPoint(position);
if (screenpos.z > 0 && screenpos.x > 0 && screenpos.x < Screen.width && screenpos.y > 0 && screenpos.y < Screen.height)
// THE OBJECT IS INSIDE VIEW
_uiIndicator.transform.position = screenpos;
_uiIndicator.transform.rotation = Quaternion.Euler(0, 0, 0);
_uiIndicator.enabled = true;
_uiArrow.enabled = false;
// THE OBJECT IS OUTSIDE VIEW
_uiIndicator.enabled = false;
_uiArrow.enabled = true;
Vector3 screenCenter = new Vector3(Screen.width, Screen.height, 0) / 2;
screenpos -= screenCenter;
if (screenpos.z < 0)
screenpos *= -1;
float angle = Mathf.Atan2(screenpos.y, screenpos.x);
angle -= 90 * Mathf.Deg2Rad;
float cos = Mathf.Cos(angle);
float sin = Mathf.Sin(angle);
screenpos = screenCenter + new Vector3(sin * 150, cos * 150, 0);
float m = cos / sin;
Vector3 screenBounds = screenCenter * 1f;
screenpos = cos > 0 ? new Vector3(-screenBounds.y / m, screenCenter.y, 0) : new Vector3(screenBounds.y / m, -screenCenter.y, 0);
if (screenpos.x > screenBounds.x)
screenpos = new Vector3(screenBounds.x, -screenBounds.x * m, 0);
else if (screenpos.x < -screenBounds.x)
screenpos = new Vector3(-screenBounds.x, screenBounds.x * m, 0);
screenpos += screenCenter;
_uiArrow.transform.position = screenpos;
_uiArrow.transform.rotation = Quaternion.Euler(0, 0, angle * Mathf.Rad2Deg);
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
149 People are following this question.
Canvas without Camera?
How can I organize menus as a tree hierarchy?
Keyboard GUI navigation priority
Creating a UI minigame almost like Stardew Valley fishing mechanics
Preventing world interactions when using an UI element with an Orthographic 3D camera