playMaker

Author Topic: Temporarily turn off a script component attached to enemy object  (Read 1592 times)

Neikke

  • Full Member
  • ***
  • Posts: 134
Currently i have a Script on all enemies that kills Player character. How do I reach to this script component on all 'enemies' tag (or layer) at once to be able to turn them on and off? I do have 'Enemies' layer and tag in my scene but have no idea how to turn off particular component on all of them.

Basically I just need to temporarily deactivate this script by Player taking some Invincibility Powerup which would just toggle this Killing script off on all enemies. Or may be there are better ways to do it? Please help! Thanks in advance!


Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Temporarily turn off a script component attached to enemy object
« Reply #1 on: October 14, 2017, 01:57:26 PM »
I think your logic is invalid, you should do something with player instead of many enemies. For example, if coliding kills the player, turn off the collider on player. If hp loss kills the player, lock the variable until invincibility wears off.
Available for Playmaker work

tcmeric

  • Beta Group
  • Hero Member
  • *
  • Posts: 768
Re: Temporarily turn off a script component attached to enemy object
« Reply #2 on: October 14, 2017, 10:33:52 PM »
I agree with krmko. However, if you really needed to do it your way (and I dont suggest it). You need to learn how to use arrays. An array can hold all of your bad guys, and then you cycle through the entire array and disable each script. Its not a simple processes however compared to krmko's solution.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Temporarily turn off a script component attached to enemy object
« Reply #3 on: October 15, 2017, 12:14:35 AM »
Hi,
To enable/disable a script you can find an action on the Ecosystem called "Enable script"

If the enemies need to idle and only react within a certain range i would do something like this :

Have child object with a trigger on the player and set the size that the enemies should react.

On the enemies have a fsm that gets triggered when in range of the player

From the player send an event to the enemy when inside the trigger.
if the player has the powerup send a different event to the enemy.

You can check out this topic this does something similar to understand the basic.

I am traveling atm, if you want i can make a sample in a few days.