Exemplo n.º 1
0
    public void UnlockCreature()
    {
        int cost = PublicLevel.friendlyPrefab[changingInfo.x, changingInfo.y].GetComponent <DefaultCreature>().GetUnlockCost();

        PublicLevel.SetCorn(PublicLevel.GetCorn() - cost);
        PublicLevel.unlockType[changingInfo.x, changingInfo.y] = true;
        unlockPopup.SetActive(false);
    }
Exemplo n.º 2
0
    private void Start()
    {
        //make buttons to call TargetCreature function which sends upgradeoption[temp] as a parameter.
        for (int i = 0; i < PublicLevel.friendlyTypeCreatureNum; i++)
        {
            upgradeButton[i] = GameObject.Find("UpgradeButton" + (i + 1)).GetComponent <Button>();
            int temp = i; //used temp since just using i makes every buttons to send last i value as a parameter
            upgradeButton[i].GetComponent <Button>().onClick.AddListener(delegate { TargetCreature(upgradeOption[temp]); });
        }

        //make buttons toi call ChangeCreature fucntion
        for (int i = 0; i < PublicLevel.usingCreatureNum; i++)
        {
            locationButton[i] = GameObject.Find("Location" + (i + 1)).GetComponent <Button>();
            int temp = i;
            locationButton[temp].onClick.AddListener(delegate { ChangeCreature(temp); });
        }

        unlockPopup.SetActive(false);
        //UI upgradShop is not shown until upgradeShop is active
        upgradeShop.SetActive(false);

        //Try to find GameDataControl
        gameDataControl = GameObject.Find("GameDataControl");

        //if no gameDataControl exists, instantiate one new gameDataControl
        if (gameDataControl == null)
        {
            gameDataControl      = Instantiate(new GameObject(), transform.position, Quaternion.identity);
            gameDataControl.name = "GameDataControl";
            gameData             = gameDataControl.AddComponent <GameData>();

            loadedData = gameData.LoadGameData();


            //load when StageSelect scene was first loaded. If there's no loadedData, make a default setting for player - level, win, creature type using.
            if (loadedData == null)
            {
                PublicLevel.SetPlayerLevel(1);
                PublicLevel.SetPlayerWin(0);
                PublicLevel.SetCorn(0);
                for (int i = 1; i < 6; i++)
                {
                    PublicLevel.unlockType[i, 0] = true;
                }
                for (int i = 0; i < PublicLevel.friendlyTypeCreatureNum; i++)
                {
                    PublicLevel.friendlyType[i] = new Vector2Int(i, 0);
                }
            }
            else
            {
                PublicLevel.SetPlayerLevel(loadedData.GetPlayerLevel());
                PublicLevel.SetPlayerWin(loadedData.GetPlayerWin());
                PublicLevel.SetCorn(loadedData.GetCorn());

                for (int i = 0; i < PublicLevel.usingCreatureNum; i++)
                {
                    PublicLevel.friendlyType[i] = new Vector2Int(loadedData.GetFriendlyType()[i].x, loadedData.GetFriendlyType()[i].y);
                }

                for (int i = 0; i < PublicLevel.friendlyTypeCreatureNum; i++)
                {
                    for (int k = 0; k < PublicLevel.friendlyTypeUpgradeNum; k++)
                    {
                        PublicLevel.unlockType[i, k] = loadedData.GetUnlockType()[i, k];
                    }
                }
            }

            //fill frienldyCreatureList based on loaded/default friendlyType
            for (int i = 0; i < PublicLevel.friendlyTypeCreatureNum; i++)
            {
                PublicLevel.friendlyCreatureList[i] = PublicLevel.friendlyPrefab[PublicLevel.friendlyType[i].x, PublicLevel.friendlyType[i].y];

                PublicLevel.friendlyImageList[i] = PublicLevel.friendlyImage[PublicLevel.friendlyType[i].x, PublicLevel.friendlyType[i].y];
            }
        }

        cornText.text = PublicLevel.GetCorn().ToString();

        stageButton = GameObject.FindGameObjectsWithTag("StageButton");
        foreach (GameObject stageBtn in stageButton)
        {
            StageButton stageCheck = stageBtn.GetComponent <StageButton>();
            if (stageCheck.GetStageLevel() > PublicLevel.GetPlayerLevel())
            {
                stageBtn.GetComponent <Image>().color         = Color.red;
                stageBtn.GetComponent <Button>().interactable = false;
            }
            else if (stageCheck.GetStageLevel() == PublicLevel.GetPlayerLevel())
            {
                stageBtn.GetComponent <Image>().color = Color.blue;
            }
        }

        //save data
        gameData.SaveGameData();
    }