Esempio n. 1
0
    private void Start()
    {
        #region Should be removed after creating game manager
        if (_instance == null)
        {
            _instance = gameObject;
        }
        else
        {
            Destroy(gameObject);
        }

        DontDestroyOnLoad(gameObject);

        #endregion

        if (PlayerPrefs.HasKey("Exp"))
        {
            Exp = PlayerPrefs.GetInt("Exp");
        }

        if (PlayerPrefs.HasKey("Health"))
        {
            Health = PlayerPrefs.GetInt("Health");

            if (Health <= 0)
            {
                Health = 2;
            }
        }

        Moving          = GetComponent <Moving>();
        DashAbility     = GetComponent <DashAbility>();
        StrikeAbility   = GetComponent <StrikeAbility>();
        InvulnerAbility = GetComponent <InvulnerAbility>();

        MobKilled = new UnityEvent();
        AmbientEvent.AddListener(PlayPopSound);
        ExpCollected.AddListener(CollectCoin);
        HealthChanged.AddListener(UpdateHealthData);

        GameUI = GameObject.FindGameObjectWithTag(nameof(GameUI))
                 .GetComponent <GameUI>();

        GameUI.ExpText.text    = $"Опыт: {Exp} поинтов";
        GameUI.HealthText.text = $"Здоровье: {Health}";

        // Extract to level configuration
        var level = SceneManager.GetActiveScene().name;

        if (level == "FirstLevel")
        {
            GetComponent <DashAbility>().IsEnabled   = false;
            GetComponent <StrikeAbility>().IsEnabled = false;
            GameUI?.DisableDash();
            GameUI?.DisableStrike();
        }
        if (level.Contains("Second") || level.Contains("Third") || level.Contains("Fourth"))
        {
            GetComponent <StrikeAbility>().IsEnabled = false;
            GameUI?.DisableStrike();
        }

        if (GameObject.FindGameObjectWithTag("AchievPool") == null)
        {
            Instantiate <GameObject>(Resources.Load <GameObject>("Prefabs/AchievmentPool"));
        }

        Respawn();
    }