void Update()
    {
        if (Input.GetAxis("Horizontal") != 0)
        {
            transform.RotateAround(rotateAround.position, Vector3.up, -Input.GetAxis("Horizontal") * rotationSpeed);
        }

        float avgO2   = 0;
        float avgTemp = 0;

        foreach (var p in particlesList)
        {
            ParticleScript ps = p.GetComponent <ParticleScript>();

            if (isVentilated)
            {
                ps.SetO2(ps.o2Con + (ventilationIntence * Time.deltaTime));
            }

            avgO2   += p.GetComponent <ParticleScript>().o2Con;
            avgTemp += p.GetComponent <Rigidbody>().velocity.magnitude;
        }

        avgO2   /= (float)particlesList.Count;
        avgTemp /= (float)particlesList.Count;

        o2ConText.text = (avgO2 * 100f).ToString("0.00") + " %";
        tempText.text  = (avgTemp * 10f).ToString("0.00") + " C°";

        o2Chart.chartLines[Color.blue].Add(new Vector2(Time.timeSinceLevelLoad, avgO2));
        o2Chart.chartLines[Color.red].Add(new Vector2(Time.timeSinceLevelLoad, 1 - avgO2));

        temperatureChart.chartLines[Color.red].Add(new Vector2(Time.timeSinceLevelLoad, avgTemp));
        prevMousePos = Input.mousePosition;
    }
    private void OnCollisionExit(Collision collision)
    {
        if (ButtonFunctions.windowRunning)
        {
            Rigidbody      tmpr        = collision.gameObject.GetComponent <Rigidbody>();
            ParticleScript tmpp        = collision.gameObject.GetComponent <ParticleScript>();
            float          tempDelta   = outsideTemp - tmpr.velocity.magnitude;
            float          oxygendelta = outsideOxygen - tmpp.o2Con;

            tmpr.velocity += tmpr.velocity.normalized * (tempDelta * heatExchange);
            tmpp.SetO2(tmpp.o2Con + oxygendelta * oxygenExchange);
        }
    }
    void Update()
    {
        unCollidables.RemoveAll(p => {
            bool check = (p.transform.position - transform.position).magnitude > collisionActiveDistance;
            if (check)
            {
                Physics.IgnoreCollision(GetComponent <SphereCollider>(), p.GetComponent <SphereCollider>(), false);
            }
            return(check);
        }
                                );



        if (lastBreaath >= breathsDelay)
        {
            if (particlesList.Count == 0)
            {
                return;
            }

            lastBreaath    = 0.0f;
            breathProgress = 0.0f;

            breathDict.Clear();

            foreach (GameObject o in particlesList)
            {
                breathDict[o] = new Dictionary <string, float>()
                {
                    { "startTemp", o.GetComponent <Rigidbody>().velocity.magnitude },
                    { "inSpeed", (Vector3.Distance(o.transform.position, transform.position)) / breathInLength },
                };
                o.GetComponent <SphereCollider>().enabled = false;
                o.GetComponent <Rigidbody>().velocity     = Vector3.zero;
            }
            firstTime = true;
            index     = 0;
            timeBetweenParticlesOut = 10.0f;
            cycleName     = "Inhale";
            avgO2Absorbed = 0;
        }

        if (breathProgress >= 0.0f)
        {
            if (breathProgress <= breathInLength) // In
            {
                particlesList.ForEach(p => p.transform.position = Vector3.MoveTowards(p.transform.position, transform.position, breathDict[p]["inSpeed"] * Time.deltaTime));
            }
            else if (particlesList.Count > index && breathProgress > breathHoldDuration + breathInLength)
            {
                if (firstTime)
                {
                    firstTime = false;
                    particlesList.ForEach(p => p.SetActive(false));
                    cycleName = "Exhalation";
                }

                if (timeBetweenParticlesOut >= delayBetweenOutParticles)
                {
                    Physics.IgnoreCollision(GetComponent <SphereCollider>(), particlesList[index].GetComponent <SphereCollider>(), true);
                    particlesList[index].SetActive(true);
                    particlesList[index].GetComponent <Rigidbody>().velocity = relativePos * (breathDict[particlesList[index]]["startTemp"] - (breathDict[particlesList[index]]["startTemp"] - bodyTemp) * tempExchange);
                    //Debug.Log((bodyTemp + (breathDict[particlesList[index]]["startTemp"] - bodyTemp) * tempExchange) + "    " + breathDict[particlesList[index]]["startTemp"]);
                    particlesList[index].GetComponent <SphereCollider>().enabled = true;
                    ParticleScript tmpPs = particlesList[index].GetComponent <ParticleScript>();
                    avgO2Absorbed += (tmpPs.o2Con - tmpPs.minO2) * o2absord;
                    tmpPs.SetO2(tmpPs.o2Con - (tmpPs.o2Con - tmpPs.minO2) * o2absord);
                    timeBetweenParticlesOut = 0;
                    index++;
                }
                else
                {
                    timeBetweenParticlesOut += Time.deltaTime;
                }
            }
            else if (particlesList.Count == index)
            {
                unCollidables   = new List <GameObject>(particlesList);
                avgO2Absorbed  /= particlesList.Count;
                breathEfficenty = avgO2Absorbed / maxAbsorb;
                particlesList.Clear();
                breathProgress = -1000.0f;
                lastBreaath    = 0.0f;
            }

            breathProgress += Time.deltaTime;
        }


        if (breathProgress < 0.0f)
        {
            lastBreaath += Time.deltaTime;
        }
    }