Is there a loop in my code i don't know about?

hello i was making code for saving the state of objects then when the game loads again they reappear, but when i try to test it in play mode unity freezes and i can’t test it, this is the code :

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using System;

public class Fish_Manager : MonoBehaviour
{

    public List<GameObject> fishSpawnable;
    public List<GameObject> foodSpawnable;
    public List<GameObject> fishies;
    public List<Food> foods;

    public System.DateTime lastPlayTime;

    public List<float> perServe;
    public List<float> leftovers;

    public float total;
    public float max;
    public float min;
    
    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        foreach (var fish in fishies)
        {
            if (fish.GetComponent<Basic_Hunger>()) {
                int numb = fishies.IndexOf(fish);
                PlayerPrefs.SetString("FishSlot" + numb, fishies[numb].GetComponent<Fish_Name>().name);
                PlayerPrefs.SetInt("MaxFishSlots", numb + 1);
            }
        }
        PlayerPrefs.SetString("LastPlayTime", System.DateTime.Now.ToString());
        foreach (var food in foods)
        {
            PlayerPrefs.SetInt("FoodFillExit" + "_" + foods.IndexOf(food), (int)food.filling);
            PlayerPrefs.SetFloat("FoodEatnExit" + "_" + foods.IndexOf(food), food.eaten);
            PlayerPrefs.SetInt("MaxFood", foods.IndexOf(food) + 1);
        }
        foods.OrderBy(f => f.rank);
    }

    void OnApplicationQuit() {
        PlayerPrefs.Save();
    }

    void Awake()
    {
        for (int i = 0; i < PlayerPrefs.GetInt("MaxFishSlots"); i++)
        {
            if (PlayerPrefs.GetString("FishSlot" + i) == "anchovy") {
                GameObject spawnedFish = Instantiate(fishSpawnable[0], new Vector3(UnityEngine.Random.Range(max, min), UnityEngine.Random.Range(max, min), UnityEngine.Random.Range(max, min)), Quaternion.identity);
                fishies.Add(spawnedFish);
            }
            if (PlayerPrefs.GetString("FishSlot" + i) == "goldfish") {
                GameObject spawnedFish = Instantiate(fishSpawnable[1], new Vector3(UnityEngine.Random.Range(max, min), UnityEngine.Random.Range(max, min), UnityEngine.Random.Range(max, min)), Quaternion.identity);
                fishies.Add(spawnedFish);
            }
            if (PlayerPrefs.GetString("FishSlot" + i) == "clownfish") {
                GameObject spawnedFish = Instantiate(fishSpawnable[2], new Vector3(UnityEngine.Random.Range(max, min), UnityEngine.Random.Range(max, min), UnityEngine.Random.Range(max, min)), Quaternion.identity);
                fishies.Add(spawnedFish);
            }
            if (PlayerPrefs.GetString("FishSlot" + i) == "piranha") {
                GameObject spawnedFish = Instantiate(fishSpawnable[3], new Vector3(UnityEngine.Random.Range(max, min), UnityEngine.Random.Range(max, min), UnityEngine.Random.Range(max, min)), Quaternion.identity);
                fishies.Add(spawnedFish);
            }
            if (PlayerPrefs.GetString("FishSlot" + i) == "pufferfish") {
                GameObject spawnedFish = Instantiate(fishSpawnable[4], new Vector3(UnityEngine.Random.Range(max, min), UnityEngine.Random.Range(max, min), UnityEngine.Random.Range(max, min)), Quaternion.identity);
                fishies.Add(spawnedFish);
            }
        }
        for (int i = 0; i < PlayerPrefs.GetInt("MaxFood"); i++)
        {
            if (PlayerPrefs.GetInt("FoodFillExit" + "_" + i) == 1) {
                GameObject spawnedFood = Instantiate(foodSpawnable[0], new Vector3(UnityEngine.Random.Range(max, min), UnityEngine.Random.Range(max, min), UnityEngine.Random.Range(max, min)), Quaternion.identity);
                spawnedFood.GetComponent<Food>().eaten = PlayerPrefs.GetInt("FoodEatnExit" + "_" + i);
                foods.Add(spawnedFood.GetComponent<Food>());
            }
            if (PlayerPrefs.GetInt("FoodFillExit" + "_" + i) == 2) {
                GameObject spawnedFood = Instantiate(foodSpawnable[1], new Vector3(UnityEngine.Random.Range(max, min), UnityEngine.Random.Range(max, min), UnityEngine.Random.Range(max, min)), Quaternion.identity);
                spawnedFood.GetComponent<Food>().eaten = PlayerPrefs.GetInt("FoodEatnExit" + "_" + i);
                foods.Add(spawnedFood.GetComponent<Food>());
            }
            if (PlayerPrefs.GetInt("FoodFillExit" + "_" + i) == 3) {
                GameObject spawnedFood = Instantiate(foodSpawnable[2], new Vector3(UnityEngine.Random.Range(max, min), UnityEngine.Random.Range(max, min), UnityEngine.Random.Range(max, min)), Quaternion.identity);
                spawnedFood.GetComponent<Food>().eaten = PlayerPrefs.GetInt("FoodEatnExit" + "_" + i);
                foods.Add(spawnedFood.GetComponent<Food>());
            }
            if (PlayerPrefs.GetInt("FoodFillExit" + "_" + i) == 4) {
                GameObject spawnedFood = Instantiate(foodSpawnable[3], new Vector3(UnityEngine.Random.Range(max, min), UnityEngine.Random.Range(max, min), UnityEngine.Random.Range(max, min)), Quaternion.identity);
                spawnedFood.GetComponent<Food>().eaten = PlayerPrefs.GetInt("FoodEatnExit" + "_" + i);
                foods.Add(spawnedFood.GetComponent<Food>());
            }
            if (PlayerPrefs.GetInt("FoodFillExit" + "_" + i) == 5) {
                GameObject spawnedFood = Instantiate(foodSpawnable[4], new Vector3(UnityEngine.Random.Range(max, min), UnityEngine.Random.Range(max, min), UnityEngine.Random.Range(max, min)), Quaternion.identity);
                spawnedFood.GetComponent<Food>().eaten = PlayerPrefs.GetInt("FoodEatnExit" + "_" + i);
                foods.Add(spawnedFood.GetComponent<Food>());
            }
        }
        string lastPlayTimeString = PlayerPrefs.GetString("LastPlayTime", string.Empty);
        if (!string.IsNullOrEmpty(lastPlayTimeString))
        {
            int size = fishies.Count;
            List<int> list = new List<int>();
            for (int i = 0; i < size; i++) {
                perServe.Add(0);
                leftovers.Add(0);
            }
            foreach (var serve in perServe.ToList())
            {
                int serveNumb = perServe.IndexOf(serve);
                foreach (var food in foods)
                {
                    total += food.GetComponent<Food>().filling * (food.GetComponent<Food>().eatenMax - food.GetComponent<Food>().eaten);
                    perServe[serveNumb] = total / fishies.Count;
                }
            }
            System.DateTime lastPlayTime = System.DateTime.Parse(lastPlayTimeString);
            System.TimeSpan elapsedTime = System.DateTime.Now - lastPlayTime;
            foreach (var fish in fishies)
            {
                // gameTime += (float)elapsedTime.TotalSeconds;
                int fishNumb = fishies.IndexOf(fish);
                Basic_Hunger fishHung = fish.GetComponent<Basic_Hunger>();
                fishHung.hunger -= (float)elapsedTime.TotalSeconds * (1 / fishHung.multiplier);
                float addNumb = fishHung.maxHunger -= fishHung.hunger; // 4
                float addedNumb = (perServe[fishNumb] -= addNumb); // 6 -> 2
                if (addedNumb <= 0) {
                    float decreasedNumb = addNumb += addedNumb;
                    perServe[fishNumb] = 0;
                    fishHung.hunger += decreasedNumb;
                }
                if (addedNumb > 0) {
                    perServe[fishNumb] = (int)addedNumb;
                    fishHung.hunger += addedNumb;
                }
            }
            foods.OrderBy(f => f.rank);
            for (int i = 0; i < foods.Count;)
            {
                foreach (var served in perServe)
                {
                    if (served == 0 && foods[i].eaten > 0) {
                        foods[i].eaten -= total / fishies.Count;
                    }
                    if (served > 0 && foods[i].eaten > 0) {
                        float comp = (total/fishies.Count) + served;
                        if ((foods[i].eaten -= comp) >= 0) {
                            foods[i].eaten -= comp;
                            i++;
                        }
                        if ((foods[i].eaten -= comp) < 0) {
                            comp -= foods[i].eaten;
                            foods[i].eaten = 0;
                            i++;
                            foods[i].eaten -= comp;
                        }
                    }
                }
            }
        }
    }
}

Edit: it appears that the problem was where i was spawning the food and assigning it, still don’t know why it freezes unity but will try to fix it
Edit 2: so i experimented a bit and apparently “foods.Add(spawnedFood.GetComponent());” is what is freezing my code…? i’ll try to fix it but i don’t know if it will work
Edit 3: i changed it so that it didn’t do “foods.Add(spawnedFood.GetComponent());” but instead did “var foodS = spawnedFood.GetComponent();” then “foods.Add(foodS);” and now it doesn’t freeze :+1: