I am trying to change my endless runner character in-game. I have a character select menu set up to where I can click the character and it will show up on the character select menu but it won’t change the character in the game the pic below shows my character select menu and this is my code for that menu
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Collections.Generic;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class CharacterCreation : MonoBehaviour
{
private List<GameObject> models;
private int selectionIndex = 0;
public static int moneyAmount;
int whichAvaterIsOn = 1;
public GameObject avatar0, avatar1, avatar2, avatar3, avatar4;
private readonly string selectedCharacter = "SelectedCharacter";
private void Start()
{
models = new List<GameObject>();
foreach(Transform t in transform)
{
models.Add(t.gameObject);
t.gameObject.SetActive(false);
}
models[selectionIndex].SetActive(true);
}
public void SwitchAvatar1()
{
switch (whichAvaterIsOn)
{
case 1:
whichAvaterIsOn = 2;
avatar0.gameObject.SetActive(false);
avatar1.gameObject.SetActive(true);
avatar2.gameObject.SetActive(false);
avatar3.gameObject.SetActive(false);
avatar4.gameObject.SetActive(false);
break;
}
}
public void SwitchAvatar2()
{
switch (whichAvaterIsOn)
{
case 2:
whichAvaterIsOn = 1;
avatar0.gameObject.SetActive(true);
avatar1.gameObject.SetActive(false);
avatar2.gameObject.SetActive(false);
avatar3.gameObject.SetActive(false);
avatar4.gameObject.SetActive(false);
break;
}
}
public void SwitchAvatar3()
{
switch (whichAvaterIsOn)
{
case 3:
whichAvaterIsOn = 3;
avatar0.gameObject.SetActive(false);
avatar1.gameObject.SetActive(false);
avatar2.gameObject.SetActive(true);
avatar3.gameObject.SetActive(false);
avatar4.gameObject.SetActive(false);
break;
}
}
public void SwitchAvatar4()
{
switch (whichAvaterIsOn)
{
case 4:
whichAvaterIsOn = 4;
avatar0.gameObject.SetActive(false);
avatar1.gameObject.SetActive(false);
avatar2.gameObject.SetActive(false);
avatar3.gameObject.SetActive(true);
avatar4.gameObject.SetActive(false);
break;
}
}
public void SwitchAvatar5()
{
switch (whichAvaterIsOn)
{
case 5:
whichAvaterIsOn = 5;
avatar0.gameObject.SetActive(false);
avatar1.gameObject.SetActive(false);
avatar2.gameObject.SetActive(false);
avatar3.gameObject.SetActive(false);
avatar4.gameObject.SetActive(true);
break;
}
}
private void Update()
{
}
public void Select(int index)
{
if (index == selectionIndex)
return;
if (index < 0 || index >= models.Count)
return;
models[selectionIndex].SetActive(false);
selectionIndex = index;
models[selectionIndex].SetActive(true);
}
}
I would just like to know how to change the character in-game when I click on the character button.