private void OnTriggerEnter(Collider other)
 {
     if (other.CompareTag("Player") && !activated)
     {
         activated = true;
         activationEffect.Play();
         anim.SetTrigger("Raise");
         activationSound.Play();
         //pelin tallennus
         GameObject player = GameObject.Find("Player");
         GameData   data   = GameDataManager.Instance.GameData;
         data.checkPoints[id.id].activated = true;
         //paikka, suunta, polku, checkpointin saavutus
         data.player.position = new GameData.SerializableVector3(spawnPoint.transform.position);
         data.player.rotation = new GameData.SerializableQuaternion(spawnPoint.transform.rotation);
         data.player.firstCheckPointReached = true;
         data.player.pathName = player.GetComponent <PathKeeper>().currentSpline.name;
         //health
         HealthSystem healthSystem = player.GetComponent <HealthSystem>();
         data.player.currentHealth = healthSystem.currentHealth;
         data.player.maxHealth     = healthSystem.maxHealth;
         //loitsut
         PlayerController playerController = GameObject.Find("TouchControlHandler").GetComponent <PlayerController>();
         GameData.Spells  spellData        = data.spells;
         spellData.owned = new bool[playerController.spellOwned.Length];
         spellData.count = new int[playerController.spellCount.Length];
         Array.Copy(playerController.spellOwned, spellData.owned, playerController.spellOwned.Length);
         Array.Copy(playerController.spellCount, spellData.count, playerController.spellCount.Length);
         //tallenna pelin tila tiedostoon
         GameDataManager.Instance.SaveGame();
     }
 }
Beispiel #2
0
    void Start()
    {
        spellOwned   = new bool[spells.Length];
        spellCount   = new int[spells.Length];
        spellButtons = new GameObject[spells.Length];
        //rakenna loitsumenun valintanapit
        for (int i = 0; i < spells.Length; i++)
        {
            Spell spell = spells[i];
            storedGestures.Add(GestureIO.ReadGestureFromXML(spell.gestureXml.text));
            GameObject spellButtonObject = Instantiate(spellMenuButtonPrefab);
            spellButtons[i] = spellButtonObject;
            spellButtonObject.transform.SetParent(spellMenuButtons.transform, false);
            spellButtonObject.GetComponent <Image>().sprite = spell.icon;
            int index = i; //delegaatin muuttujan pitää olla samassa scopessa kuin delegaatti
            spellButtonObject.GetComponent <Button>().onClick.AddListener(delegate { StartSpellGestureDrawMode(index); });
        }

        //lataa loitsujen tilanne tallennuksesta
        GameData.Spells spellData  = GameDataManager.Instance.GameData.spells;
        GameData.Player playerData = GameDataManager.Instance.GameData.player;
        if (playerData.firstCheckPointReached)
        {
            Debug.Log("PlayerController - First Checkpoint Reached");
            Debug.Log(spellData.count[0]);
            Array.Copy(spellData.owned, spellOwned, spells.Length);
            Array.Copy(spellData.count, spellCount, spells.Length);
            for (int i = 0; i < spells.Length; i++)
            {
                setSpellState(i, spellOwned[i], spellCount[i]);
            }
        }
        else
        {
            for (int i = 0; i < spells.Length; i++)
            {
                setSpellState(i, false, 0);
            }
            setSpellState(0, true, 1); //parannusloitsu on käytössä heti pelin alussa
        }

        EnableInput = true;
        //loitsumenu avataan tutoriaalin suorittamisen jälkeen
        SpellMenuEnabled = playerData.firstCheckPointReached;

        defaultDeltaTime        = Time.fixedUnscaledDeltaTime; //Time.fixedDeltaTime;
        defaultMaximumDeltaTime = 1f;                          //Time.maximumDeltaTime;
        SetSpellMenuSlowDown(false);

        playerControls = GameObject.Find("Player").GetComponent <PlayerControls>();
    }