- Home /
 
               Question by 
               Tubestorm · Nov 30, 2020 at 03:07 PM · 
                unity 5scripting problemcomponentdisable  
              
 
              enable and disable script on Unity gameobject
Hey I'm working on a selection feature in unity. Essentially when the player clicks on an object I want a script called "Outline" to be added to the gameobject, and if they click off I want the script to either be removed or disabled (either is fine.)
Any Ideas why this isn't working?
  var outlineScript = new Outline();
 
         //if nothing is selected remove/disable script
         if (_selection != null)
 
         {
             outlineScript.enabled = false; //how to turn this part off
 
         }
 
         //add script if selected
         if (Physics.Raycast(ray, out hit))
         {
             var selection = hit.transform;
 
             selected = hit.collider.gameObject;//get gameobject that was hit
             outlineScript = selected.GetComponent<Outline>();
 
             if (selection.CompareTag(selectableTag))
             {
                 selected.AddComponent<Outline>();
             }
             _selection = selection;
         }
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                