Search Unity

how do i disable scripts in javascripts?

Discussion in 'Scripting' started by ZimonIsHim, Apr 30, 2015.

  1. ZimonIsHim

    ZimonIsHim

    Joined:
    Apr 18, 2015
    Posts:
    7
    How do i disable scripts in javascripts?

    I have a pause menu and a player.
    When I click continue I can still shoot, how do I disable that?

    btw good explenations plz im a noob in unity :(
     
  2. Chaselon

    Chaselon

    Joined:
    May 17, 2015
    Posts:
    13
    If it functions on a GUI, you could just manipulate the time scale to pause everything in game. So one could write a condition, which in your case is most likely a boolean that enables showing the pause menu, to set the time scale to 0. Then upon pressing any button on the pause menu that goes to another scene, or continues the game again, you can set it back to 1.

    If you are just single out the script for the player then this could work:

    Code (JavaScript):
    1. public var playerObject : GameObject;
    2.  
    3. function PausePlayer() {
    4.     (playerObject.GetComponent("ScriptName")as MonoBehaviour).enabled = false;
    5. }
    Just place the actual enabled where you want to disable.
     
    Last edited: May 25, 2015
  3. vfxjex

    vfxjex

    Joined:
    Jun 3, 2013
    Posts:
    93
    you might want to check this