playMaker

Author Topic: Send event to Game Object FSM by layer  (Read 2142 times)

troubleMaker

  • Playmaker Newbie
  • *
  • Posts: 25
Send event to Game Object FSM by layer
« 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.

Code: [Select]
// (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?  :)
« Last Edit: April 12, 2014, 01:11:03 PM by troubleMaker »

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Send event to Game Object FSM by layer
« Reply #1 on: April 14, 2014, 07:44:52 AM »
Make sure you add in the first few lines of the script

Code: [Select]
using UnityEngine;
Or it won't understand what anything is.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Send event to Game Object FSM by layer
« Reply #2 on: April 14, 2014, 07:52:20 AM »
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


troubleMaker

  • Playmaker Newbie
  • *
  • Posts: 25
Re: Send event to Game Object FSM by layer
« Reply #3 on: April 19, 2014, 12:21:06 PM »
Ok,

Thanks Jean, I'll try that.