Exemple #1
0
    public void TakeDamage(float damage)
    {
        healthSlider.SubtractHealth(damage);

        StartCoroutine(setUnderAttack());

        healthText.text = ((int)healthSlider.Health).ToString();

        var position = transform.position;

        position.Set(position.x, position.y + HEIGHT_OFFSET, position.z);
        var text_holder = Instantiate(dmgTakenText, position, Quaternion.Euler(Camera.main.transform.eulerAngles));

        text_holder.transform.GetChild(0).GetComponent <TextMeshPro>().SetText("- " + damage);

        if (healthSlider.Health <= 0)
        {
            if (Faction == FactionEnum.Player)
            {
                menuScript.GameOver();
            }
            else
            {
                menuScript.GameWin();
            }
        }
    }
    void OnCollisionEnter(Collision collision)
    {
        if (script != null)
        {
            if (collision.gameObject.layer == script.LayerEnemy && SceneManager.GetActiveScene().name == "Level2")
            {
                if (firsttime)
                {
                    menuscript.GameOver();
                    firsttime = false;
                }
            }
        }

        if (SceneManager.GetActiveScene().name == "Level1" && collision.gameObject.layer == 11)      // for level 1
        {
            if (firsttime)
            {
                menuscript.GameOver();
                firsttime = false;
            }
        }
    }
    private void Update()
    {
        if (timeCountdown > 0)
        {
            timeCountdown -= Time.deltaTime;

            UpdateTime();
        }
        else
        {
            Time.timeScale = 0f;
            menuScript.GameOver();
        }
    }
Exemple #4
0
    // Update is called once per frame.
    void Update()
    {
        // The moment the player stops touching the ground they lose the game and go to the game over menu.
        if (!IsGrounded() && IsPlaying)
        {
            isDead = true;
            // Stops the camera from moving and tiles from falling.
            IsPlaying = false;
            // Loads the Game Over function and reset button.
            myMenuScript.GameOver();

            resetBtn.SetActive(true);

            if (transform.childCount > 0)
            {
                transform.GetChild(0).transform.parent = null;
            }
        }

        // Triggered when the played clicks and is not dead, therefore when they are playing the game.
        if (Input.GetMouseButtonDown(0) && !isDead)
        {
            IsPlaying = true;
            score++;
            scoreUI.SetText(score.ToString());
            // On the first tap it should remove the Game Start menu.
            if (myMenuScript.firstTap == false)
            {
                myMenuScript.FirstTap();
            }

            // If the player is moving forward it will set the direction to the left, if it is facing any other direction it will set the direction to forward.
            // This is the function that causes it to switch between two directions.
            if (dir == Vector3.forward)
            {
                dir = Vector3.left;
            }
            else
            {
                dir = Vector3.forward;
            }
        }

        // Actually moves the sphere in the set direction at a constant speed.
        float amountToMove = speed * Time.deltaTime;

        transform.Translate(dir * amountToMove);
    }