// Update is called once per frame
    void Update()
    {
        if (lives == 2 && hits == 3 && flag1 == false)
        {
            flag1 = true;
            color = Random.Range(3, 6);
            GetComponent <MeshRenderer>().material = materials[color];
        }
        else if (lives == 1 && hits != 1 && flag2 == false)
        {
            flag2  = true;
            color -= 3;
            GetComponent <MeshRenderer>().material = materials[color];
        }
        else if (lives == 0 && flag3 == false)
        {
            flag3 = true;
            bottom.GetComponent <Lose_Script>().score += points;
            bottom.GetComponent <Lose_Script>().brick_count++;

            if (has_powerup)
            {
                PowerUp.GetComponent <PowerUp_Script>().start = true;
                PowerUp.GetComponent <BoxCollider>().enabled  = true;
                PowerUp.GetComponent <MeshRenderer>().enabled = true;
                PowerUp.transform.position = transform.position;
            }

            GetComponent <MeshRenderer>().enabled = false;
            GetComponent <BoxCollider>().enabled  = false;
            SoundManagerScript.PlaySoundFX("brick_break");
        }
    }
    public void Tap()
    {
        follow = false;
        Vector3 direction = new Vector3(-1, 0, 1);

        GetComponent <Rigidbody>().AddForce(direction.normalized * speed);
        SoundManagerScript.PlaySoundFX("tap");
    }
Example #3
0
    // Update is called once per frame
    void Update()
    {
        for (int i = 0; i < Input.touchCount; i++)
        {
            var touch = Input.GetTouch(i);
            if (touch.phase == TouchPhase.Began)
            {
                if (!EventSystem.current.IsPointerOverGameObject(touch.fingerId))
                {
                    if (lives == 0 || brick_count == Blocks.transform.childCount)
                    {
                        Restart();
                    }
                    else if (Ball.GetComponent <Ball_Script>().follow == true)
                    {
                        Ball.GetComponent <Ball_Script>().Tap();
                        TapToStart.enabled = false;
                    }
                }
            }
        }

        if (Input.GetKeyDown(KeyCode.Space))
        {
            if (lives == 0 || brick_count == Blocks.transform.childCount)
            {
                Restart();
            }
            else if (Ball.GetComponent <Ball_Script>().follow == true)
            {
                Ball.GetComponent <Ball_Script>().Tap();
                TapToStart.enabled = false;
            }
        }

        Score.GetComponent <Text>().text = "Score: " + "<color=yellow>" + score + "</color>";
        Lives.GetComponent <Text>().text = "Lives: " + "<color=red>" + lives + "</color>";

        // Game Over
        if (lives == 0)
        {
            GameOver.enabled     = true;
            TapToRestart.enabled = true;
            Ball.GetComponent <Ball_Script>().speed = 0f;
            SoundManagerScript.PlaySoundFX("game_lose");
        }

        // Win
        if (brick_count == Blocks.transform.childCount)
        {
            Win.enabled          = true;
            TapToRestart.enabled = true;
            Ball.GetComponent <Ball_Script>().speed = 0f;
            SoundManagerScript.PlaySoundFX("game_win");
        }
    }
 private void OnCollisionExit(Collision collision)
 {
     if (collision.gameObject == GameObject.Find("Ball") && GameObject.Find("Ball").GetComponent <Ball_Script>().follow == false)
     {
         SoundManagerScript.PlaySoundFX("ball_bounce");
         if (destructible)
         {
             lives--;
         }
     }
 }
Example #5
0
    private void OnTriggerEnter(Collider collider)
    {
        if (collider.gameObject == Ball && Ball.GetComponent <Ball_Script>().follow == false)
        {
            lives--;
            SoundManagerScript.PlaySoundFX("ball_destroyed");
            Ball.GetComponent <Ball_Script>().Respawn();
        }

        if (collider.gameObject.transform.IsChildOf(GameObject.Find("PowerUps").transform))
        {
            collider.gameObject.GetComponent <PowerUp_Script>().start = false;
            collider.gameObject.GetComponent <PowerUp_Script>().GetComponent <MeshRenderer>().enabled = false;
            collider.gameObject.GetComponent <PowerUp_Script>().GetComponent <BoxCollider>().enabled  = false;
            collider.gameObject.GetComponent <PowerUp_Script>().transform.position = collider.gameObject.GetComponent <PowerUp_Script>().pos;
        }
    }
    private void OnTriggerEnter(Collider collider)
    {
        SoundManagerScript.PlaySoundFX("powerup_pick");

        if (collider.gameObject == GameObject.Find("Platform") && name == "Bigger")
        {
            Bottom.GetComponent <Lose_Script>().score += powerups_points;
            Platform.GetComponent <Platform_Script>().Reset();
            Platform.GetComponent <Transform>().localScale = new Vector3(Platform.GetComponent <Platform_Script>().size.x, Platform.GetComponent <Platform_Script>().size.y, Platform.GetComponent <Platform_Script>().size.z * 2);
            Disable();
        }
        else if (collider.gameObject == GameObject.Find("Platform") && name == "Smaller")
        {
            Bottom.GetComponent <Lose_Script>().score += powerups_points;
            Platform.GetComponent <Platform_Script>().Reset();
            Platform.GetComponent <Transform>().localScale = new Vector3(Platform.GetComponent <Platform_Script>().size.x, Platform.GetComponent <Platform_Script>().size.y, Platform.GetComponent <Platform_Script>().size.z / 2);
            Disable();
        }
        else if (collider.gameObject == GameObject.Find("Platform") && name == "Extra Life")
        {
            Bottom.GetComponent <Lose_Script>().score += powerups_points;
            Bottom.GetComponent <Lose_Script>().lives++;
            Disable();
        }
        else if (collider.gameObject == GameObject.Find("Platform") && name == "Fast Ball")
        {
            Bottom.GetComponent <Lose_Script>().score += powerups_points;
            Platform.GetComponent <Platform_Script>().Reset();
            Ball.GetComponent <Ball_Script>().speed *= 2;
            Disable();
        }
        else if (collider.gameObject == GameObject.Find("Platform") && name == "Slow Ball")
        {
            Bottom.GetComponent <Lose_Script>().score += powerups_points;
            Platform.GetComponent <Platform_Script>().Reset();
            Ball.GetComponent <Ball_Script>().speed /= 2;
            Disable();
        }
        else if (collider.gameObject == GameObject.Find("Platform") && name == "Shield")
        {
            Bottom.GetComponent <Lose_Script>().score  += powerups_points;
            Shield.GetComponent <Shield_Script>().shown = true;
            Disable();
        }
    }