playMaker

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

Neikke

  • Junior Playmaker
  • **
  • Posts: 53
    • View Profile
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!


krmko

  • Sr. Member
  • ****
  • Posts: 423
    • View Profile
    • Fat Pug Studio
Re: Temporarily turn off a script component attached to enemy object
« Reply #1 on: October 14, 2017, 10:57:26 AM »
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.

tcmeric

  • Sr. Member
  • ****
  • Posts: 480
    • View Profile
Re: Temporarily turn off a script component attached to enemy object
« Reply #2 on: October 14, 2017, 07: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: 2291
    • View Profile
    • jinxtergames
Re: Temporarily turn off a script component attached to enemy object
« Reply #3 on: October 14, 2017, 09:14:35 PM »
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.