Skip to content

Instantly share code, notes, and snippets.

@unity3dcollege
Created August 30, 2017 17:31
Show Gist options
  • Save unity3dcollege/60c002d0e78e46f49c5b38dc1acab261 to your computer and use it in GitHub Desktop.
Save unity3dcollege/60c002d0e78e46f49c5b38dc1acab261 to your computer and use it in GitHub Desktop.
using UnityEngine;
public class CharacterControlSwapper : MonoBehaviour
{
private Character[] characters;
int characterIndex;
private void Awake()
{
characters = FindObjectsOfType<Character>();
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
SelectNextCharacter();
}
}
private void SelectNextCharacter()
{
characters[characterIndex].UseAIBrain();
characterIndex++;
if (characterIndex >= characters.Length)
characterIndex = 0;
characters[characterIndex].UsePlayerBrain();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment