Image processing: reseting image problems

Hey guys :3
I’m currently working on a project at school, trying to do some image processing in Unity (Please don’t ask me why, it’s a bad idea :P)
So we ran into a problem where we can’t reset the picture on which we draw the other image <.<’

Here’s the OnTriggerStay function:

function OnTriggerStay(myCollider : Collider){

//Here’s where we check if the player is close, in order not to waste ressources on Image Processing when the player is not around

	if (myCollider.gameObject.tag == "Player"){
		
		timeCount++;

//this is used for optimizing when to do the Image processing

		if(timeCount%myTime == 0){

			//first we loop through the amount of spiders we have and assign a new random value to the spider, this number is used as a reference for where to draw the spider

			for(var k = 0; k < spiderReferenceArray.Length; k++){
			
				spiderReferenceArray[k] += parseInt(Random.RandomRange(1.0f,5.0f)) + 256*parseInt(Random.RandomRange(1.0f,5.0f));
			
			}

//This is where the image should be reset back to the background picture. the background is right, but what happens is that it for some reason doesn’t assign the values from backgroundPixels into printPixels

            for(var txt = 0; txt < printPixels.Length; txt++){
    			
    			printPixels[txt].r = backgroundPixels[txt].r;
    			printPixels[txt].g = backgroundPixels[txt].g;
    			printPixels[txt].b = backgroundPixels[txt].b;
    			
    		}

//here we draw the images of the spiders, first loop for every spider we have, second for every pixel in the spider image

			for(var j = 0; j < spiderReferenceArray.Length; j++){
			
				for(var i = 0; i < spiderPixels.Length; i++){
					
					if(i%32 == 0){
						
						lineChange++;
						
					}
					
					if(spiderPixels<em>.r + spiderPixels_.g + spiderPixels*.b < 2.4f){*_</em>

* myPixel = i%32;*

_ printPixels[spiderReferenceArray[j] + myPixel + 256lineChange].r = spiderPixels.r;
printPixels[spiderReferenceArray[j] + myPixel + 256lineChange].g = spiderPixels*.g;
printPixels[spiderReferenceArray[j] + myPixel + 256lineChange].b = spiderPixels*.b;*_

* }*

* }*

* lineChange = 0;*

* }*
* //assigns the values of the printPixels to the myTexture, which is the texture being displayed in unity*
* myTexture.SetPixels(printPixels);*
* myTexture.Apply();*

* this.renderer.material.mainTexture = myTexture;*

* }*

* }*

}

In conclusion from the discussion above, your problem is that both printPixels and backgroundPixels refer to the same array. Make sure one is a copy of the other, not a reference:

Reference:

printPixels=backgroundPixels;

Copy:

printPixels=new Color[backgroundPixels.Length]; // will not copy the *contents*, only provide the memory

If it’s still unclear, we’ll need to see the code where you actually create/assign the array to both printPixels and backgroundPixels.