Script for checking things in an array doesn't work.

Hello.

My script doesn’t work although it seems like it should. Another thing (that has been double and triple checked for accuracy) triggers the function TrigCamCheck but every 10th time or so it fails to execute properly.

function TrigCamCheck()
{
	var highestTriggerValue = 0;
	var triggerCamScript : TriggerCamScript;
	//var triggerCamArray2 : GameObject[];
	
	var triggerCamArray2 = new Array();
	
	var camChangeToThisTrigger : Vector3;
	
	triggerCamArray2 = GameObject.FindGameObjectsWithTag ("TriggerCam"); 
	
	for (var trigger : GameObject in triggerCamArray2)	
	{
		triggerCamScript = trigger.GetComponent(TriggerCamScript);		
			
		if(triggerCamScript.validLookAt == true) 
		{	
			if (triggerCamScript.trigValue > highestTriggerValue) 
				{
					highestTriggerValue = triggerCamScript.trigValue;
					camChangeToThisTrigger = triggerCamScript.camFocus.transform.position;
					print("STEP2 DONE");
				}				
		}
	}
	FrameTargetNew(camChangeToThisTrigger);
	print("Cam is told to look at: " + highestTriggerValue);
	triggerCamArray2 = null;
}

Save me! I’ve been banging my head on this all day and i’m dizzy with tiredness and rage.

These things are much easier to debug if you start every file with:

#pragma strict

this will help you avoid mistakes before they compound into head-banging problems. Above, you’re changing a variable’s type, and trying to get a for iterator to downcast. The logic of your code looks right, but you’re leaning too much on the compiler to (mis)understand you. Get it compiling with strict and it will work.