Page 1 of 1

Feedback about implementation

Posted: Tue Aug 30, 2022 10:33 am
by devlucaslopes
Hello guys, i wanna ask a feedback about this implementation...I'm creating a platformer game. When player get the checkpoint I will save: Collected Coins and Enemies Killed.

I'm create a script to management all saves. Also create unique keys using a prefix with SCENE BUILD INDEX + NAME for save this data about each level.

I'm using the position of gameobjects to save in the list. I not found some kind of ID unchanged and unique for get gameobjects. This aproch is wrong?

Code: Select all

    private void Awake()
    {
            COLLECTED_COINS = $"{_sceneIndex}_COLLECTED_COINS";
            ENEMIES_KILLED = $"{_sceneIndex}_ENEMIES_KILLED";

            _collectedCoins = ES3.Load(COLLECTED_COINS, _collectedCoins);
            _enemiesKilled = ES3.Load(ENEMIES_KILLED, _enemiesKilled);
    }

    public void NewCoinCollected (Vector3 position)
    {
        _collectedCoins.Add(position);
    }

    public bool FindCoinByPosition(Vector3 position)
    {
        return _collectedCoins.Exists(coin => Equals(coin, position));
    }

    public void EnemyKilled (Vector3 position)
    {
        _enemiesKilled.Add(position);
    }
    public bool FindEnemyByPosition(Vector3 position)
    {
        return _enemiesKilled.Exists(enemy => Equals(enemy, position));
    }

    public void SaveGameFromCheckpoint ()
    {
        ES3.Save(COLLECTED_COINS, _collectedCoins);
        ES3.Save(ENEMIES_KILLED, _enemiesKilled);
    }
When player restart the level I will check if this enemy or this coin was collected.

Code: Select all

        if (SaveController.Instance.FindCoinByPosition(transform.position))
            Destroy(gameObject);

Re: Feedback about implementation

Posted: Wed Aug 31, 2022 8:52 am
by Joel
Hi there,

I see no reason why your code shouldn’t work. You would just need to ensure that your load code runs before your code which checks whether the coins have been collected, and that your NewCoinCollected method is actually being called.

All the best,
Joel