示例#1
0
    // Update is called once per frame
    void Update()
    {
        // get uart value
        uart.Update();
        if (uart.interrupt_flag == true)
        {
            uart.CloseSerial();
            if (selectValue > 512)
            {
                SceneManager.LoadScene(0);
            }
            else
            {
                SceneManager.LoadScene(2);
            }
        }
        else if (uart.data != "")
        {
            try {
                selectValue = Int32.Parse(uart.data.Split(',')[0]);
            } catch (Exception) {}
        }
        Debug.Log(uart.data);

        if (selectValue < 512)
        {
            button[0].GetComponent <Image>().color = new Color(0.7f, 0.4f, 0.4f);
            button[1].GetComponent <Image>().color = Color.white;
        }
        else
        {
            button[0].GetComponent <Image>().color = Color.white;
            button[1].GetComponent <Image>().color = new Color(0.7f, 0.4f, 0.4f);
        }
    }
示例#2
0
 void Update()
 {
     uart.Update();
     uart.Clear();
     if (uart.interrupt_flag == true)
     {
         SceneManager.LoadScene(1);
         uart.CloseSerial();
     }
     ApplyVisual();
 }
示例#3
0
    // Update is called once per frame
    void Update()
    {
        // get uart value
        uart.Update();
        if (uart.interrupt_flag == true)
        {
            // jump
            if (heart_count <= 0)
            {
                uart.CloseSerial();
                SceneManager.LoadScene(1);
            }
            else
            {
                uart.interrupt_flag = false;
                if (_rigidbody.velocity.y == 0)
                {
                    _rigidbody.AddForce(new Vector2(0, jumpforce), ForceMode2D.Impulse);
                }
            }
        }
        else if (uart.data != "")
        {
            try {
                //Debug.Log(uart.data);
                //serial_speed = 512 - Int32.Parse(uart.data);
                serial_speed = 512 - Int32.Parse(uart.data.Split(',')[0]);
            } catch (Exception) {
                //Debug.Log("Format Exception: " + uart.data);
            }
        }

        if (_rigidbody.velocity.y > 0)
        {
            //jump
            animator.SetInteger("status", 3);
        }
        else if (_rigidbody.velocity.y < 0)
        {
            //dowm
            animator.SetInteger("status", 5);
        }
        else
        {
            //run
            animator.SetInteger("status", 1);
        }
        //down in the air
        if (serial_speed > 0 && Mathf.Abs(_rigidbody.velocity.y) > 0)
        {
            animator.SetInteger("status", 5);
            transform.position += new Vector3(0, 1, 0) * Time.deltaTime * -speed;
        }
        //down on the land
        else if (serial_speed > 0)
        {
            animator.SetInteger("status", 2);
            transform.localScale = new Vector3(13.6f, 8.6f, 1);
            transform.position  += new Vector3(0, 1, 0) * Time.deltaTime * -speed;
        }
        else
        {
            transform.localScale = new Vector3(13.6f, 13.6f, 1);
        }

        var movement = Input.GetAxis("Horizontal");

        //left
        if (Input.GetKey(KeyCode.A))
        {
            transform.position += new Vector3(movement, 0, 0) * Time.deltaTime * speed;
        }
        ////right
        if (Input.GetKey(KeyCode.D))
        {
            transform.position += new Vector3(movement, 0, 0) * Time.deltaTime * speed;
        }

        if (Input.GetKeyUp(KeyCode.S))
        {
            transform.localScale = new Vector3(13.6f, 13.6f, 1);
        }

        if (Input.GetKey(KeyCode.Escape))
        {
            SceneManager.LoadScene(1);
        }
    }
