Playmaker Forum
PlayMaker Help & Tips => PlayMaker Help => Topic started by: troubleMaker on April 11, 2014, 06:33:21 PM
-
Hi,
I was trying to modify the send event FSM to make one that will broadcast an event to all gameObjects on a layer. I was just copy/pasting stuff from different scripts, but no surprise failed miserably. I need this for a sort of RTS game where i'd like the AI-controlled units on different teams to be able to issue orders to each other.
UPDATE: Ok, so i realized that in my case i could also sort by tags just as well, but i couldn't get that to work either. This is what i tried to paste together.
// (c) Copyright HutongGames, LLC 2010-2013. All rights reserved.
using System;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.StateMachine)]
[Tooltip("Sends an Event after an optional delay. NOTE: To send events between FSMs they must be marked as Global in the Events Browser.")]
public class SendEventToTagged : FsmStateAction
{
[RequiredField]
[Tooltip("The event to send. NOTE: Events must be marked Global to send between FSMs.")]
public FsmEvent sendEvent;
[RequiredField]
[UIHint(UIHint.Tag)]
[Tooltip("Only consider objects with this Tag. NOTE: It's generally a lot quicker to find objects with a Tag!")]
public FsmString withTag;
public override void Reset()
{
withTag = "Untagged";
sendEvent = null;
}
public override void OnEnter()
{
GameObject[] objects;
objects = GameObject.FindGameObjectsWithTag(withTag.Value);
foreach (GameObject obj in objects)
{
Fsm.Event(obj, sendEvent);
}
}
}
}
I also need to have it ignore itself when broadcasting. Help? :)
-
Make sure you add in the first few lines of the script
using UnityEngine;
Or it won't understand what anything is.
-
Hi,
Fsm.event won't work like that, you'll need to use my utils library and send event to a gamobject using:
PlayMakerUtils.SendEventToGameObject() call.
If you have arrayMaker, then PlayMakerUtils is featured, else you can get it here:
https://hutonggames.fogbugz.com/default.asp?W715
bye,
Jean
-
Ok,
Thanks Jean, I'll try that.