2018年5月16日 星期三

Week12_是沫不是沬

🌟期末專案_嗨!地鼠

🌠程式碼撰寫—除錯及切換場景

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

using UnityEngine.SceneManagement;


public class EasyControl : MonoBehaviour {
    public static float gametimer;
    float roundTimer;
    int max;
    bool gameOver = false, round = false;
    public GameObject s1MouseOne, s1MouseTwo;
    public List<ControlMouse> mouse = new List<ControlMouse>();
    public List<Transform> hole = new List<Transform>();

    void Start()
    {
        gametimer = 60f;
        roundTimer = 0f;
        gameOver = false;
    }

    void Update()
    {
        if (!gameOver)
        {
            if (gametimer <= 0) gameOver = true;
            gametimer -= Time.deltaTime;
            roundTimer -= Time.deltaTime;

            if (!gameOver && roundTimer <= 0.2f)
            {
                round = true;
                roundTimer = 4f;
            }
            if (round)
            {
                max = Random.Range(1, 4);
                //Debug.Log(max);
                while (max > 0)
                {
                    max -= 1;
                    spawnS1Mouse();
                }
                round = false;
            }
        }
        if (gameOver)
        {
            SceneManager.LoadScene("Easy");
        }

    }

    void spawnS1Mouse()  //產生第一關的地鼠
    {
        int index = Random.Range(0, 8);
        while (mouse[index] != null) index = Random.Range(0, 8);
        if (index % 2 == 0)
        {

            GameObject s1One = Instantiate(s1MouseOne, new Vector3(hole[index].position.x, 

                   hole[index].position.y - 15f, hole[index].position.z), hole[index].transform.rotation);
            mouse[index] = s1One.GetComponent<ControlMouse>();
            Destroy(s1One, 3f);
        }
        else
        {

            GameObject s1Two = Instantiate(s1MouseTwo, new Vector3(hole[index].position.x, 



                 hole[index].position.y - 15f, hole[index].position.z), hole[index].transform.rotation);
            mouse[index] = s1Two.GetComponent<ControlMouse>();
            Destroy(s1Two, 3f);
        }
    }
}

沒有留言:

張貼留言