Search Unity

Script enable disable doesn't work

Discussion in 'Scripting' started by Andy, Jan 9, 2007.

  1. Andy

    Andy

    Joined:
    Nov 5, 2006
    Posts:
    50
    I am making a game in which the script enable/disable button has no effect. The script remains active. Is this a bug in my project and should I start from scratch or is there something I don't know about this?

    Andy
     

    Attached Files:

  2. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    Yes, I've noticed that too. It seems to apply to more than scripts. Incidentally does the texture offset function in the inspector work for you?
    AC
     
  3. Andy

    Andy

    Joined:
    Nov 5, 2006
    Posts:
    50
    I haven't used it recently but with Unity 1.5 I did notice the offset did not work always.

    Andy
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It does work to enable/disable scripts, but not all functions are actually disabled. Primarily trigger functions I believe, so you can turn off scripts for stuff that's not needed, but triggers will still work so they can be "woken up". Since you have mouseover stuff, I guess that's what's happening. (And yes, the texture offsets work fine here....)

    --Eric
     
  5. Andy

    Andy

    Joined:
    Nov 5, 2006
    Posts:
    50
    That is interesting. I am trying to make an object change color by moving a mouse over it and then after a click on the object switch to making a different object change color by moving a mouse over it. Is there any way to completely disable a script like this one in one object and enable the same script in another object?


    function OnMouseEnter () {
    renderer.material.color = Color.yellow;
    }

    function OnMouseExit () {
    renderer.material.color = Color.blue;
    }
     
  6. freyr

    freyr

    Joined:
    Apr 7, 2005
    Posts:
    1,148
    The enabled property only enables/disables Update and FixedUpdate. See:MonoBehaviour.enabled

    But you are free to inspect the value yourself.
    Code (csharp):
    1.  
    2. function OnMouseEnter() {
    3.    // Do nothing unless enabled
    4.    if ( ! enabled ) return;
    5.  
    6.    // ... else continue as normal
    7.  
    8.    ...
    9. }
     
  7. Andy

    Andy

    Joined:
    Nov 5, 2006
    Posts:
    50
    Hey it worked, thanks a lot.

    Andy