using UnityEngine;
using System.Collections;

public class PlayerController : MonoBehaviour {
    private RexController rexController;
    private PlayerWidget[] playerWidgets;
    private int PlayerAmount = 4;

    public void Initialize() {
        playerWidgets = new PlayerWidget[PlayerAmount];
        for (int i = 0; i < PlayerAmount; i++) {
            playerWidgets[i] = GameObject.Find("r_Player"+i).GetComponent<PlayerWidget>();
        }
    }

    public void OnIndexPicked(int offset) {
        rexController = GetComponent<RexController>();

        for (int i = 0; i < PlayerAmount; i++) {
            int playerIndex = offset+i < PlayerAmount ? offset+i : (offset+i)-PlayerAmount;
            Transform t = rexController.AddJoint(playerIndex,"LHorizontal"+(i+1));
            PlayerWidget playerWidget = playerWidgets[i];
            playerWidget.SetPlayerTransform(t);
            playerWidget.Show(4);
        }
    }
}