Example #1
0
    // Update is called once per frame
    void FixedUpdate()
    {
        float posx = tr.position.x + (speed * Time.deltaTime);
        float posy = tr.position.y;

        tr.position = new Vector2(posx, posy);
        if (Input.GetKeyDown(keyCode) && interf.Started())
        {
            if (canAttack && !attackFailed)
            {
                StartCoroutine("Win");
            }
            else
            {
                StartCoroutine("FailAttack");
            }
        }
        if (!swapped && !GetComponent <Renderer>().isVisible)
        {
            speed = -speed;
            Flip();
            swapped = true;
        }
        if (swapped && GetComponent <Renderer>().isVisible)
        {
            swapped = false;
        }
    }
Example #2
0
    void Update()
    {
        if (scoreInterface.Started())
        {
            Vector3 dp = new Vector3();

            if (Input.GetKeyDown(KeyCode.Q))
            {
                countLeft++;
            }

            if (Input.GetKeyDown(KeyCode.M))
            {
                countRight++;
            }

            if (Time.time > nextRope)
            {
                nextRope = Time.time + ropeRate;
                if (countLeft > countRight)
                {
                    dp.x -= speed;
                }
                else if (countLeft < countRight)
                {
                    dp.x += speed;
                }

                transform.position += dp;

                countLeft  = 0;
                countRight = 0;
            }

            float centerPointSize = centerpointCollider.size.x;

            float ropeScale = transform.localScale.x;
            float ropeSize  = ropeCollider.size.x;

            if (transform.position.x > (centerPointSize + ropeSize) / 2)
            {
                GlobalController.instance.IncRoundScoreRed();
                //Debug.Log("Right Win !");
                //Destroy(secondRope.GetComponent<SpriteRenderer>());
                //Destroy(secondRope);
                //Destroy(this.GetComponent<SpriteRenderer>());
                //Destroy(this);
            }
            else if (transform.position.x < -(centerPointSize + ropeSize) / 2)
            {
                GlobalController.instance.IncRoundScoreBlue();
                //Debug.Log("Left Win !");
                //Destroy(secondRope.GetComponent<SpriteRenderer>());
                //Destroy(secondRope);
                //Destroy(this.GetComponent<SpriteRenderer>());
                //Destroy(this);
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (interf.Started())
        {
            float   horizontal_p1 = Input.GetAxisRaw("Horizontal2");
            float   vertical_p1   = Input.GetAxisRaw("Vertical2");
            Vector2 fVelocity_p1  = new Vector2(horizontal_p1, vertical_p1) * speed;
            rb_player1.velocity = fVelocity_p1;

            float   horizontal_p2 = Input.GetAxisRaw("Horizontal");
            float   vertical_p2   = Input.GetAxisRaw("Vertical");
            Vector2 fVelocity_p2  = new Vector2(horizontal_p2, vertical_p2) * speed;
            rb_player2.velocity = fVelocity_p2;

            bool player1_check = Mathf.Abs(player1.transform.position.x - (mazeGenerator.Get_width())) <= 1.5f && Mathf.Abs(player1.transform.position.y - (mazeGenerator.Get_height())) <= 1.5f;
            bool player2_check = Mathf.Abs(player2.transform.position.x - (mazeGenerator.Get_width())) <= 1.5f && Mathf.Abs(player2.transform.position.y - (mazeGenerator.Get_height())) <= 1.5f;
            if (player1_check && !finishedGame)
            {
                if (!GetComponent <AudioSource>().isPlaying)
                {
                    GetComponent <AudioSource>().Play();
                }
                winner       = 1;
                finishedGame = true;
                StartCoroutine(BlueWon());
            }
            if (player2_check && !finishedGame)
            {
                if (!GetComponent <AudioSource>().isPlaying)
                {
                    GetComponent <AudioSource>().Play();
                }
                winner       = 2;
                finishedGame = true;
                StartCoroutine(RedWon());
            }
        }
    }