2018年1月5日 星期五

吳映廷 計算機圖學 week17

本週的主題是製作期末作品。
這週的進度是將基本的HUD(分數,血量)加入
以及敵人的生成.。
以下是分數和血量的部分程式碼。
    public void Score()
    {
        bonusHealthText.SetActive(false);
        stick_man_combo += 1;
        if (stick_man_combo % 5 == 0)
        {
            stick_man_health += 10;
            bonusHealthText.SetActive(true);
            healthText.text = "Health: " + stick_man_health.ToString();
        }
        comboText.text = "Combo: " + stick_man_combo.ToString();
        stick_man_score += stick_man_combo * 10;
        scoreText.text = "Score: " + stick_man_score.ToString();
    }
    public void Hurt()
    {
        stick_man_combo = 0;
        comboText.text = "Combo: " + stick_man_combo.ToString();
        stick_man_health -= 10;
        healthText.text = "Health: " + stick_man_health.ToString();
        if (stick_man_health <= 0)
        {
            gameoverText.SetActive(true);
            gameover = true;
        }

    }

以下是敵人經過時間隨機生成的程式碼。
if (gameover == false)
        {
            System.Random rnd = new System.Random();
            GenTime = rnd.Next(1, 50);
            GenTime2 = rnd.Next(1, 50);
        }
        if (enemyGenCounter > GenTime)
        {
            GameObject.Instantiate(enemy);
            enemyGenCounter = 0;
        }
        if (enemyGenCounter > GenTime2)
        {
            GameObject.Instantiate(enemy_R);
            enemyGenCounter2 = 0;
        }

沒有留言:

張貼留言