- Home /
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?
Answer by Eric5h5 · Apr 03, 2011 at 11:28 PM
GetComponent returns Component; you have to cast it to the correct type. Easiest way is to use generics: GetComponent.<SpawnBoard>().enabled = false;
As an aside, don't use quotes in GetComponent unless you have to (slower and errors are runtime instead of compile-time).
Your answer
Follow this Question
Related Questions
Creating a Game for IPhone/Android but testing it on a P.C. 1 Answer
Help for code optimization 2 Answers
My non-static models look black in the Precomputed GI environment 1 Answer
Tilt control for jump 0 Answers
Android / iPhone deployment.. 2 Answers