Search Unity

Disabling / Enabling Scripts after initializing it to be disabled

Discussion in 'Editor & General Support' started by taragon, Dec 11, 2011.

  1. taragon

    taragon

    Joined:
    Jan 23, 2010
    Posts:
    119
    When currentInventory < 3, the following scripts are supposed to deactivate. I have the currentInventory debug to the screen, and it definitely decreases as the player gets rid of inventory, but I'm not sure why this isn't working. Enabling the scripts works on the 2 coppers (they are initially disabled), but after they're enabled and they don't go back to being disabled when currentInventory < 3

    Code (csharp):
    1. function Update () {   
    2.                                                    
    3.     if (currentInventory >= 3) {
    4.     copperOne.GetComponent("EnemyPoliceGuy").enabled=true;
    5.     copperOne.GetComponent("EnemyDamage").enabled=true;
    6.     copperTwo.GetComponent("EnemyPoliceGuy").enabled=true;
    7.     copperTwo.GetComponent("EnemyDamage").enabled=true;
    8.     }
    9.     else{
    10.     copperOne.GetComponent("EnemyPoliceGuy").enabled=false;
    11.     copperOne.GetComponent("EnemyDamage").enabled=false;
    12.     copperTwo.GetComponent("EnemyPoliceGuy").enabled=false;
    13.     copperTwo.GetComponent("EnemyDamage").enabled=false;
    14.     }
    15. }