game jumps through levels and only counts last level

So I am trying to create a game that responds to a sensor and works with a timer as well. So the first level will be: if x amount of force is applied to the sensor for y amount of time, then the next level can be accessed. What my game is currently doing, is that it jumps through the first three levels and only counts down fully in the last level. I have attached the timer and the game codes below. The different time levels have been specified in the actual unity interface as depicted in the attached image. Each level has a different time specified 122310-timer.png

Game code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO.Ports; 

public class arduino : MonoBehaviour {
	
	SerialPort sp = new SerialPort("\\\\.\\COM6", 9600);// Com port and the baud rate of the arduino
	Material m_Material;
	GameObject Sphere;



	void Awake(){
		Sphere = GameObject.FindWithTag ("Player");
		m_Material = GameObject.FindWithTag ("Player").GetComponent<Renderer > ().material ;
	}
	void Start ()
    {
		if (!sp.IsOpen) 
		{ // If the serial port is not open 
			sp.Open(); // Open 
		}
		sp.ReadTimeout = 250; // Timeout for reading 
     }
	// Update is called once per frame
	void Update () {
		if (sp.IsOpen) { // Check to see if the serial port is open 
            try
            {

                string portreading = sp.ReadLine(); // get the string output of the serial port 
                float amount = int.Parse(portreading);



                if ((amount > 10f) && (amount < 100f))
                {
                    m_Material.color = Color.grey;
                   // Sphere.transform.position = (new Vector3(0f, amount * 0.1f, 0f));


                }

                if ((amount > 101f) && (amount < 150f))
                {
                    m_Material.color = Color.blue;
                    //Sphere.transform.position = (new Vector3(0f, amount * 0.1f, 0f));
                }

                if ((amount > 151f) && (amount < 201f))
                {
                    m_Material.color = Color.yellow;
                    //Sphere.transform.position = (new Vector3(0f, amount * 0.1f, 0f));
                }
                if ((amount > 201f))          
                {
                    m_Material.color = Color.red;
                   // Sphere.transform.position = (new Vector3(0f, amount * 0.1f, 0f));


                }
            }
            catch (System.Exception)
            {

            }

		}

	}
	}

Timer code:

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class Timer : MonoBehaviour
{
    public int timeLeft = 5;
    public Text countdownText;

    // Use this for initialization
    void Start()
    {
        StartCoroutine("LoseTime");
    }

    // Update is called once per frame
    void Update()
    {
        countdownText.text = ("Time Left = " + timeLeft);

        if (timeLeft <= 0)
        {
            StopCoroutine("LoseTime");
            countdownText.text = "Times Up!";
        }
        Invoke("ChangeLevel", 0.1f);
    }

    IEnumerator LoseTime()
    {
        while (true)
        {
            yield return new WaitForSeconds(1);
            timeLeft--;
        }
    }
    void ChangeLevel()
    {

        SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
    }

}

Please assist, I feel stuck at this point, will appreciate any assistance

Hi, in your timer code you have written:

     void Update()
     {
         countdownText.text = ("Time Left = " + timeLeft);
 
         if (timeLeft <= 0)
         {
             StopCoroutine("LoseTime");
             countdownText.text = "Times Up!";
         }
         Invoke("ChangeLevel", 0.1f);
     }

but the line “Invoke(“ChangeLevel”, 0.1f);” will be executed in the first frame. I think you wanted to put it in the if function like so:

      void Update()
      {
          countdownText.text = ("Time Left = " + timeLeft);
  
          if (timeLeft <= 0)
          {
              StopCoroutine("LoseTime");
              countdownText.text = "Times Up!";
              Invoke("ChangeLevel", 0.1f);
          }
      }