Hi what would be the easiest way for me to to create a state for each what that the player is facing?
example
i have 4 states on my player (facing up,down,left,right) these all have different game objects active and and different animations playing. how would i go about telling the player is facing these directions? to use in an attacking script so that if im facing right it would raycast right ect.
i was thinking of using enums but im not sure how to implement this
i use this script currently but their is alot going on and would love to shorten it by using enums
using UnityEngine;
using System.Collections;
using SpriteTile;
using PlayerStates;
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);
}
}