IEnumerator DrawPixels() { int currentPixelRow = 0; ShellDisplay.isReloading[shellDisplayIndex] = 1; //this line is so that other shells now this one is reloading isCurrentlyLoading = true; //this is one is so that the coroutine just runs once //filling a part of the temporary texture with the target texture while (currentPixelRow < targetTexture.height) { //Debug.Log("currentPixel: " + currentPixelRow); for (int y = currentPixelRow; y < currentPixelRow + 1; y++) { for (int x = 0; x < tmpTexture.width; x++) { tmpTexture.SetPixel(x, y, targetTextureColors[x, y]); } tmpTexture.Apply(); gameObject.GetComponent <RawImage>().texture = tmpTexture; } currentPixelRow++; yield return(new WaitForSeconds(Time.deltaTime * reloadingTimeFactor)); } isCurrentlyLoading = false; int ammo = WeaponsController.GetCurrentAmmo(); WeaponsController.SetCurrentAmmo(ammo + 1); ShellDisplay.isReloading[shellDisplayIndex] = 0; WeaponsController.SetShellAsLoaded(shellDisplayIndex); ResetTextures(); enabled = false; }