Example #1
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if ((timeOfRoundEnd != -1) && (Time.time > (timeOfRoundEnd + 5)))
        {
            timeOfRoundEnd = -1;

            if ((PlayerPrefs.GetInt("player1Wins") == PlayerPrefs.GetInt("rounds")) || (PlayerPrefs.GetInt("player2Wins") == PlayerPrefs.GetInt("rounds")))
            {
                SceneManager.LoadScene(2);
            }
            else
            {
                SceneManager.LoadScene(1);
            }
            return;
        }
        if ((Time.time > (lastJumpTime + coolDownTime)) && (childMaterial.color == Color.gray))
        {
            childMaterial.color = Color.yellow;
        }
        if (!isSinking)
        {
            if (isFloating)
            {
                Vector3 normal = new Vector3(water.getVertexY(waterVertIndex - 1) - water.getVertexY(waterVertIndex + 1), -(water.getVertexX(waterVertIndex - 1) - water.getVertexX(waterVertIndex + 1)), 0);
                if (Time.time > (splashInvincibilityTime + splashTime))
                {
                    if (Vector3.Angle(Vector3.up, normal) > 5)
                    {
                        if (transform.position.x > 0)
                        {
                            if (transform.up.x >= 0)
                            {
                                transform.Rotate(Vector3.left * (normal.y * waveStrength));
                            }
                            else
                            {
                                transform.Rotate(Vector3.right * (normal.y * waveStrength));
                            }
                        }
                        else
                        {
                            if (transform.up.x <= 0)
                            {
                                transform.Rotate(Vector3.left * (normal.y * waveStrength));
                            }
                            else
                            {
                                transform.Rotate(Vector3.right * (normal.y * waveStrength));
                            }
                        }
                    }
                    else
                    {
                        if (transform.position.x > 0)
                        {
                            if (transform.up.x > 0)
                            {
                                transform.Rotate(Vector3.left * .05f);
                            }
                            else
                            {
                                transform.Rotate(Vector3.right * .05f);
                            }
                        }
                        else
                        {
                            if (transform.up.x < 0)
                            {
                                transform.Rotate(Vector3.left * .05f);
                            }
                            else
                            {
                                transform.Rotate(Vector3.right * .05f);
                            }
                        }
                    }
                }

                isFloating = true;
                Vector3 tempVec = transform.position;
                tempVec.y          = water.getVertexY(waterVertIndex);
                transform.position = tempVec;

                savedVelocity = transform.GetComponent <Rigidbody>().velocity;
                transform.GetComponent <Rigidbody>().velocity = Vector3.zero;

                if (Vector3.Angle(transform.up, Vector3.up) > 75)
                {
                    isSinking  = true;
                    isFloating = false;
                    if (victoryText.text == "")
                    {
                        if (transform.position.x > 0)
                        {
                            victoryText.GetComponents <AudioSource>()[0].Stop();
                            Camera.main.GetComponent <AudioSource>().Stop();
                            victoryText.GetComponents <AudioSource>()[1].Play();
                            victoryText.text = "Player 1 Wins!";
                            timeOfRoundEnd   = Time.time;
                            PlayerPrefs.SetInt("player1Wins", PlayerPrefs.GetInt("player1Wins") + 1);
                        }
                        else
                        {
                            victoryText.GetComponents <AudioSource>()[0].Stop();
                            Camera.main.GetComponent <AudioSource>().Stop();
                            victoryText.GetComponents <AudioSource>()[1].Play();
                            victoryText.text = "Player 2 Wins!";
                            timeOfRoundEnd   = Time.time;
                            PlayerPrefs.SetInt("player2Wins", PlayerPrefs.GetInt("player2Wins") + 1);
                        }
                    }
                }
            }
            if ((transform.GetComponent <Rigidbody>().velocity.y < 0) && (!isFloating) && (transform.transform.position.y < water.getVertexY(waterVertIndex)))
            {
                if (isSlamming)
                {
                    splashTime          = Time.time;
                    lastJumpTime        = Time.time;
                    childMaterial.color = Color.gray;
                    GetComponents <AudioSource>()[0].Play();
                }
                isSlamming = false;
                isFloating = true;
                Vector3 tempVec = transform.position;
                tempVec.y          = water.getVertexY(waterVertIndex);
                transform.position = tempVec;

                savedVelocity = transform.GetComponent <Rigidbody>().velocity;
                transform.GetComponent <Rigidbody>().velocity = Vector3.zero;
            }
        }
    }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        GetShipInput();
        if (victoryText.text == "" && MaxTime != 0)
        {
            time -= Time.deltaTime;
            if (time >= 0)
            {
                if (alarm.isPlaying)
                {
                    victoryText.GetComponents <AudioSource>()[0].volume = 1;
                    alarm.Stop();
                }
                CountDownTimer.text = "Timer: " + ((int)time);
                Color tempColor = suddenDeathTexture.color;
                tempColor.a = 0;
                suddenDeathTexture.color = tempColor;
            }
            else if (time <= -5)
            {
                time = MaxTime;
                for (int i = 0; i < meteorCounter; ++i)
                {
                    Destroy(meteors[i].gameObject);
                    meteors[i] = null;
                }
            }
            else
            {
                if (!alarm.isPlaying)
                {
                    victoryText.GetComponents <AudioSource>()[0].volume = 0;
                    alarm.Play();
                }
                if (suddenDeathTexture.color.a < .25f)
                {
                    Color tempColor = suddenDeathTexture.color;
                    tempColor.a += .025f;
                    suddenDeathTexture.color = tempColor;
                }
                CountDownTimer.text  = "SUDDEN DEATH!";
                CountDownTimer.color = Color.red;
                if (meteors[0] == null)
                {
                    meteorCounter = Mathf.Min(3, meteorCounter + 1);

                    if (meteorCounter == 1)
                    {
                        meteors[0] = Instantiate(prefabMeteor, new Vector3(0, 5, 0), Quaternion.identity) as Transform;
                    }
                    else if (meteorCounter == 2)
                    {
                        meteors[0] = Instantiate(prefabMeteor, new Vector3(-1.5f, 5, 0), Quaternion.identity) as Transform;
                        meteors[1] = Instantiate(prefabMeteor, new Vector3(1.5f, 5, 0), Quaternion.identity) as Transform;
                    }
                    else
                    {
                        meteors[0] = Instantiate(prefabMeteor, new Vector3(6, 5, 0), Quaternion.identity) as Transform;
                        meteors[1] = Instantiate(prefabMeteor, new Vector3(0, 5, 0), Quaternion.identity) as Transform;
                        meteors[2] = Instantiate(prefabMeteor, new Vector3(-6, 5, 0), Quaternion.identity) as Transform;
                    }
                }
            }
        }
        else if (CountDownTimer.text != "")
        {
            if (alarm.isPlaying)
            {
                alarm.Stop();
            }
            Color tempColor = suddenDeathTexture.color;
            tempColor.a = 0;
            suddenDeathTexture.color = tempColor;
            CountDownTimer.text      = "";
        }
    }