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.