コード例 #1
0
ファイル: shop.cs プロジェクト: thufuhong/-
    void FixedUpdate()
    {
        if (button_cooldown > 0)
        {
            button_cooldown -= Time.fixedDeltaTime;
        }
        if (!isPlayerNearBy && (this.gameObject.transform.position - player.transform.position).sqrMagnitude < 500)
        {
            isPlayerNearBy  = true;
            mainHelper.text = "按 E 来显示商店。\n按 N 来进入下一关卡。\n按 R 来手动保存游戏。";
            mainHelper.gameObject.transform.parent.gameObject.SetActive(true);
        }
        if (isPlayerNearBy)
        {
            //if (shopOpened && (Input.GetKeyDown(KeyCode.E) || Input.GetKeyDown(KeyCode.Escape)))
            //{
            //    ShopObject.SetActive(false);
            //    shopOpened = false;
            //    return;
            //}
            //if (!shopOpened && Input.GetKeyDown(KeyCode.E))
            //{
            //    ShopObject.SetActive(true);
            //    ShopObject.GetComponent<bagManager>().RefreshBag();
            //    shopOpened = true;
            //    //Put SHOP code here
            //}

            if (button_cooldown < 0 && SaveObject.activeInHierarchy && (Input.GetKeyDown(KeyCode.R) || Input.GetKeyDown(KeyCode.Escape)))
            {
                //Debug.Log(SaveObject.activeInHierarchy.ToString() + "0" + Input.GetKeyDown(KeyCode.R).ToString());
                button_cooldown = 0.2f;
                SaveObject.SetActive(false);
                SaveOpened = false;
                return;
            }
            if (button_cooldown < 0 && !(SaveObject.activeInHierarchy) && Input.GetKeyDown(KeyCode.R))
            {
                //Debug.Log(SaveObject.activeInHierarchy.ToString() + "1" + Input.GetKeyDown(KeyCode.R).ToString());
                button_cooldown = 0.2f;
                SaveObject.SetActive(true);
                Transform _t;
                if (player.GetComponent <attribute>().GetSaveTimeFromFile(0) == " ")
                {
                    SaveObject.transform.Find("Save0").Find("Button0").gameObject.SetActive(false);
                    SaveObject.transform.Find("Save0").Find("Button1").gameObject.SetActive(false);
                    SaveObject.transform.Find("Save0").Find("Empty").gameObject.SetActive(true);
                }
                else
                {
                    SaveObject.transform.Find("Save0").Find("Empty").gameObject.SetActive(false);
                    if (player.GetComponent <attribute>().GetTypeOfPlayerFromFile(0) == "warrior")
                    {
                        _t = SaveObject.transform.Find("Save0").Find("Button0");
                        SaveObject.transform.Find("Save0").Find("Button0").gameObject.SetActive(true);
                        SaveObject.transform.Find("Save0").Find("Button1").gameObject.SetActive(false);
                    }
                    else
                    {
                        _t = SaveObject.transform.Find("Save0").Find("Button1");
                        SaveObject.transform.Find("Save0").Find("Button0").gameObject.SetActive(false);
                        SaveObject.transform.Find("Save0").Find("Button1").gameObject.SetActive(true);
                    }

                    _t.Find("Text").Find("GameLevel").gameObject.GetComponent <Text>().text   = player.GetComponent <attribute>().GetLevelOfGameFromFile(0).ToString();
                    _t.Find("Text").Find("PlayerLevel").gameObject.GetComponent <Text>().text = player.GetComponent <attribute>().GetLevelOfPlayerFromFile(0).ToString();
                    _t.Find("Text").Find("gold").gameObject.GetComponent <Text>().text        = player.GetComponent <attribute>().GetGoldOfPlayerFromFile(0).ToString();
                    _t.Find("Text").Find("time").gameObject.GetComponent <Text>().text        = player.GetComponent <attribute>().GetSaveTimeFromFile(0).ToString();
                }

                if (player.GetComponent <attribute>().GetSaveTimeFromFile(1) == " ")
                {
                    SaveObject.transform.Find("Save1").Find("Button0").gameObject.SetActive(false);
                    SaveObject.transform.Find("Save1").Find("Button1").gameObject.SetActive(false);
                    SaveObject.transform.Find("Save1").Find("Empty").gameObject.SetActive(true);
                }
                else
                {
                    SaveObject.transform.Find("Save1").Find("Empty").gameObject.SetActive(false);
                    if (player.GetComponent <attribute>().GetTypeOfPlayerFromFile(1) == "warrior")
                    {
                        _t = SaveObject.transform.Find("Save1").Find("Button0");
                        SaveObject.transform.Find("Save1").Find("Button0").gameObject.SetActive(true);
                        SaveObject.transform.Find("Save1").Find("Button1").gameObject.SetActive(false);
                    }
                    else
                    {
                        _t = SaveObject.transform.Find("Save1").Find("Button1");
                        SaveObject.transform.Find("Save1").Find("Button0").gameObject.SetActive(false);
                        SaveObject.transform.Find("Save1").Find("Button1").gameObject.SetActive(true);
                    }

                    _t.Find("Text").Find("GameLevel").gameObject.GetComponent <Text>().text   = player.GetComponent <attribute>().GetLevelOfGameFromFile(1).ToString();
                    _t.Find("Text").Find("PlayerLevel").gameObject.GetComponent <Text>().text = player.GetComponent <attribute>().GetLevelOfPlayerFromFile(1).ToString();
                    _t.Find("Text").Find("gold").gameObject.GetComponent <Text>().text        = player.GetComponent <attribute>().GetGoldOfPlayerFromFile(1).ToString();
                    _t.Find("Text").Find("time").gameObject.GetComponent <Text>().text        = player.GetComponent <attribute>().GetSaveTimeFromFile(1).ToString();
                }

                if (player.GetComponent <attribute>().GetSaveTimeFromFile(2) == " ")
                {
                    SaveObject.transform.Find("Save2").Find("Button0").gameObject.SetActive(false);
                    SaveObject.transform.Find("Save2").Find("Button1").gameObject.SetActive(false);
                    SaveObject.transform.Find("Save2").Find("Empty").gameObject.SetActive(true);
                }
                else
                {
                    SaveObject.transform.Find("Save2").Find("Empty").gameObject.SetActive(false);
                    if (player.GetComponent <attribute>().GetTypeOfPlayerFromFile(2) == "warrior")
                    {
                        _t = SaveObject.transform.Find("Save2").Find("Button0");
                        SaveObject.transform.Find("Save2").Find("Button0").gameObject.SetActive(true);
                        SaveObject.transform.Find("Save2").Find("Button1").gameObject.SetActive(false);
                    }
                    else
                    {
                        _t = SaveObject.transform.Find("Save2").Find("Button1");
                        SaveObject.transform.Find("Save2").Find("Button0").gameObject.SetActive(false);
                        SaveObject.transform.Find("Save2").Find("Button1").gameObject.SetActive(true);
                    }

                    _t.Find("Text").Find("GameLevel").gameObject.GetComponent <Text>().text   = player.GetComponent <attribute>().GetLevelOfGameFromFile(2).ToString();
                    _t.Find("Text").Find("PlayerLevel").gameObject.GetComponent <Text>().text = player.GetComponent <attribute>().GetLevelOfPlayerFromFile(2).ToString();
                    _t.Find("Text").Find("gold").gameObject.GetComponent <Text>().text        = player.GetComponent <attribute>().GetGoldOfPlayerFromFile(2).ToString();
                    _t.Find("Text").Find("time").gameObject.GetComponent <Text>().text        = player.GetComponent <attribute>().GetSaveTimeFromFile(2).ToString();
                }
                SaveOpened = true;
            }

            if (Input.GetKeyDown(KeyCode.N) && !next_level && player.GetComponent <attribute>().ifAlive)
            {
                //next level
                next_level = true;
                Debug.Log(player_attribute.level_num);
                player_attribute.level_num++;
                Debug.Log(player_attribute.level_num);
                player_attribute.SavePlayerAttribute();
                //player_attribute.SaveAttributeInFile();
                UnityEngine.SceneManagement.SceneManager.LoadScene("LevelFirst");
            }
        }
        if (isPlayerNearBy && (this.gameObject.transform.position - player.transform.position).sqrMagnitude > 600)
        {
            isPlayerNearBy = false;
            mainHelper.gameObject.transform.parent.gameObject.SetActive(false);
        }
    }
