- Home /
Question by
theUndeadEmo · Apr 14, 2012 at 08:51 AM ·
arraycomponents
adding all scripts in current gameobject to an array
having some trouble adding my scripts into an array so i can enable and disable them all at once
private MonoBehaviour [] scripts;
// Use this for initialization
void Start ()
{
scripts = GetComponent<MonoBehaviour> ();
if (Application.loadedLevel == 0) {
for (int i=0; i<scripts.Length; i++) {
}
}
}
getting this error
error CS0029: Cannot implicitly convert type UnityEngine.MonoBehaviour' to
UnityEngine.MonoBehaviour[]'
Comment
Best Answer
Answer by GuyTidhar · Apr 14, 2012 at 09:01 AM
Instead of your first line in the Start() method,
Change to this:
scripts = GetComponents<MonoBehaviour>() as MonoBehaviour[];
You probably can ditch the
as MonoBehaviour[]
(You used GetComponent instead of GetComponents - note the "s" at the end).
Your answer
Follow this Question
Related Questions
Create array of scripts 1 Answer
In an array of scripts, how to access their variables? 2 Answers
foreach Element Problem 1 Answer
how to get a gameObject's name from another scrpit 1 Answer
Array script boolean 1 Answer