I would like to disable a specific component.
It seems easy but the type of the component is dynamic, that is a public variable that set on the Unity inspector.
My code:
public class QualityControl : MonoBehaviour {
public int AtMinQuality;
public Component myComponent;
void Start () {
if(QualitySettings.GetQualityLevel()<=AtMinQuality){
//myComponent.enabled = false; <--dont work
//error CS1061: Type `UnityEngine.Component' does not contain a definition for `enabled'...
//Component.Destroy(Componente); <--work but i want disable it, not delete!
}
}
In simple terms, if my quality setting is less a specific number, i want to disable the component set in the inspector… I can? How?
I try with this code to get the type of my component:
myTipe=myComponent.GetType();
GetComponent<myTipe>().enabled = false; <--dont work
return this error:
error CS0118: QualityControl.myTipe' is a
field’ but a `type’ was expected
Where myTipe is a System.Type variable.
Any ideas?
(sorry for my bad english)