using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ChangePlayer : MonoBehaviour
{
public Transform character;
public list<Transform> possibleCharacters;
public int whichCharacter;
// Start is called before the first frame update
void Start()
{
if(character == null && possibleCharacters.Count >-1)
{
character = possibleCharacters[0];
}
Swap();
}
// Update is called once per frame
void Update()
{
if(Input.GetKeyDown(KeyCode.R))
{
if(whichCharacter ==0 )
{
whichCharacter = possibleCharacters.Count -1;
}
else
{
whichCharacter -= 1;
}
Swap();
}
if(Input.GetKeyDown(KeyCode.P))
{
if(whichCharacter == possibleCharacters.Count - 1 )
{
whichCharacter = 0;
}
else
{
whichCharacter += 1;
}
Swap();
}
}
public void Swap()
{
character = possibleCharacters[whichCharacter];
character.GetComponent<PlayerController>().enabled = true;
for (int i - 0; i < possibleCharacters.Count; i++)
{
if(possibleCharacters *!= character)*
{
possibleCharacters*.GetComponent().enabled = false;*
}
} }
}
Thank you. It worked!!!!
– haydenle632