Created
August 30, 2017 17:31
-
-
Save unity3dcollege/60c002d0e78e46f49c5b38dc1acab261 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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