Upgrad my player's characteristics

Hello to all

Being a beginner in unity and facing a major problem I am addressing you.

I have two scenes one to choose / change players and a second to improve the characteristics of the players (speed, degat, ect).

To choose / change character I chose to make a game object that groups these characters and that activates/disactivates them according to the one we choose, here is the code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class CharacterSelection : MonoBehaviour {

        private GameObject[] characterObjectList;
        private int index;

        private void Start ()
        {

                index = PlayerPrefs.GetInt("CharacterSelected");

                characterObjectList = new GameObject[transform.childCount];

                for(int i = 0; i < transform.childCount; i++)
                {
                        characterObjectList[i] = transform.GetChild(i).gameObject;
                }

                foreach (GameObject go in characterObjectList)
                        go.SetActive(false);

                        if(characterObjectList[index])
                                characterObjectList[index].SetActive(true);
        }
    ///// Touche de Gauche /////
        public void ToucheLeft ()
        {
                // met celui d'avant en desactif
                characterObjectList[index].SetActive(false);

                // change celui qui est present
                index--;
                if (index < 0)
                {
                        index = characterObjectList.Length - 1;
                }

                // on l'affiche
                characterObjectList[index].SetActive(true);
        }

        ///// Touche de Droite /////
        public void ToucheRight ()
        {
                // met celui d'avant en desactif
                characterObjectList[index].SetActive(false);

                // change celui qui est present
                index++;
                if (index == characterObjectList.Length)
                {
                        index = 0;
                }

                // on l'affiche
                characterObjectList[index].SetActive(true);
        }

        public void ToucheConfirm ()
        {
                PlayerPrefs.SetInt("CharacterSelected", index);
                SceneManager.LoadScene("Upgrade");
        }
}

And in my second scene I would like to recover my player’s characteristics (speed, damage, etc.) in order to improve them. The problem is that each character has its own characteristic and when I want to improve a characteristic it is the one of the chosen character.

To do this I told myself that I would get my active player that is in my gameObject grouping all my players but that’s where I have trouble, I can’t get the code from the active player.

If you have a solution to find the code in my player that is active (not all players) I would like your help.

Thank you very much.

Salut,
Unity - Scripting API: PlayerPrefs will help you to take some variables through your project without much code.

When you load another scene (line 66) al objects in current scene are destroyed. Try loadsceneaddictive or, better, move your character descriptions to scriptable objects and recreate a selected character using that data object.

I personally choose to recreate the character.
You should check also DontDestroyOnLoad, maybe that will work for you.

Later edit: I definitely will chose to recreate the avatar (character).
You just need to think about loading, in DontDestroyOnLoad you need to go through first scene to get the avatar then add attributes and go to your saved location, too much code.

LoadSceneAdditive might be very useful for complex uis. I have many UI screens in the game and players opening maybe 20-25 percents of the screens during each session. I moved windows to scenes and loaded them with additive mode so only screens player wants to see are loaded and total number of loaded screens may be easily limited with UnloadScene calls.