Differant sprites in states

Hi im not sure how to ask this as its rather complicated i have a a top down game where my character is split into 4 parts a left facing and right,up and down . made out of different parts and animated inside unity is their a way that i can sort of combine thees to use states like left right up and down so i can easily access these in scrip. so that i can add weapons and things

here is what i do currently but its rather alot and hard to access weapons on each part

using UnityEngine;
using System.Collections;
using SpriteTile;
public class CharacterMovement :Photon.MonoBehaviour
{

	public float speed;

	public Camera cam;
	public TextAsset myLevel;

	public GameObject Front;
	public GameObject Back;
	public GameObject Left;
	public GameObject Right;

	public Animator Forwardanim;
	public Animator Backwardanim;
	public Animator Leftanim;
	public Animator Rightanim;


	void Start()
	{
		Front.SetActive(true);
		Back.SetActive(false);
		Left.SetActive(false);
		Right.SetActive(false);
		if (photonView.isMine) 
		{
			cam.enabled = true;

		}
		if (photonView.isMine) {
			Tile.SetCamera(cam);
			Tile.LoadLevel (myLevel);
		}
	}

	void Update() 
	{
		if (photonView.isMine) {
		if(Input.GetKey(KeyCode.W)){
			rigidbody2D.transform.position += Vector3.up * speed * Time.deltaTime;
			GetComponent<PhotonView>().RPC("ForwardAnim",PhotonTargets.All);
		}

		else if(Input.GetKey(KeyCode.S)){
			rigidbody2D.transform.position += Vector3.down * speed * Time.deltaTime;
			GetComponent<PhotonView>().RPC("BackwardAnim",PhotonTargets.All);
		}

		else if(Input.GetKey(KeyCode.A)){
			rigidbody2D.transform.position += Vector3.left * speed * Time.deltaTime;
			GetComponent<PhotonView>().RPC("LeftAnim",PhotonTargets.All);
		}

		else if(Input.GetKey(KeyCode.D)){
			rigidbody2D.transform.position += Vector3.right * speed * Time.deltaTime;
			GetComponent<PhotonView>().RPC("RightAnim",PhotonTargets.All);
		}
		else
		{
				GetComponent<PhotonView>().RPC("LeftAnimOff",PhotonTargets.All);
				GetComponent<PhotonView>().RPC("RightAnimOff",PhotonTargets.All);
				GetComponent<PhotonView>().RPC("ForwardAnimOff",PhotonTargets.All);
				GetComponent<PhotonView>().RPC("BackAnimOff",PhotonTargets.All);
		}

	}
	}

	[RPC]
	void ForwardAnim()
	{
		Front.SetActive(false);
		Back.SetActive(true);
		Left.SetActive(false);
		Right.SetActive(false);
		Backwardanim.SetBool ("Walking", true);
	}
	[RPC]
	void ForwardAnimOff()
	{
		Backwardanim.SetBool ("Walking", false);
	}


	[RPC]
	void BackwardAnim()
	{
		Front.SetActive(true);
		Back.SetActive(false);
		Left.SetActive(false);
		Right.SetActive(false);
		Forwardanim.SetBool ("Walking", true);
	}
	[RPC]
	void BackAnimOff()
	{
		Forwardanim.SetBool ("Walking", false);
	}


	[RPC]
	void LeftAnim()
	{
		Front.SetActive(false);
		Back.SetActive(false);
		Left.SetActive(true);
		Right.SetActive(false);
		Leftanim.SetBool ("Walking", true);
	}
	[RPC]
	void LeftAnimOff()
	{
		Leftanim.SetBool ("Walking", false);
	}


	[RPC]
	void RightAnim()
	{
		Front.SetActive(false);
		Back.SetActive(false);
		Left.SetActive(false);
		Right.SetActive(true);
		Rightanim.SetBool ("Walking", true);
	}
	[RPC]
	void RightAnimOff()
	{
		Rightanim.SetBool ("Walking", false);
	}
}

Have a “Weapon” script and make sure the 4 objects are children of another object (“MainPlayerObject”). You can then directly access the weapons with:

MainPlayerObject.GetComponentsInChildren<Weapon>()

which returns an array of Weapon
The order will depend on the hierarchy.

I suggest that instead of using 4 seperate GameObjects you use an array of 4 GameObjects and have the index be the direction:

GameObject PlayerSides[] = new GameObject[4];

0 is left, 1 is right, 2 is up, 3 is down. Or some other order, up to you.

It’s a lot eaasier writing procedural code in this format.