How to make Versus screen in Unity

¡WOW! How can I change this unity forum, after so many time without going to the forum. After learning the basics in Junior Programmer, I have managed to advance a little more in my understanding of Unity. I recently downloaded a fighting game project made in Unity that is inspired by the MUGEN game engine. This project has allowed me to learn a lot, such as how the game options work, the new input system, artificial intelligence, among other things. However, there are still aspects that are not being added, such as the implementation of the arcade mode, the selection and loading of characters, the operation of the sounds not working, the story mode, and the limitation of the camera zoom, among others. Fortunately, I have permission to modify this project to my liking.

I am here because I need help with loading characters in the versus screen. For example, in the character selection, if I have Bruno as a character and I choose Cube, I don’t know how to make Cube load in the versus scene (What you do is think that the character you chose is loaded but in reality it was always active, there is no script that loads the character you chose). What I’ve done so far in the character selection scene is to create a GameObject, copy the script that loads the character (SelectPlayer), and place Cube as a child of the object that has the script to spawn the character (SelectPlayer). However, when I choose a scenario and go to the versus scene, the character I selected doesn’t appear; instead, the default character appears. Here’s the video with details.

The problem seems to be related to the fact that the script has a public GameObject PrefabPlayer array; which only contains Bruno. When I try to add Cube, the script spawns both Bruno and Cube in the P1 and P2 positions, which results in a mess. This script doesn’t seem to be designed to load the previously selected character, but instead only loads the prefab that’s already set up in the battlefield scene.

Is there an idea or tip I could do? If you want I can give you more details of the code. Thanks in advance.

Please don’t recommend me to download or buy from UFE (Universal Fighting Engine) asset store because I don’t have USD, I’m a 16 year old so I don’t have a bank account to deposit money, in Argentina the payment rule is different from your country (for example the United States).

(Sorry if there are some parts that are poorly translated, I’m using Google Translate)

Hi @CaptainVega ,

Dont know your script but belive catched idea.
You had two scenes (one for character selection and second for fight, right)?

If yes, first scene need to result in some sort of data saving which character was chosen by player.
This could be [string] GameObject.name or [int] index of GameObject inside array.

If you are able to use same array in character chose scene and fight scene suggest going with array index.
Then this value int/string need to be stored (or not destroyed) when next scene is loaded.
And finaly, you can have GameObject with all characters in scene (just use hierarchy and arrange them) then when scene is loaded, cast SetActive(true) on chosen Character GameObject.

Hope will do, let me know below!

I think you are right, good, but I don’t know how to make a character loading script without making it complicated.

but there is this in the ConfiguracionA script, it is in Spanish but I translate it in English `public static class ConfiguracionA { //****************************************************************// //*****************************************************************// public enum CombatType { VSOneOnOne, VSTeam, Arcade }; public enum LanguageSetting { English, Spanish }; public enum VoiceLanguageSetting { English, Spanish }; public enum Control { Keyboard, Xbox, Playstation, Virtual }; public enum GameMode { P1VSCpu, P1VSP2, CpuVSCpu, Online, P1VSArcade }; public enum AllyMode { Solo, Cooperative };

//// //// public static CombatType CombatMode;
public static LanguageSettingLanguage;
public static VoiceLanguageSetting VoiceLanguage;
public static GameModeVersusMode = GameMode.P1VSP2;
public static AllyModeTeam;
public static ScreenMode DisplayMode = ScreenMode.Normal;
public static int SelectedPlayerP1;
public static int SelectedPlayerP2;
public static float TimeLimit = 90f;
public static bool InfiniteTime;
public static bool NoRounds;
public static ControlControlType;
public static bool PlayEnter = true;
public static bool PlayVictory = true;
public static bool Player1HasPartner;
public static bool Player2HasPartner;
public static int PlayerControllers;
public static bool StartPressed;
public static bool P2UsesKeyboardAsController;

//// //// } the public static int SelectedPlayerP1; which is responsible for loading the character with the prefabs. for example (in the battle scene,not on the versus screen)if (ConfiguracionA.VersusMode == ConfiguracionA.GameMode.P1VSP2) { PlayerP1 = Instantiate(PrefabPlayer[ConfiguracionA.SelectedPlayerP1], new Vector3(-3, 0, 0), transform.rotation = Quatern ion.Euler(0f, 90f, 0f));
PlayerP1.SetActive(true);
PlayerP1.GetComponent().Player = PlayerCommand.PlayerType.P1;

PlayerP2 = Instantiate(PrefabPlayer[ConfigurationA.SelectedPlayerP2], new Vector3(3, 0, 0), transform.rotation = Quaternion.Euler(0f, -90f, 0f));
PlayerP2.SetActive(true);
PlayerP2.GetComponent().Player = PlayerCommand.PlayerType.P2;
} ` PlayerP1 = Instantiate(PrefabPlayer[ConfigurationA.SelectedPlayerP1] I imagine that if I change from 0 to 1 change to the scene cube. it could work. right? Still, if you would like to make your own character loading system for this project, you can if you want, I can not make it so complex. Well, it is only optional to create your own character loading system.

Hi @CaptainVega,

Try to use/edit ``` before first and after last line, when pasting code, will help a lot in future.

Yes this line is one you look for:

Instantiate(PrefabPlayer[ConfigurationA.SelectedPlayerP1]]

We can see that there is array of PrefabPlayer, (1) add cube to this array.
(2) then change numeber for this index (as you mention 1).

You mention that script will create all elemnts from PrefabPlayer array when do as mention above. Can you confirm this, still occuring?

I tried to use ``` in the code of the post, but he didn’t do it correctly, it’s because I’m new to the unity forum change. Ok, I’ll do it later because it’s raining a lot with a storm. I have to turn off my computer and try later.

1 Like

How could I change the index to 1 in the code🤔? Sorry, I think I’ve forgotten how to do it.