Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: Groo Gadgets on August 18, 2015, 09:46:04 PM

Title: How to make a UGUI label follow a 3D game object?
Post by: Groo Gadgets on August 18, 2015, 09:46:04 PM
Hey guys,

I'm trying to get a UGUI element to follow a 3D game object (basically an arrow floating above the object) but when the object leaves the view of the camera the UGUI element would be clamped to the edge of the screen, indicating the direction of the object off screen.

Here's a script that does exactly what I need but using the old GUI system with a text label:
http://wiki.unity3d.com/index.php/ObjectLabel (http://wiki.unity3d.com/index.php/ObjectLabel)

Does anyone know how I could achieve this using standard actions? If not would it be possible to come up with an action that does this?

Thanks!

Simon
Title: Re: How to make a UGUI label follow a 3D game object?
Post by: jeanfabre on August 19, 2015, 08:09:03 PM
Hi,

 I made a Sample exactly for this on the Ecosystem (https://hutonggames.fogbugz.com/default.asp?W1181). Search for "text follow".

You can download the package here (https://github.com/jeanfabre/PlayMaker--Unity--UI/blob/master/PlayMaker/Ecosystem/Custom%20Samples/uGui/uGuiTextFollowGameObject.unitypackage) if you don't want to use the Ecosystem

Bye,

 Jean
Title: Re: How to make a UGUI label follow a 3D game object?
Post by: Groo Gadgets on August 19, 2015, 08:54:09 PM
Hey Jean,

Yes I downloaded that example soon after I posted this question. It works well but when I clamp the values to the screen size the GUI label gets messed up when the object is behind the camera. I think that's where some math on the Z value comes in. Here's the snippet from the ObjectLabel script:
Code: [Select]
var relativePosition = camTransform.InverseTransformPoint(target.position + offset);
relativePosition.z = Mathf.Max(relativePosition.z, 1.0);

I'm going to try and recreate the script using standard actions today, i'll let you know if it works  :-)

Simon