Post by wohltaeter on Mar 29, 2016 9:14:28 GMT
Hi, I am trying to spawn a 2D Text "Bonus" at the position of the last killable of a Wave. I have Setup the Custom Event and the Text with a Script:
private Color neuRect;
public RectTransform canvasRectT;
public RectTransform healthBar;
public Transform objectToFollow;
void Update ()
{
neuRect = Color.Lerp(Color.white, Color.black, Mathf.PingPong(Time.time, 1));
Vector2 screenPoint = RectTransformUtility.WorldToScreenPoint(Camera.main, objectToFollow.position);
healthBar.anchoredPosition = screenPoint - canvasRectT.sizeDelta / 2f;
}
At the moment the Bonus-Text is shown on every Kill but I only want to show it when the last Killable died. - I know that there Custom Events triggering the last kill Bonus but there is no solution for Translating Custom Absolute Position or the position of the 3D Killable. But no solution for the 3D to 2D translation.
I also tried a solution with a Triggered Listener Subclass but the Text does not show up at the desired Event (I set up the Bonus Event in Level Settings Triggerd Spawner). Here is the Listener Sub
public class TriggeredSpawnerListenerSub : TriggeredSpawnerListener {
private Color neuRect;
public RectTransform canvasRectT;
public RectTransform healthBar;
public Transform objectToFollow;
/// <summary>
/// This method gets calls when a spawner gets ready to call events on child spawners. Override if you need custom logic.
/// </summary>
/// <param name="eType">The event type.</param>
/// <param name="transmitterTrans">The parent spawner's Transform.</param>
/// <param name="receiverSpawnerCount">The count of all child spawners of the parent.</param>
public override void EventPropagating(TriggeredSpawner.EventType eType, Transform transmitterTrans,
int receiverSpawnerCount) {
// your code here.
}
/// <summary>
/// This method gets calls when a child spawner gets notified to call its wave from a parent spawner. Override if you need custom logic.
/// </summary>
/// <param name="eType">The event type.</param>
/// <param name="transmitterTrans">The parent spawner's Transform.</param>
public override void PropagatedEventReceived(TriggeredSpawner.EventType eType, Transform transmitterTrans) {
// your code here.
neuRect = Color.Lerp(Color.white, Color.black, Mathf.PingPong(Time.time, 1));
Vector2 screenPoint = RectTransformUtility.WorldToScreenPoint(Camera.main, objectToFollow.position);
healthBar.anchoredPosition = screenPoint - canvasRectT.sizeDelta / 2f;
}
My Question: how can I show the 2D Text at the 2D position of the last Killable (3D pos) of a wave?
private Color neuRect;
public RectTransform canvasRectT;
public RectTransform healthBar;
public Transform objectToFollow;
void Update ()
{
neuRect = Color.Lerp(Color.white, Color.black, Mathf.PingPong(Time.time, 1));
Vector2 screenPoint = RectTransformUtility.WorldToScreenPoint(Camera.main, objectToFollow.position);
healthBar.anchoredPosition = screenPoint - canvasRectT.sizeDelta / 2f;
}
At the moment the Bonus-Text is shown on every Kill but I only want to show it when the last Killable died. - I know that there Custom Events triggering the last kill Bonus but there is no solution for Translating Custom Absolute Position or the position of the 3D Killable. But no solution for the 3D to 2D translation.
I also tried a solution with a Triggered Listener Subclass but the Text does not show up at the desired Event (I set up the Bonus Event in Level Settings Triggerd Spawner). Here is the Listener Sub
public class TriggeredSpawnerListenerSub : TriggeredSpawnerListener {
private Color neuRect;
public RectTransform canvasRectT;
public RectTransform healthBar;
public Transform objectToFollow;
/// <summary>
/// This method gets calls when a spawner gets ready to call events on child spawners. Override if you need custom logic.
/// </summary>
/// <param name="eType">The event type.</param>
/// <param name="transmitterTrans">The parent spawner's Transform.</param>
/// <param name="receiverSpawnerCount">The count of all child spawners of the parent.</param>
public override void EventPropagating(TriggeredSpawner.EventType eType, Transform transmitterTrans,
int receiverSpawnerCount) {
// your code here.
}
/// <summary>
/// This method gets calls when a child spawner gets notified to call its wave from a parent spawner. Override if you need custom logic.
/// </summary>
/// <param name="eType">The event type.</param>
/// <param name="transmitterTrans">The parent spawner's Transform.</param>
public override void PropagatedEventReceived(TriggeredSpawner.EventType eType, Transform transmitterTrans) {
// your code here.
neuRect = Color.Lerp(Color.white, Color.black, Mathf.PingPong(Time.time, 1));
Vector2 screenPoint = RectTransformUtility.WorldToScreenPoint(Camera.main, objectToFollow.position);
healthBar.anchoredPosition = screenPoint - canvasRectT.sizeDelta / 2f;
}
My Question: how can I show the 2D Text at the 2D position of the last Killable (3D pos) of a wave?