Statically write .enabled for use with Android

Hello, I have been stuck on this for a while now and I'm trying to figure out how to structure my code to work with Android. Originally my code was written like this...

GetComponent("SpawnBoard").enabled = false;

And I am getting the error saying .enabled is not a member of UnityEngine.Component or the likes. Obviously this is because it is written dynamically which mobile Unity does not support so how do i get this to work?

How can I enable/disable scripts statically?

1 Answer

1

GetComponent returns Component; you have to cast it to the correct type. Easiest way is to use generics: `GetComponent.().enabled = false;` As an aside, don't use quotes in GetComponent unless you have to (slower and errors are runtime instead of compile-time).