void OnTriggerEnter2D(Collider2D collider) { HeroRabit rabit = collider.GetComponent <HeroRabit>(); if (rabit != null) { LevelStats stats = LevelController.current.getStats(); if (stats == null) { Debug.Log("Statsk is null"); } stats.levelPassed = true; if (FruitsController.controller.allCollected()) { stats.hasAllFruits = true; } PlayerPrefs.SetInt("coins", CoinsController.controller.getCoins()); //string str = JsonUtility.ToJson(stats); ///PlayerPrefs.SetString(currentLevelName, str); PlayerPrefs.Save(); GameObject parent = UICamera.first.transform.parent.gameObject; GameObject obj = NGUITools.AddChild(parent, winPrefab); WinPopup popup = obj.GetComponent <WinPopup>(); } }
private void OnEnable() { if (instance == null) { instance = this; HidePopup(); } }
void OnTriggerEnter2D(Collider2D collider) { HeroController heroController = collider.GetComponentInParent <HeroController> (); if (heroController != null) { //Знайти батьківський елемент GameObject parent = UICamera.first.transform.parent.gameObject; //Створити Prefab GameObject obj = NGUITools.AddChild(parent, winPopupPrefab); //Отримати доступ до компоненту (щоб передати параметри) WinPopup winPopup = obj.GetComponent <WinPopup>(); //... LevelStat levelStat = LevelController.current.getStats(); winPopup.setStats(levelStat); levelStat.save(); } }
void Awake() { if (!Application.isEditor) { Cursor.visible = false; Cursor.lockState = CursorLockMode.Locked; } _loadingScreen = GameObject.Instantiate(loadingScreenPrefab, new Vector3(8000, 8000, 8000), Quaternion.identity); _loadingScreen.gameObject.SetActive(false); _winPopup = GameObject.Instantiate(winPopupPrefab, Vector3.zero, Quaternion.identity); _winPopup.gameObject.SetActive(false); spawns = StageManager.instance.transform.Find("SpawnPoints").GetComponentsInChildren <Transform>().Where(x => x.name != "SpawnPoints").ToArray(); playerInfo = Serializacion.LoadJsonFromDisk <RegisteredPlayers>("Registered Players"); playerInfo.playerStats = new PlayerStats[playerInfo.playerControllers.Length]; playerCameras[playerInfo.playerControllers.Length - 2].SetActive(true); if (playerInfo.playerControllers.Length == 2) { for (int i = 0; i < 2; i++) { Camera c = GameObject.Find("Camera_P" + (i + 1)).GetComponent <Camera>(); cameraTexturesForTwoPlayers[i].width = 1280; c.rect = new Rect(0, 0, 2, 1); } } else { for (int i = 0; i < 2; i++) { Camera c = GameObject.Find("Camera_P" + (i + 1)).GetComponent <Camera>(); cameraTexturesForTwoPlayers[i].width = 640; c.rect = new Rect(0, 0, 1, 1); } } //Setting the mode! gameRules = Resources.Load("Scriptable Objects/GameMode_" + playerInfo.gameMode) as SO_GameRules; //get all the cameras var allCams = GameObject.FindObjectsOfType <CamFollow>().ToList(); Utility.KnuthShuffle(spawns); for (int i = 0; i < playerInfo.playerControllers.Length; i++) { var URLs = Serializacion.LoadJsonFromDisk <CharacterURLs>("Player " + (playerInfo.playerControllers[i] + 1)); //Dejo los objetos ccomo children del body por cuestiones de carga de los scripts. Assembler no debería generar problemas, ya que su parent objetivo sería el mismo. var player = Instantiate(Resources.Load <GameObject>("Prefabs/Bodies/" + URLs.bodyURL), spawns[i].transform.position, Quaternion.identity).GetComponent <Player>(); var weapon = Instantiate(Resources.Load <GameObject>("Prefabs/Weapons/" + URLs.weaponURL), player.transform.position, Quaternion.identity, player.transform); var comp1 = Instantiate(Resources.Load <GameObject>("Prefabs/Skills/Complementary/" + URLs.complementaryURL[0]), player.transform.position, Quaternion.identity, player.transform); var comp2 = Instantiate(Resources.Load <GameObject>("Prefabs/Skills/Complementary/" + URLs.complementaryURL[1]), player.transform.position, Quaternion.identity, player.transform); var def = Instantiate(Resources.Load <GameObject>("Prefabs/Skills/Defensive/" + URLs.defensiveURL), player.transform.position, Quaternion.identity, player.transform); CharacterAssembler.Assemble(player.gameObject, def, comp1, comp2, weapon); player.transform.forward = spawns[i].forward; comp1.GetComponent <ComplementarySkillBase>().RegisterInput(0); comp2.GetComponent <ComplementarySkillBase>().RegisterInput(1); player.gameObject.layer = LayerMask.NameToLayer("Player" + (playerInfo.playerControllers[i] + 1)); player.gameObject.tag = "Player " + (playerInfo.playerControllers[i] + 1); foreach (Transform t in player.transform) { t.gameObject.layer = LayerMask.NameToLayer("Player" + (playerInfo.playerControllers[i] + 1)); t.gameObject.tag = "Player " + (playerInfo.playerControllers[i] + 1); } player.Stats.Score = 0; player.lockedByGame = true; player.LightsModule.SetPlayerColor(playerColors[playerInfo.playerControllers[i]]); CamFollow cam = allCams.Where(x => x.name == "Camera_P" + (i + 1)).First(); allCams.Remove(cam); if (player.ControlModule.playerType == PlayerControlModule.PlayerType.DRONE) { cam.AssignTarget(player, player.GetCameraOffset()); } else { var castedControlModule = player.ControlModule as QuadrupedControlModule; cam.AssignTarget(player, player.GetCameraOffset(), castedControlModule.HardcodeForCameraForward); } } //disable cams that are not being used foreach (var item in allCams) { item.gameObject.SetActive(false); } AddEvents(); UIManager.Instance.Initialize(Players, StartFirstRound, gameRules.pointsToWin[playerInfo.playerControllers.Length - 2]); }