playMaker

Author Topic: Send message to all objects with tag  (Read 3044 times)

frozze

  • Playmaker Newbie
  • *
  • Posts: 25
Send message to all objects with tag
« on: May 31, 2015, 12:27:45 PM »
Hi.

How is it possible to use "send message" to all objects with a tag, or within a given radius? Lets say I have a bomb that explodes. It has a radius collider, and everything within that radius gets a send message.

I assume I need to make a for loop, and check if each tag is in range. If the tag matches it will send message. But I'm not sure how to do it.

I think it's this in code:
http://answers.unity3d.com/questions/463020/sendmessage-to-all-tag-within-range.html

best regards
frozze


dudebxl

  • Hero Member
  • *****
  • Posts: 602
Re: Send message to all objects with tag
« Reply #1 on: May 31, 2015, 06:43:49 PM »
check action: SendEventByTag

@ ecosystem or https://snipt.net/dudebxl/?page=2 (copy/paste into new C# script with same name)
« Last Edit: May 31, 2015, 07:11:18 PM by dudebxl »

frozze

  • Playmaker Newbie
  • *
  • Posts: 25
Re: Send message to all objects with tag
« Reply #2 on: June 01, 2015, 10:03:22 AM »
Thanks, but where am I supposed to insert the name of the method? "like in send message = method name"

dudebxl

  • Hero Member
  • *****
  • Posts: 602
Re: Send message to all objects with tag
« Reply #3 on: June 01, 2015, 10:17:26 AM »
mmm not sure i understand but i will give it a try.

1. Select the tag you went to send event to in the action
2. copy the event that will be used by all the gameobjects with target tag (make sure you set the event to global after)
3. paste event name in action at 'or send by..' space in the action
4. put the FSM name from the target gameobjects tag (usually if only one then it is 'FSM' which is the default name) into the action

Now you are good to go. bear in mind this is a solution for all gameobjects with target tag and not for object with target tag in only the collider zone. maybe you should change tag on all object that touch the collider (trigger event) then use this action for the new tag. Or use array list actions.

if you are using a script in your target gameobject then create a global event (and do above) then call the script method() with an another action.

hope it helps