コード例 #2
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (WinFlag)
        {
            return;
        }

        if ((Boss.transform.position - player.transform.position).sqrMagnitude < 10000)
        {
            Boss_Slider.SetActive(true);
        }
        else
        {
            Boss_Slider.SetActive(false);
        }
        Boss.transform.Find("Boss Partical").Rotate(0, 0, 20 * Time.fixedDeltaTime);
        // Boss.transform.Find("Particle System").Rotate()
        if (player.transform.position.x < 2 * quad1.transform.position.x ||
            player.transform.position.x > 2 * quad3.transform.position.x - map_scale_x ||
            player.transform.position.z < 2 * quad2.transform.position.z ||
            player.transform.position.z > 2 * quad4.transform.position.z - map_scale_z)
        {
            player.GetComponent <attribute>().update_HP(-DamagePerSecond * Time.deltaTime);
        }
        if (timer > 0)
        {
            timer -= Time.fixedDeltaTime;
        }
        if (boss_transition_timer > 0)
        {
            boss_transition_timer -= Time.fixedDeltaTime;
            if (boss_transition_timer > 3)
            {
                Boss.transform.Find("Boss Partical").gameObject.SetActive(false);
                Boss.GetComponent <Collider>().enabled = false;
                Boss.GetComponent <MeshRenderer>().materials[0].color =
                    Color.Lerp(Boss.GetComponent <MeshRenderer>().material.color, new Color(Boss.GetComponent <MeshRenderer>().material.color.r, Boss.GetComponent <MeshRenderer>().material.color.g, Boss.GetComponent <MeshRenderer>().material.color.b, 0f), Time.fixedDeltaTime);
            }
            if (boss_transition_timer < 3)
            {
                //Boss.transform.position = SafeCenter + new Vector3(0f, 3.9f, 0f);

                Vector3 t = new Vector3(SafeCenter.x, 3.9f, SafeCenter.z);
                while (gameobject_generate.IsCoincide(new GameObjectGenerate.GameObjectNode(t.x, t.y, t.z, boss_length, boss_width, 0)))
                {
                    t = t + new Vector3(UnityEngine.Random.Range(-2f * boss_length, 2f * boss_length), 0, UnityEngine.Random.Range(-2f * boss_width, 2f * boss_width));
                }
                Boss.transform.position = t;



                Boss.GetComponent <MeshRenderer>().materials[0].color =
                    Color.Lerp(Boss.GetComponent <MeshRenderer>().material.color, new Color(Boss.GetComponent <MeshRenderer>().material.color.r, Boss.GetComponent <MeshRenderer>().material.color.g, Boss.GetComponent <MeshRenderer>().material.color.b, 1f), Time.fixedDeltaTime);
            }
            if (boss_transition_timer < 0)
            {
                Boss.transform.Find("Boss Partical").gameObject.SetActive(true);
                Boss.GetComponent <Collider>().enabled = true;
            }
        }
        if (Boss.GetComponent <attribute>().ifAlive == false)
        {
            WinFlag      = true;
            ui_text.text = "You Win";
            Boss_Slider.SetActive(false);
            //Boss.transform.Find("Boss Partical").gameObject.SetActive(false);
            //Boss.transform.Find("Died Partical").gameObject.SetActive(true);
            quad1.transform.position = new Vector3(0f, 0.02f, map_scale_z / 2);
            quad2.transform.position = new Vector3(map_scale_x / 2, 0.02f, 0f);
            quad3.transform.position = new Vector3(map_scale_x - 0f, 0.02f, map_scale_z / 2);
            quad4.transform.position = new Vector3(map_scale_x / 2, 0.02f, map_scale_z - 0f);

            quad1.transform.localScale = new Vector3(0f, map_scale_z, 1f);
            quad2.transform.localScale = new Vector3(0f, map_scale_x, 1f);
            quad3.transform.localScale = new Vector3(0f, map_scale_z, 1f);
            quad4.transform.localScale = new Vector3(0f, map_scale_x, 1f);

            player.GetComponent <attribute>().update_HP(player.GetComponent <attribute>().HP_max);
            shop.transform.position = Boss.transform.position;
            shop.SetActive(true);
            //event when success

            player_attribute.SavePlayerAttribute();
            //UnityEngine.SceneManagement.SceneManager.LoadScene("LevelSecond");

            return;
        }

        else
        {
            if (timer <= 0)
            {
                if (!IsWaiting)
                {
                    rounds++;
                    SafeCenter = new Vector3(UnityEngine.Random.Range(2 * quad1.transform.position.x, 2 * quad3.transform.position.x - map_scale_x),
                                             0,
                                             UnityEngine.Random.Range(2 * quad2.transform.position.z, 2 * quad4.transform.position.z - map_scale_z));
                    SafeScale *= 2;
                    float _totalframes = (Base_transfer_time + Additional_transfer_time / rounds) / Time.deltaTime;
                    DeltaQuad1 = (SafeCenter.x - 2 * quad1.transform.position.x) / _totalframes / scale_factor;
                    DeltaQuad2 = (SafeCenter.z - 2 * quad2.transform.position.z) / _totalframes / scale_factor;
                    DeltaQuad3 = (2 * quad3.transform.position.x - map_scale_x - SafeCenter.x) / _totalframes / scale_factor;
                    DeltaQuad4 = (2 * quad4.transform.position.z - map_scale_z - SafeCenter.z) / _totalframes / scale_factor;
                    timer      = wait_time;
                    IsWaiting  = true;

                    // Transition of Boss
                    boss_transition_timer = 6f;
                }
                else
                {
                    timer     = (Base_transfer_time + Additional_transfer_time / rounds);
                    IsWaiting = false;
                }
            }
            // TBD: else here?
            ui_text.text = (IsWaiting ? "Safe Area Will Reduce in " : "Safe Area Reductin Ends in ") + ((int)timer + 1).ToString();
            if (!IsWaiting)
            {
                quad1.transform.position = quad1.transform.position + new Vector3(DeltaQuad1 / 2, 0f, 0f);
                quad2.transform.position = quad2.transform.position + new Vector3(0f, 0f, DeltaQuad2 / 2);
                quad3.transform.position = quad3.transform.position + new Vector3(-DeltaQuad3 / 2, 0f, 0f);
                quad4.transform.position = quad4.transform.position + new Vector3(0f, 0f, -DeltaQuad4 / 2);

                quad1.transform.localScale = quad1.transform.localScale + new Vector3(DeltaQuad1, 0f, 0f);
                quad2.transform.localScale = quad2.transform.localScale + new Vector3(DeltaQuad2, 0f, 0f);
                quad3.transform.localScale = quad3.transform.localScale + new Vector3(DeltaQuad3, 0f, 0f);
                quad4.transform.localScale = quad4.transform.localScale + new Vector3(DeltaQuad4, 0f, 0f);
            }
        }
    }