public static void show() { GameObject obj = Resources.Load("Prefabs/UI/UIPlayerInfo") as GameObject; s_gameObject = Instantiate(obj, GameObject.Find("LowCanvas").transform); s_playerInfoScript = s_gameObject.GetComponent <PlayerInfoScript>(); }
// Start is called before the first frame update void Start() { info = PlayerInfoScript.instance; if (info == null) { Debug.LogError("PlayerInfoScript not found"); } //Update the achievement list and get the index of completion int levelIndex = UpdateAchievements(info.GetLevelAchievementIndex(), info.GetLevel(), _levelAchievements, 0); int killIndex = UpdateAchievements(info.GetKillAchievementIndex(), info.GetTotalKills(), _killAchivements, 1); _achievementScroller.GetComponent <ScrollRect>().verticalNormalizedPosition = 1; //Automatically scroll to the top //If the game hasn't be loaded before, then set the achievement index for each achievement. if (!info.HasAchievementBeenLoaded()) { info.SetAchievementLevel(levelIndex); info.SetAchievementKillLevel(killIndex); } //Update the UI for coins and the xp bar _levelUIManager.UpdateUIStats(); OrderAchievements(); }
// Start is called before the first frame update private void Start() { if (_IsTesting) //If you are using a computer, lock the mouse to the middle of the Game window { Cursor.lockState = CursorLockMode.Locked; } if (PlayerInfoScript.instance != null) { PlayerInfoScript info = PlayerInfoScript.instance; _health = info.GetPowerValue("Health"); _damage = info.GetPowerValue("Damage"); _armour = info.GetPowerValue("Armour"); _rapidDelay = info.GetPowerValue("Rapid"); } else { if (!_IsTesting) { Debug.LogError("No PlayerInfoScript found"); } //Default values _health = 100.0f; _damage = 25.0f; _armour = 1.0f; _rapidDelay = 0.15f; } _startingHealth = _health; }
/// <summary> /// This fucntion is used to spawn a number of monsters. /// </summary> IEnumerator SpawnEnemies(int num) { while (_monsters.Count < num) { GameObject monster = Instantiate(_monsterPrefabs[Random.Range(0, _monsterPrefabs.Count)], transform.position, Quaternion.identity); Vector3 vel = Random.onUnitSphere * Random.Range(2, 5); monster.GetComponent <Rigidbody>().velocity = vel; PlayerInfoScript player = PlayerInfoScript.instance; //If the PlayerInfoScript exists (started game from menu) if (player) { //Each level is offset but 10 levels to make it more challenging in other groups int level = player.GetCurrentGroup() * 25 + player.GetLevelInSugarGroup(player.GetCurrentGroup()); monster.GetComponent <MonsterScript>().InitMonster(_cameraTransform.position, _radius, _canvas, level); } else //For testing purposes { monster.GetComponent <MonsterScript>().InitMonster(_cameraTransform.position, _radius, _canvas, 0); } monster.transform.LookAt(_cameraTransform.position); _monsters.Add(monster); yield return(null); } }
private int _numberOfEnemiesKilled = 0; // The total number of enemies killed #endregion private void Awake() { if (instance == null) { instance = this; } else { Destroy(gameObject); } _coinsFromLevel = 0; _xpFromLevel = 0; int size = powerGroup.Count; for (int i = 0; i < size; i++) { PowerUpGroup power = powerGroup[i]; powerupsDict.Add(power._name, i); power.SetValue(powerGroup[i]._startingValue); powerGroup[i] = power; } DontDestroyOnLoad(gameObject); }
/// <summary> /// This fucntion is used to update the coins and xp bars on the stats panel. /// </summary> public void UpdateUIStats() { PlayerInfoScript play = PlayerInfoScript.instance; tempCoins.text = play.GetCoinCount().ToString("00000000");//change the innital coin display here tempLevel.transform.parent.transform.Find("Fill").GetChild(0).GetComponent <Image>().fillAmount = play.GetPercentageToNextLevel(); tempLevel.text = "" + play.GetLevel(); }
private void Awake() { Instance = this; transform_ = GetComponent <RectTransform>(); text_ = GetComponentInChildren <TextMeshProUGUI>(); transform_.localPosition += Vector3.right * 10000; Timing.RunCoroutine(QueueCo().CancelWith(this.gameObject)); }
// Use this for initialization void Start() { gameObject.transform.Find("BtnList/Button_sign").GetComponent <Button>().onClick.AddListener(() => { SignScript.show(); }); gameObject.transform.Find("BtnList/Button_activity").GetComponent <Button>().onClick.AddListener(() => { ToastScript.createToast("暂无活动"); }); gameObject.transform.Find("BtnList/Button_bag").GetComponent <Button>().onClick.AddListener(() => { ToastScript.createToast("背包"); }); gameObject.transform.Find("BtnList/Button_shop").GetComponent <Button>().onClick.AddListener(() => { ToastScript.createToast("商城"); }); gameObject.transform.Find("BtnList/Button_task").GetComponent <Button>().onClick.AddListener(() => { ToastScript.createToast("任务"); }); gameObject.transform.Find("BtnList/Button_jingji").GetComponent <Button>().onClick.AddListener(() => { ToastScript.createToast("竞技"); }); gameObject.transform.Find("BtnList/Button_zhanyi").GetComponent <Button>().onClick.AddListener(() => { //SceneManager.LoadScene("GameScene"); SceneManager.LoadScene("DiLaoScene"); }); gameObject.transform.Find("Head/Button").GetComponent <Button>().onClick.AddListener(() => { PlayerInfoScript.show(); }); reqUserInfo(); }
private void OnDestroy() { if (!_didDealDamage) { PlayerInfoScript info = PlayerInfoScript.instance; if (info) //If the PlayerInfoScript exists (ran game from main menu) add proper xp/coins { info.AddCoinsInLevel(_coins); info.AddXPInLevel(_xp); info.AddToTotalKills(); } else //For testing when running the game from this scene { Debug.Log("No PlayerInfoScript found!"); } } _sm.RemoveMonster(gameObject); }
/// <summary> /// This function is used to remove a destroyed monster from the list. /// </summary> /// -This function gets called from the MonterScript- public void RemoveMonster(GameObject obj) { _monsters.Remove(obj); if (_monsters.Count <= 0 && !PlayerScript.instance.IsDead()) { PlayerInfoScript info = PlayerInfoScript.instance; if (PlayerScript.instance._IsTesting) //If you are using a computer, lock the mouse to the middle of the Game window { Cursor.lockState = CursorLockMode.None; } //Update the stats of the player info.AddLevelInSugarGroup(); _winPanel.SetActive(true); //Display win screen string stats = "Coins: " + info.GetCoinsFromLevel() + "\nXP: " + info.GetXpFromLevel(); _winPanel.transform.Find("Stats").GetComponent <TextMeshProUGUI>().text = stats; //Update stats } }
/// <summary> /// This fucntion is used to spawn a number of monsters. /// </summary> IEnumerator SpawnEnemies(int num) { PlayerInfoScript player = PlayerInfoScript.instance; int index; if (player) { index = player.GetCurrentGroup(); } else { index = 0; } // set monsters depending on the current chosen sugar type switch (index) { // cane case 0: _chosenMonster = _caneMonster; break; // concentrate case 1: _chosenMonster = _concentrateMonster; break; // dextrin case 2: _chosenMonster = _dextrinMonster; break; // Obvios case 3: _chosenMonster = _obviosMonster; break; // ose case 4: _chosenMonster = _OSEMonster; break; // strange case 5: _chosenMonster = _strangeMonster; break; // syrup case 6: _chosenMonster = _syrupMonster; break; default: _chosenMonster = _caneMonster; break; } while (_monsters.Count < num) { player = PlayerInfoScript.instance; GameObject monster = Instantiate(_chosenMonster, transform.position, Quaternion.identity); // generate random velocity random Vector3 vel = Random.onUnitSphere * Random.Range(2, 5); // setting the velocity monster.GetComponent <Rigidbody>().velocity = vel; //If the PlayerInfoScript exists (started game from menu) if (player) { //Each level is offset but 10 levels to make it more challenging in other groups int level = player.GetLevelInSugarGroup(player.GetCurrentGroup()); print("level: " + level); monster.GetComponent <MonsterScript>().InitMonster(_cameraTransform.position, _radius, _canvas, level);//leveling setting here ############## } else //For testing purposes { monster.GetComponent <MonsterScript>().InitMonster(_cameraTransform.position, _radius, _canvas, 0); } monster.transform.LookAt(_cameraTransform.position); _monsters.Add(monster); yield return(null); } }
private PlayerInfoScript info; // A reference to the PlayerInfoScript singleton #endregion private void Start() { //Get all of the references in the game _buttonPanel = GameObject.Find("Buttons"); _allPanels = GameObject.Find("SugarPanels"); _backButton = GameObject.Find("BackButton"); _selectionPanel = GameObject.Find("Selection"); _skillsPanel = GameObject.Find("SkillsPanel"); _mainMenuPanel = GameObject.Find("MainMenu"); _achievementPanel = GameObject.Find("AchievementsPanel"); _leftArrow.SetActive(false); _xpSlider = tempLevel.transform.parent.transform.Find("Fill").GetChild(0).GetComponent <Image>(); _allPanels.SetActive(false); _selectionPanel.SetActive(false); _skillsPanel.SetActive(false); _achievementPanel.SetActive(false); info = PlayerInfoScript.instance; tempCoins.text = info.GetCoinCount().ToString("00000000"); _xpSlider.fillAmount = info.GetPercentageToNextLevel(); tempLevel.text = "" + info.GetLevel(); UpdatePowers(info.GetLevel()); _currentLevels = _mainMenuPanel; int size = _allPanels.transform.childCount; //Loop through the sugar groups panels for (int i = 0; i < size; i++) { SugarButton group = new SugarButton(); Transform panel = _allPanels.transform.GetChild(i).GetChild(0); _allPanels.transform.GetChild(i).GetComponent <ScrollRect>().verticalNormalizedPosition = 1; //Automatically scroll to the top group.init(panel.gameObject, PlayerInfoScript.instance.GetLevelInSugarGroup(i)); //Init the sugar group buttonGroups.Add(group); //Update the titles Transform child = panel.parent.Find("Text"); if (group._currentButton) { group._currentButton.onClick.AddListener(() => PlayLevel(_currentSelection)); //Set the current button to be active group._currentButton.interactable = true; child.GetComponent <Text>().text = buttonGroups[i]._name + " - " + (buttonGroups[i]._currentButtonIndex) + "/" + buttonGroups[i]._buttonCount; } else { child.GetComponent <Text>().text = buttonGroups[i]._name + " - " + (buttonGroups[i]._buttonCount) + "/" + buttonGroups[i]._buttonCount; } //Update the buttons to be at the location last saved (Future: From the save file) UpdateButtons(buttonGroups[i]); panel.parent.gameObject.SetActive(false); } //Settings for the "map" selection animations _selectionOffset = -_selectionPanel.transform.GetChild(0).GetComponent <RectTransform>().sizeDelta.x / buttonGroups.Count; _targetLocation = -_selectionPanel.transform.GetChild(0).GetChild(0).GetComponent <RectTransform>().anchoredPosition.x; }