playMaker

Author Topic: How to make a UGUI label follow a 3D game object?  (Read 3457 times)

Groo Gadgets

  • Beta Group
  • Full Member
  • *
  • Posts: 175
How to make a UGUI label follow a 3D game object?
« 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

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

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How to make a UGUI label follow a 3D game object?
« Reply #1 on: August 19, 2015, 08:09:03 PM »
Hi,

 I made a Sample exactly for this on the Ecosystem. Search for "text follow".

You can download the package here if you don't want to use the Ecosystem

Bye,

 Jean

Groo Gadgets

  • Beta Group
  • Full Member
  • *
  • Posts: 175
Re: How to make a UGUI label follow a 3D game object?
« Reply #2 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