disable component of object code example
Example 1: enabling and disabling components unity
//Enable or disable a component in Unity example:
component.enabled = false;
Example 2: 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;
}
}
}