playMaker

Author Topic: GetTagCountFloat  (Read 1922 times)

MattyWS

  • Junior Playmaker
  • **
  • Posts: 90
GetTagCountFloat
« on: February 27, 2018, 04:13:33 PM »
It was a super quick edit from me but I needed to get a tag count and do maths with it, the action currently was an INT so I changed a few lines to make it a float. Figured I'd mention it here, maybe it can be added later or something.

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2013. All rights reserved.

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.GameObject)]
[Tooltip("Gets the number of Game Objects in the scene with the specified Tag. Uses Float")]
public class GetTagCountFloat : FsmStateAction
{
[UIHint(UIHint.Tag)]
public FsmString tag;
[RequiredField]
[UIHint(UIHint.Variable)]
public FsmFloat storeResult;

public override void Reset()
{
tag = "Untagged";
storeResult = null;
}

public override void OnEnter()
{
GameObject[] gos = GameObject.FindGameObjectsWithTag(tag.Value);

if (storeResult != null)
storeResult.Value = gos != null ? gos.Length : 0;

Finish();
}
}
}

My reason for this was that I needed to get a count of every star in my scene,  "StarCount" and then compare with the amount of stars collected at the end of the level "StarsCollected" so I could work out a percentage at the end of how many the player collected (StarsCollected / StartCount x 100). I couldn't do this with an INT.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: GetTagCountFloat
« Reply #1 on: February 28, 2018, 01:07:36 AM »
Hi,

 Thanks for sharing your work!

 I think there is already an action that does this on the Ecosystem though:

'SceneObjectsCount'

 Bye,

 Jean

MattyWS

  • Junior Playmaker
  • **
  • Posts: 90
Re: GetTagCountFloat
« Reply #2 on: February 28, 2018, 04:40:59 AM »
Ah I did not find that, I guess I didn’t look too hard before I made the edit myself. Thank you for pointing it out! :)