Changing a certain element from a bool array in another script

Hi folks,

Unity noob here! I have the following Problem, while trying to build a small step sequencer:

I have a public bool array in Script A which consists of 16 elements.

In Script B I have a OnTriggerEnter event, which fires, if one of the 16 buttons (that I build from cubes) is triggered. What I’m trying to achieve is that, if for example I press button 3, the element 3 of the bool array in Script A is changing it’s value to true.

I already linked the Script A into Script B via a public GameObject and I am accessing the script via a GetComponent, but I don’t know how to access the one element of the array that I need.

Your help is appreciated :slight_smile:

I’m not that experienced as well but assuming that you’ve assigned some values like this in Script A:

//Bool array with 4 entries
bool[] myArray = new bool[]{ true, true, false, true };

//In Script B .. 

public void Element3()
element3 = ScriptA.myArray[2]; // An Array starts at Index 0, the 3rd Element is Index 2

if (Input.GetKeyDown("3"))
  element3 = true;

   element3 = false;
ScriptA.myArray[2] = element3;

//In FixedUpdate or Update
void FixedUpdate()

This should do what you want. If not I’m, sorry :frowning: Can’t test it right now…