I have been watching tutorials by TheFaceGrabber, and I have been following along with his scripts. Here are two scripts that are supposed to be used to switch characters. Also, the camera is supposed to zoom out, and then go to the selected player and zoom back in.
Game Manager:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class GameManager : MonoBehaviour {
public List<Character> Characters = new List<Character>();
bool ShowCharWheel;
public int SelectedCharacter;
int LastCharacter;
public static GameManager Instance;
public bool CanShowSwitch = true;
void Awake()
{
Instance = this;
foreach (Character c in Characters)
{
c.Instance = Instantiate (c.PlayerPrefab, c.HomeSpawn.position, c.HomeSpawn.rotation) as GameObject;
}
ChangeCharacterStart(Characters[PlayerPrefs.GetInt("SelectedChar")]);
}
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update () {
if (Input.GetKey (KeyCode.C))
{
ShowCharWheel = true;
}
else
{
ShowCharWheel = false;
}
Characters [SelectedCharacter].Instance.GetComponent<PlayerController> ().CanPlay = true;
Camera.main.GetComponent<SmoothFollow> ().target = Characters[SelectedCharacter].Instance.transform;
}
void ChangeCharacterStart(Character c)
{
LastCharacter = SelectedCharacter;
SelectedCharacter = Characters.IndexOf (c);
Characters [LastCharacter].Instance.GetComponent<PlayerController> ().CanPlay = false;
Characters [SelectedCharacter].Instance.GetComponent<PlayerController> ().CanPlay = true;
Camera.main.GetComponent<SmoothFollow> ().target = Characters[SelectedCharacter].Instance.transform;
PlayerPrefs.SetInt ("SelectedChar", SelectedCharacter);
}
void ChangeCharacter(Character c)
{
CanShowSwitch = false;
SequenceManager.Instance.StartCoroutine ("DoCharSwitch", c);
LastCharacter = SelectedCharacter;
SelectedCharacter = Characters.IndexOf (c);
Characters [LastCharacter].Instance.GetComponent<PlayerController> ().CanPlay = false;
Characters [SelectedCharacter].Instance.GetComponent<PlayerController> ().CanPlay = true;
//Camera.main.GetComponent<SmoothFollow> ().target = Characters[SelectedCharacter].Instance.transform;
PlayerPrefs.SetInt ("SelectedChar", SelectedCharacter);
}
void OnGUI()
{
if (ShowCharWheel && CanShowSwitch)
{
GUILayout.BeginArea(new Rect(Screen.width-64, Screen.height-192,64,192));
foreach(Character c in Characters)
{
if(GUILayout.Button(c.Icon,GUILayout.Width(64),GUILayout.Height(64)))
{
ChangeCharacter(c);
}
}
GUILayout.EndArea();
}
}
}
[System.Serializable]
public class Character
{
public string Name;
public Texture2D Icon;
public GameObject PlayerPrefab;
public GameObject Instance;
public Transform HomeSpawn;
}
Sequence Manager:
using UnityEngine;
using System.Collections;
public class SequenceManager : MonoBehaviour {
public CharacterTransition CharSwitch;
public static SequenceManager Instance;
void Awake()
{
Instance = this;
}
public IEnumerator DoCharSwitch(Character c)
{
int i = 0;
while (i > 3)
{
if (i == 0)
{
CharSwitch.Follower.height = CharSwitch.Height;
while(Mathf.Round(CharSwitch.Follower.transform.position.y) != CharSwitch.Height)
yield return new WaitForEndOfFrame();
}
if (i == 1)
{
Vector3 pos = new Vector3(c.Instance.transform.position.x, CharSwitch.Height, c.Instance.transform.position.z);
CharSwitch.Follower.transform.position = Vector3.Lerp(CharSwitch.Follower.transform.position,pos,CharSwitch.Speed*Time.deltaTime);
if(CharSwitch.Follower.transform.position != pos)
yield return new WaitForEndOfFrame();
}
if (i == 2)
{
Camera.main.GetComponent<SmoothFollow> ().target = c.Instance.transform;
CharSwitch.Follower.height = 2;
GameManager.Instance.CanShowSwitch = true;
if ((int)CharSwitch.Follower.transform.position.y != 2)
yield return new WaitForEndOfFrame();
}
i++;
}
StopCoroutine ("DoCharSwitch");
yield return null;
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
[System.Serializable]
public class CharacterTransition
{
public float Height;
public float Speed;
public SmoothFollow Follower;
}
Any help is appriciated, thank you in advance