How to disable and enable a c# script with a code?

For example when key “tab” is pressed a script disables but when you press one more time it enables.

Have a script in the scene that has a reference to the script you want to enable/disable.
Then within that script, check for tab to be pressed.

Within the check for tab, just set
otherScript.enabled = true/false;

But if I have like 3 other scripts on object and I only need to disable/enable one of them.

public theScript;
theScript.enabled = false;

Then assign the script that you want to disable into the slot in the inspector

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class isjungimas2 : MonoBehaviour
{
    public <First> theScript;
  
    void Start()
    {
        theScript.enabled = false;
    }

  
    void Update()
    {
      
    }
}

Something like that? Because i get errors.

You don’t need < and > around First. Assuming First is the name of your other script.
I suggest you go look at some tutorials to help get yourself started.

1 Like

Okay, thanks.