Playmaker Forum
PlayMaker Updates & Downloads => Share New Actions => Topic started by: Flying Robot on October 18, 2013, 01:57:12 AM
-
If you have bought NGUI HUD Text. A nice way for attaching NGUI widgets (health bar, dialogs etc) to your NPCs.
https://www.assetstore.unity3d.com/#/content/3831
You will need this to attach the GUI to the target object.
PS. I don't know if Jean is already working on this. Or I'll post the other NGUI HUD actions. Let me know.
AddNGUIFloatingText (https://github.com/flyingrobot/playmakercustomactions/blob/master/AddNGUIFloatingText.cs)
-
Hi,
by all mean, you are more than welcome to participate!
Also, pm me with your email if you want to be part of the trello board.
https://trello.com/b/1VSKPLcT/addons
bye,
Jean
-
Here's the remaining action of NGUI HUD Text. Thus completing this mini addon :)
I'm maintaining these files at github as they could require updates.
SetNGUIFollowTarget (https://github.com/flyingrobot/playmakercustomactions/blob/master/SetNGUIFollowTarget.cs)
AddNGUIFloatingText (https://github.com/flyingrobot/playmakercustomactions/blob/master/AddNGUIFloatingText.cs)
PS : Sent you PM
-
I'm trying to get this to work but I'm having a issue where the character is getting moved to the position of the UI Root (2D) and is invisible.
I'm getting this error.
NullReferenceException: Object reference not set to an instance of an object
UIFollowTarget.Update () (at Assets/HUD Text/Scripts/UIFollowTarget.cs:104)
-
Hi,
can you paste that script, I am looking at my version here and line 104 is not a line of code, so I am not sure which version of this script you have.
Bye,
Jean
-
// If visible, update the position
if (vis)
{
pos = uiCamera.ViewportToWorldPoint(pos);
pos = mTrans.parent.InverseTransformPoint(pos);
//pos.x = Mathf.RoundToInt(pos.x);
//pos.y = Mathf.RoundToInt(pos.y);
pos.z = 0f;
mTrans.localPosition = pos;
}
-
Hi,
the whole script :) i need to see what is line 104 in your case. Thanks :)
bye,
Jean
-
//--------------------------------------------
// NGUI: HUD Text
// Copyright © 2012 Tasharen Entertainment
//--------------------------------------------
using UnityEngine;
/// <summary>
/// Attaching this script to an object will make it visibly follow another object, even if the two are using different cameras to draw them.
/// </summary>
public class UIFollowTarget : MonoBehaviour
{
public delegate void OnVisibilityChange (bool isVisible);
/// <summary>
/// Callback triggered every time the object becomes visible or invisible.
/// </summary>
public OnVisibilityChange onChange;
/// <summary>
/// 3D target that this object will be positioned above.
/// </summary>
public Transform target;
/// <summary>
/// Game camera to use.
/// </summary>
public Camera gameCamera;
/// <summary>
/// UI camera to use.
/// </summary>
public Camera uiCamera;
/// <summary>
/// Whether the children will be disabled when this object is no longer visible.
/// </summary>
public bool disableIfInvisible = true;
/// <summary>
/// Destroy the game object when target disappears.
/// </summary>
public bool destroyWithTarget = true;
Transform mTrans;
int mIsVisible = -1;
/// <summary>
/// Whether the target is currently visible or not.
/// </summary>
public bool isVisible { get { return mIsVisible == 1; } }
/// <summary>
/// Cache the transform;
/// </summary>
void Awake () { mTrans = transform; }
/// <summary>
/// Find both the UI camera and the game camera so they can be used for the position calculations
/// </summary>
void Start()
{
if (target)
{
if (gameCamera == null) gameCamera = NGUITools.FindCameraForLayer(target.gameObject.layer);
if (uiCamera == null) uiCamera = NGUITools.FindCameraForLayer(gameObject.layer);
Update();
}
else
{
if (destroyWithTarget) Destroy(gameObject);
else enabled = false;
}
}
/// <summary>
/// Update the position of the HUD object every frame such that is position correctly over top of its real world object.
/// </summary>
void Update ()
{
if (target && uiCamera != null)
{
Vector3 pos = gameCamera.WorldToViewportPoint(target.position);
// Determine the visibility and the target alpha
int isVisible = (gameCamera.orthographic || pos.z > 0f) && (pos.x > 0f && pos.x < 1f && pos.y > 0f && pos.y < 1f) ? 1 : 0;
bool vis = (isVisible == 1);
// If visible, update the position
if (vis)
{
pos = uiCamera.ViewportToWorldPoint(pos);
pos = mTrans.parent.InverseTransformPoint(pos);
//pos.x = Mathf.RoundToInt(pos.x);
//pos.y = Mathf.RoundToInt(pos.y);
pos.z = 0f;
mTrans.localPosition = pos;
}
// Update the visibility flag
if (mIsVisible != isVisible)
{
mIsVisible = isVisible;
if (disableIfInvisible)
{
for (int i = 0, imax = mTrans.childCount; i < imax; ++i)
NGUITools.SetActive(mTrans.GetChild(i).gameObject, vis);
}
// Inform the listener
if (onChange != null) onChange(vis);
}
}
else Destroy(gameObject);
}
}
-
Hi,
ok, so your GameObject needs a parent. currently it doesn't right?
Bye,
Jean
-
This is what I have.
https://postimg.org/image/9u1luekgf
-
Hi,
this doesn't show your hierarchy, basically you should have this on a ngui GameObject, which means it must be parented somehow.
Bye,
Jean
-
I see. So what I just did was add the "Control - Simple Progress Bar" to my scene. It automatically added the UI Root. Then in playmaker I added the FSM like in my picture and assigned the components to the progress bar. Now in game the progress bar shows up and follows the AI around.
But I noticed that when you turn the player around the progress bar stays at the edge of the screen until you look back at the AI and then it follows the AI again.
Another question, that just came up. In the UI Follow Target, how can you define multiple targets?
-
Also how do you update the progress bar of the health?
-
Okay, I have figured most of what I asked out.
Not sure how to get multiple progress bars for multiple characters.
How can I turn a digit number (like 68) into a decimal (0.68)? I'm trying to change a float from like 68 to 0.68.
-
Hi,
you should have prefabs for your players and HUD, which then means either your player instance manage its own HUD or you have a manager that create both the player and hud instance and tight them together.
divide 68 /100 and you'll get 0.68, else if 68 comes as a string, use String format action
Bye,
Jean