示例#1
0
    void FixedUpdate()
    {
        if (leftWall.isBroken || rightWall.isBroken)
        {
            if (leftWall.isBroken)
            {
                print("Player 2 has won the round!");
                if (rightPlayer.GetComponent <PlayerAI> ())
                {
                    rightPlayer.GetComponent <PlayerAI> ().speed--;
                    print("The AI's speed has decreased to " + rightPlayer.GetComponent <PlayerAI> ().speed);
                }
            }

            if (rightWall.isBroken)
            {
                print("Player 1 has won the round!");
                if (rightPlayer.GetComponent <PlayerAI> ())
                {
                    rightPlayer.GetComponent <PlayerAI> ().speed++;
                    print("The AI's speed has increased to " + rightPlayer.GetComponent <PlayerAI> ().speed);
                }
            }

            StartCoroutine(leftWall.ResetHealth());
            StartCoroutine(rightWall.ResetHealth());
            topWall.Reset();
            bottomWall.Reset();
            leftPlayer.GetComponent <Paddle> ().ResetXPosition();
            rightPlayer.GetComponent <Paddle> ().ResetXPosition();
            print("New Round");
        }



        if (puck.isDestroyed)
        {
            puck.isDestroyed = false;
            StartCoroutine(puck.ResetPosition());
            StartCoroutine(Countdown());
        }



        if (puck.body.velocity.x > 0 && puck.initialCollision)
        {
            puck.ColorChange(leftPlayer.GetComponent <Renderer> ().material.color);
        }
        else if (puck.body.velocity.x < 0 && puck.initialCollision)
        {
            puck.ColorChange(rightPlayer.GetComponent <Renderer> ().material.color);
        }
        else
        {
            puck.ColorChange(Color.white);
        }
    }
示例#2
0
    void Start()
    {
        leftWall   = GameObject.FindGameObjectWithTag("Left Wall").GetComponent <BreakableWall>();
        rightWall  = GameObject.FindGameObjectWithTag("Right Wall").GetComponent <BreakableWall>();
        topWall    = GameObject.FindGameObjectWithTag("Top Wall").GetComponent <ColorFlash>();
        bottomWall = GameObject.FindGameObjectWithTag("Bottom Wall").GetComponent <ColorFlash>();

        soundManager = GameObject.FindObjectOfType <SoundManager> ();
        canvas       = GameObject.FindObjectOfType <Canvas>();

        text = canvas.GetComponentInChildren <Text> ();

        leftPlayer  = Instantiate(leftPlayer, new Vector3(-6, 0, 0), Quaternion.identity);
        rightPlayer = Instantiate(rightPlayer, new Vector3(6, 0, 0), Quaternion.identity);

        puck = Instantiate(puck, Vector3.zero, Quaternion.identity);

        puck.Initialize();

        StartCoroutine(puck.ResetPosition());
        StartCoroutine(Countdown());
    }