Alright, so I have a character select scene and I have 4 platforms with buttons for a player to choose between 4 characters to make a team. I have a character container and a script for selecting the characters and buttons that represents each character. Almost everything is working but my first problem is I can only select one character and my second problem is referencing the selected character and setting them active in the position and rotation of the selected platform. For my first problem I was thinking of adding an array, but I need help executing it as well as I need help transforming the position of the selected character. My script that works is
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CharacterContainer : MonoBehaviour
{
private List<GameObject> characters;
private int selectionIndex = 0;
private void Start()
{
characters = new List<GameObject>();
foreach(Transform t in transform)
{
characters.Add(t.gameObject);
t.gameObject.SetActive(false);
}
characters[selectionIndex].SetActive(true);
}
public void Select(int index)
{
if(index == selectionIndex)
return;
if(index < 0 || index >= characters.Count)
return;
characters[selectionIndex].SetActive(false);
selectionIndex = index;
characters[selectionIndex].SetActive(true);
}
}
And the edits that I began on the script are
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CharacterContainer : MonoBehaviour
{
private List<GameObject> characters;
private int selectionIndex = 0;
public Transform Player1SpawnPoint;
public Transform Player2SpawnPoint;
public Transform Player3SpawnPoint;
public Transform Player4SpawnPoint;
public bool platformActive;
private void Start()
{
characters = new List<GameObject>();
foreach(Transform t in transform)
{
characters.Add(t.gameObject);
t.gameObject.SetActive(false);
}
characters[selectionIndex].SetActive(true);
}
public void Select(int index)
{
if(index == selectionIndex)
return;
if(index < 0 || index >= characters.Count)
return;
characters[selectionIndex].SetActive(false);
selectionIndex = index;
characters[selectionIndex].SetActive(true);
}
//////Transform the position on selected platform
if (platformActive)
{
characters[selectionIndex].transform.Translate(Player1SpawnPoint.position, Player1SpawnPoint.rotation;)
}
}
I was gonna have 4 platformActive listed, but the first one didn’t work. I hit a wall.