Hi there,
I’m looking to build an array of scripts and then access variables from whichever script I need through the array.
MonoBehaviour[] AbilitiesScripts = new MonoBehaviour[6];
and then
AbilitiesScripts[0].somePublicVariable = 15;
Is this possible or can I only enable / disable scripts by adding them to an array and that’s it?
it is possible, but the type of your array is MonoBehaviour, so you need to cast each script into its real type to be able to access variables of that type. If they’re all the same type use that type for your array and you won’t need a cast. If not you’d need to do something like this:
var upCast = AbilitiesScripts[0] as WhatItReallyIs;
if (upCast != null)
upCast.theVariable = something
which tries to cast and if ur is that type it proceeds.
But to be honest, an array of MonoBehaviours should operate on that level, like access transform or gameobject, ire just toggle scripts on and off.