Search Unity

run a script of an inactive object ... every time an enemy dies.

Discussion in 'Scripting' started by maubar, Oct 21, 2015.

  1. maubar

    maubar

    Joined:
    May 27, 2015
    Posts:
    128
    hi
    i have a .cs script, on an empty gameobject,
    but I need to activate / run it ... every time an enemy dies.

    any idea please ....?
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    an empty gameobect isn't "inactive"... unless you are purposely setting it to that (terminology matters here since code will not run at all on an inactive gameobject).

    Assuming your gameobject is active, you just want the script to react to something happening elsewhere in your game, I'd suggest you look up "unity event".

    https://unity3d.com/learn/tutorials/modules/intermediate/scripting/events
     
  3. maubar

    maubar

    Joined:
    May 27, 2015
    Posts:
    128
    thanks a lot
    i put the script on an inactive gameobject...
    then set active the gameobject and follow the script will rund, then set inactive again..
    and repeat ... and repeat..
    but this is not the profesional way...

    thanks a lot so much again for your / any help.
    i will try what you say.
     
  4. BenZed

    BenZed

    Joined:
    May 29, 2014
    Posts:
    524
    Code can still be run on inactive components. Inactive components just will not call unity functions, Start(), Update(), FixedUpdate(), OnTriggerEnter(), ect. ect. ect.

    If I have a component cached in a variable that belongs to an inactive component, I can still call functions on it.