Example #1
0
    // Update is called once per frame
    void Update()
    {
        if (UserPaddle.isStarted)
        {
            if (ball.transform.position.z <= lose_wall.transform.position.z || losed)
            {
                if (!audio.isPlaying)
                {
                    t = audio.clip.length;
                    audio.Play();
                }
                losed = true;
                t    -= Time.deltaTime;
                //Debug.Log (t);
                if (t < 0)
                {
                    UserPaddle.reset();
                    Application.LoadLevel("pong");
                }
            }


            if (!starting)
            {
                ball.rigidbody.isKinematic = false;
                ball.rigidbody.velocity    = new Vector3(0.0f, -1.0f, 1.0f);
                starting = true;
            }

            if (ball.rigidbody.mass != 1.0f)
            {
                ball.rigidbody.mass = 1.0f;
            }
            ball.rigidbody.velocity = force * ball.rigidbody.velocity.normalized;
            //Debug.Log (lastTap);

            if (ball.rigidbody.velocity.z < 5.0f && ball.rigidbody.velocity.z > -5.0f)
            {
                //Debug.Log (ball.rigidbody.velocity);
                if (lastTap == "AI Paddle")
                {
                    ball.rigidbody.velocity += new Vector3(0.0f, 0.0f, -5.0f);
                }
                else if (lastTap == "Player Paddle")
                {
                    ball.rigidbody.velocity += new Vector3(0.0f, 0.0f, 5.0f);
                }
            }
        }
        else
        {
            ball.rigidbody.isKinematic = true;
        }
    }
Example #2
0
    void lose()
    {
        UserPaddle.reset();
        audio.Play();
        pauseAndResume();
        float t    = audio.clip.length;
        float time = Time.time;

        while (Time.time - time < t)
        {
            ;
        }
        Application.LoadLevel("pong");
    }