OnTriggerEnter doesn't work as it should? (c#)

Hi everyone, I am facing a problem with OnTriggerEnter.

Why does OnTriggerEnter work at start, but after it has runned as it should and you change variables for the conditions, it doesn’t work? The methods that sets/changes the variables are the same for the start condition, and when event is triggered

I have debugged to check that the variables are actually changed to what we want, and that happens correctly. I am checking for collision detection for up to 4 conditions, four different objects colliding with the Collider. Basically you have four version of the code below, with four variable for each(activeCell2, activeBodyPart2, danceMove2Completed, currentDanceMove2 etc)

The variables are changed correctly, but they aren’t beeing checked in OnTriggerEnter, even though they should have.

Thank you and apologize for a little messy code.

void OnTriggerEnter (Collider cell)
	{
		
		if (cell.name == "cellID " + activeCell && this.name == activeBodyPart && !danceMoveCompleted) {
			/**< if the active cell and  our active bodypart collides, and dancemoves(so we can set currentMove to next dancemove when a dancemove is complted)
			 * not completed and a dance is not completed*/  
			
			cell.renderer.enabled = false; // after every collision, make cells invisible/dissapear
			
			if (counter < currentDanceMove.Length - 1) {
				drawFirstInstruction (currentDanceMove, counter);
			}
			if (counter < currentDanceMove.Length - 2) {
				drawSecondInstruction (currentDanceMove, counter);
			}
			if (counter < currentDanceMove.Length - 3) {
				drawThirdInstruction (currentDanceMove, counter);
			}
			Debug.Log (activeBodyPart + "collided with " + cell.name + " Counter: " + counter);
			
			if (counter < currentDanceMove.Length - 1) {	/**< increment counter by one while counter is less than second last element of the array*/  
				counter++;
			}
			
			if (activeCell == currentDanceMove [currentDanceMove.Length - 1]) { // if dance move is completed and dance is not completed
				danceMoveCompleted = true;	
				checkMoves (numOfabp); 
				danceMoveCompleted = false;
				danceMoveCompleted = true;
				
			} // end if
			
			activeCell = currentDanceMove [counter]; // active cell is set to the incrementing counter variable in currentDanceMove array for every collision

		} // end first if

The variables inside OnTriggerEnter doesn’t seem to change, even though they are changed outside OnTriggerEnter which the debug statements are showing.

RE: comment about solving using static vars

So your trigger script has got string activeCell; as a global, resulting in 4 copies of activeCell (one for each trigger)? And instead, there should be a single copy they all share? Static vars are one way to do that, but they almost always cause problems later on (for example, you want to add a 2nd dancer.)

Instead of statics, can create one a “I’m the dancer” script, with all the common data and routines for one dancer: Ex:

// dancerScript, for one dancing thing
public string activeCell;
public void drawFirstInstructions() {...}

Then have the triggers all refer to that dancer:

// triggerScript:
public dancerScript DS; // drag object w/dancerScript here

void OnTriggerEnter(...) {
  if(DS.activeCell == ... ) DS.drawFirstInstruction();