// Use this for initialization
	void Start () {
		// initialize the GUI Controller object
		gc = GameObject.Find ("GUI Controller").GetComponent<Level_GUIController> ();
		// initialize the Network Controller object
		nc = GameObject.Find ("Network Controller").GetComponent<Level_NetworkController> ();
		classNo=9;
	}
	// Use this for initialization
	void Start () {
		//linkSlider.gameObject.SetActive (false);
		gui = GameObject.Find("GUI Controller").GetComponent<Level_GUIController>();
		if (currentTeam == Char_AttributeScript.Teams.BLUE){
			linkValue = 0;
			InitBlue();
		}
		else if (currentTeam == Char_AttributeScript.Teams.RED){
			linkValue = 100;
			InitRed();
		}
		else
			InitNeutral();
	}
	// Use this for initialization
	void Start () {
		// initialize the GUI Controller object
		gc = GameObject.Find ("GUI Controller").GetComponent<Level_GUIController> ();
	}
	[RPC] void MovePlayerTeamList(string pName, int newTeam){

		nc = GameObject.Find ("Network Controller").GetComponent<Level_NetworkController> ();
		gc = GameObject.Find ("GUI Controller").GetComponent<Level_GUIController> ();
		//If we join after other players
		if (nc.neutPlayers == null) {
			nc.neutPlayers = new List<PlayerInfo>();
			for (int i = 0; i < PhotonNetwork.playerList.Length - 1; i++){
				PlayerInfo newPlayer = new PlayerInfo("blank_name");
				nc.neutPlayers.Add(newPlayer);
			}
		}

		Debug.Log(pName + " " + newTeam.ToString());
		for (int i = 0; i < nc.neutPlayers.Count; i++){
			if (nc.neutPlayers[i].name == _MainController.playerName || nc.neutPlayers[i].name == "blank_name"){
				PlayerInfo pi = nc.neutPlayers[i];
				nc.neutPlayers.Remove(pi);
				pi.team = (Char_AttributeScript.Teams)newTeam;
				pi.name = pName;
				//pi.photonPlayerName = pName;
				if (pi.team == Char_AttributeScript.Teams.BLUE)
					nc.bluePlayers.Add(pi);
				else
					nc.redPlayers.Add(pi);
				break;
			}
		}

		gc.SetUpScoreboard();
		
		if (photonView.isMine)
			photonView.RPC("MovePlayerTeamList", PhotonTargets.OthersBuffered, pName, newTeam);
	}
	// Use this for initialization
	void Start () {

		animInstance = GetComponent<Char_BasicMoveScript> ();
		//audio = GetComponent<AudioSource> ();
		HUD = GameObject.Find("GUI Controller").GetComponent<Level_GUIController>();

		if (photonView.isMine){
			buffs= new List<string>();

			animInstance.anim.SetBool("Pistol",true);
			animInstance.anim.SetBool("SecondaryWeapon",false);

			pistolMuzzleFlash.transform.parent = weapon1.transform;
			pistolMuzzleFlash.transform.position = pistolFPSMuzzle.transform.position;
			pistolMuzzleFlash.transform.rotation = Quaternion.identity;

			pistolMuzzleEmitter.transform.position = pistolFPSMuzzle.transform.position;

			secondaryMuzzleFlash.transform.parent = weapon2.transform;
			secondaryMuzzleFlash.transform.position = secondaryFPSMuzzle.transform.position;
			secondaryMuzzleFlash.transform.localRotation = Quaternion.identity;

			secondaryMuzzleEmitter.transform.position = secondaryFPSMuzzle.transform.position;

			if (builderGloveMuzzle && !builderGloveMuzzle.transform.name.Equals("EmptyGameObject")){
				builderGloveMuzzle.transform.parent = weapon3.transform;
				builderGloveMuzzle.transform.position = builderGloveFPSPos.transform.position;
				//builderGloveMuzzle.transform.localRotation = Quaternion.identity;
				builderGloveMuzzle.transform.localRotation = Quaternion.Euler(new Vector3(15,60,290));
				//builderGloveMuzzle.transform.GetComponentInChildren<ParticleSystem>().transform.localPosition = Vector3.zero;

				gloveEmitter.transform.localPosition = new Vector3(0.3810017f, -0.261f, 1.086f);
				//gloveEmitter.GetComponentInChildren<ParticleSystem>().Play();
			}
				

			//thirdPersonSecondary.SetActive(false);
			//secondaryMuzzleFlash.transform.parent.gameObject.SetActive(false);

			MeshRenderer[] fpWeapon2 = weapon2.GetComponentsInChildren<MeshRenderer>();
			for (int i = 0; i < fpWeapon2.Length; i++){
				fpWeapon2[i].enabled = true;
			}

			MeshRenderer[] meshes = thirdPersonPlayer.GetComponentsInChildren<MeshRenderer>();
			for (int i = 0; i < meshes.Length; i++){
				meshes[i].enabled = false;
			}

			SkinnedMeshRenderer[] skMeshes = thirdPersonPlayer.GetComponentsInChildren<SkinnedMeshRenderer>();
			for (int i = 0; i < skMeshes.Length; i++){
				skMeshes[i].enabled = false;
			}
			
			SkinnedMeshRenderer[] skfpWeapon1 = weapon1.GetComponentsInChildren<SkinnedMeshRenderer>();
			for (int i = 0; i < skfpWeapon1.Length; i++){
				skfpWeapon1[i].enabled = true;
			}
			
			SkinnedMeshRenderer[] skfpWeapon2 = weapon2.GetComponentsInChildren<SkinnedMeshRenderer>();
			for (int i = 0; i < skfpWeapon2.Length; i++){
				skfpWeapon2[i].enabled = true;
			}
			
			MeshRenderer[] fpBuilderGlove = weapon3.GetComponentsInChildren<MeshRenderer>();
			for (int i = 0; i < fpBuilderGlove.Length; i++){
				fpBuilderGlove[i].enabled = true;
			}

			SetPlayerName(GetComponent<PhotonView>().viewID, _MainController.playerName);

			if(team == Teams.RED){
				joinTeam(new Vector3(Color.red.r, Color.red.g, Color.red.b), 0, playerName + " spawned as RED");
				playerColor = Color.red;
			}
			else if(team == Teams.BLUE){
				joinTeam(new Vector3(Color.blue.r, Color.blue.g, Color.blue.b), 1, playerName + " spawned as BLUE");
				playerColor = Color.blue;
			}

			InvokeRepeating("energyTrickle",energyTrickeRate,energyTrickeRate);
		}

		weapon2.SetActive(false);
		thirdPersonSecondary.SetActive (false);
		weapon3.SetActive(false);
		thirdPersonBuilderGlove.SetActive(false); 
	}
	[RPC] void joinTeam(Vector3 color, int myTeam, string message)
	{
		renderer.material.color = new Color(color.x, color.y, color.z, 1f);
		armour.material.color = new Color(color.x, color.y, color.z, 1f);
		HUD = GameObject.Find("GUI Controller").GetComponent<Level_GUIController>();
		HUD.AddItemToScrollingList(message,  new Color(color.x, color.y, color.z, 1f));
		team = (Teams)myTeam;
		if (photonView.isMine)
			photonView.RPC("joinTeam", PhotonTargets.OthersBuffered, color, myTeam, message);
	}