I'm trying to create an emoji balloon like this:
My NPC is walking at a 3D world space, but the canvas should be a 2D fixed image, following above characters head. In my case I need it to be clickable.
Should I use some specific kind of Camera Overlay or screen spaces?
I'm using Ortographic camera.
As mentioned you could either use a world space Canvas and then parent it and make it always face the camera (billboard).
Or you could also stay in Screenspace Overlay and just make your object follow the NPC using Camera.WorldToScreenPoint
public enum OffsetType
{
Screenspace,
Worldspace
}
public class FollowTargetInScreenSpace : MonoBehavior
{
public Transform Target;
[SerializeField] private Camera camera;
public OffsetType OffsetType;
public Vector3 Offset;
private void Awake()
{
if(!camera) camera = Camera.main;
}
private void Update()
{
if(!Target) return;
var worldPosition = Target.position;
Vector2 screenPoisition;
switch(OffsetType)
{
case OffsetType.Screenspace:
screenPoisition = camera.WorldToScreenPoint(worldPosition) + (Vector2) Offset;
break;
case OffsetType.Worldspace:
screenPoisition = camera.WorldToScreenPoint(worldPosition + Offset);
break;
default:
throw new ArgumentOutOfRangeException(nameof(OffsetType));
}
transform.position = screenPoisition;
}
}