Answers for "how to disable all other components in gameobject in unity"

C#
6

disable a component unity

using UnityEngine;
using System.Collections;

public class EnableComponents : MonoBehaviour
{
    private Light myLight;
    
    
    void Start ()
    {
        myLight = GetComponent<Light>();
    }
    
    
    void Update ()
    {
        if(Input.GetKeyUp(KeyCode.Space))
        {
            myLight.enabled = !myLight.enabled;
        }
    }
}
Posted by: Guest on June-10-2020
0

how to disable all other components in gameobject in unity

foreach (MonoBehaviour component in GetComponents<MonoBehaviour>())
{	
	if (component != this) component.enabled = false;
}
Posted by: Guest on May-20-2021

Code answers related to "how to disable all other components in gameobject in unity"

C# Answers by Framework

Browse Popular Code Answers by Language