示例#4
0
    // Update is called once per frame
    void Update()
    {
        t += 1;

        // get uart value
        uart.Update();
        if (uart.interrupt_flag == true)
        {
            // jump
            if (heart_count <= 0)
            {
                uart.Send("mmm"); // pic18 exit fox game state
                uart.CloseSerial();
                SceneManager.LoadScene(1);
            }
            else
            {
                uart.interrupt_flag = false;
                if (_rigidbody.velocity.y == 0)
                {
                    _rigidbody.AddForce(new Vector2(0, jumpforce), ForceMode2D.Impulse);
                }
            }
        }
        else if (uart.data != "")
        {
            try {
                //Debug.Log(uart.data);
                //serial_speed = 512 - Int32.Parse(uart.data);
                string s    = uart.data;
                bool   is_t = false;
                for (int i = 0; i < s.Length; i++)
                {
                    if (s[i] == 't')
                    {
                        is_t        = true;
                        count_time += 1;
                    }
                }
                if (is_t == false)
                {
                    serial_speed = Int32.Parse(uart.data);
                }
            } catch (Exception) {
                //Debug.Log("Format Exception: " + uart.data);
            }
        }

        // Debug.Log(uart.data);

        /*
         *  serial_speed is the value of acc
         */
        if (Math.Abs(serial_speed - last_ser) < 20)
        {
            standard_ser = serial_speed;
        }
        if (serial_speed - last_ser > 100 && t - standard_t > 100 && t > 100 && is_squad == false)
        {
            //jump
            if (_rigidbody.velocity.y == 0)
            {
                Debug.Log("jmp");
                _rigidbody.AddForce(new Vector2(0, jumpforce), ForceMode2D.Impulse);
            }

            standard_t = t;
        }
        else if ((serial_speed - last_ser < -100 && t - standard_t > 100))
        {
            Debug.Log("squad");
            is_squad   = true;
            squad_time = 0;
        }
        last_ser = serial_speed;

        if (is_squad == true)
        {
            squad_time += 1;
            ////down in the air
            if (Mathf.Abs(_rigidbody.velocity.y) > 0)
            {
                animator.SetInteger("status", 5);
                transform.position += new Vector3(0, 1, 0) * Time.deltaTime * -speed;
                _rigidbody.AddForce(new Vector2(0, -0.5f), ForceMode2D.Impulse);
            }
            //down on the land
            else
            {
                animator.SetInteger("status", 2);
                transform.localScale = new Vector3(13.6f, 8.6f, 1);
                transform.position  += new Vector3(0, 1, 0) * Time.deltaTime * -speed;
            }

            standard_t = t;
        }

        if (squad_time > 700)
        {
            is_squad             = false;
            transform.localScale = new Vector3(13.6f, 13.6f, 1);
        }

        if (count_time % 10 == 0)
        {
            //bizzer loudly speek
        }
        if (_rigidbody.velocity.y > 0)
        {
            animator.SetInteger("status", 3);
        }
        else if (_rigidbody.velocity.y < 0)
        {
            animator.SetInteger("status", 5);
        }
        else
        {
            animator.SetInteger("status", 1);
        }
        var movement = Input.GetAxis("Horizontal");

        //transform.position += new Vector3(movement, 0, 0) * Time.deltaTime * speed;

        if (Input.GetKey(KeyCode.Escape))
        {
            SceneManager.LoadScene(1);
        }

        ////down in the air
        if (Input.GetKey(KeyCode.S) && Mathf.Abs(_rigidbody.velocity.y) > 0)
        {
            animator.SetInteger("status", 5);
            transform.position += new Vector3(0, 1, 0) * Time.deltaTime * -speed;
            _rigidbody.AddForce(new Vector2(0, -0.5f), ForceMode2D.Impulse);
        }
        //down on the land
        else if (Input.GetKey(KeyCode.S))
        {
            animator.SetInteger("status", 2);
            transform.localScale = new Vector3(13.6f, 8.6f, 1);
            transform.position  += new Vector3(0, 1, 0) * Time.deltaTime * -speed;
        }
        if (Input.GetKeyUp(KeyCode.S))
        {
            transform.localScale = new Vector3(13.6f, 13.6f, 1);
        }
        //left and check border
        if (Input.GetKey(KeyCode.A) && transform.position.x > -92)
        {
            animator.SetInteger("status", 1);
            transform.position += new Vector3(movement, 0, 0) * Time.deltaTime * speed;
        }
        ////right
        if (Input.GetKey(KeyCode.D) && transform.position.x < -71.5)
        {
            animator.SetInteger("status", 1);
            transform.position += new Vector3(movement, 0, 0) * Time.deltaTime * speed;
        }
        //jmp
        if ((Input.GetKey(KeyCode.Space) || Input.GetKey(KeyCode.W)) && _rigidbody.velocity.y == 0)
        {
            Debug.Log("jmp");
            _rigidbody.AddForce(new Vector2(0, jumpforce), ForceMode2D.Impulse);
        }

        //if (Input.GetKey(KeyCode.S))
        //{
        //    animator.SetInteger("status", 2);
        //    _rigidbody.AddForce(new Vector2(0, -jumpforce / 3), ForceMode2D.Impulse);
        //}
    }