Good day. I am using Unity 2021.3.22f1. The Get/Set is not being assigned for the Sword animation. I am unsure if i am assigning the value to the FacingLeft bool properly.
public bool FacingLeft { get { return facingLeft; } set { facingLeft = value; } }
[SerializeField] private float moveSpeed = 1f;
private PlayerControls playerControls;
private Vector2 movement;
private Rigidbody2D rb;
private Animator myAnimator;
private SpriteRenderer mySpriteRenderer;
private bool facingLeft = false;
private void Awake()
{
playerControls = new PlayerControls();
rb = GetComponent<Rigidbody2D>();
myAnimator = GetComponent<Animator>();
mySpriteRenderer = GetComponent<SpriteRenderer>();
}
private void OnEnable()
{
playerControls.Enable();
}
private void OnDisable()
{
playerControls.Disable();
}
private void Update()
{
PlayerInput();
}
private void FixedUpdate()
{
Move();
FlipPlayerPosition();
}
private void PlayerInput()
{
movement = playerControls.Movement.Move.ReadValue<Vector2>();
myAnimator.SetFloat("moveX", movement.x);
myAnimator.SetFloat("moveY", movement.y);
}
private void Move()
{
rb.MovePosition(rb.position + movement * (moveSpeed * Time.fixedDeltaTime));
}
private void FlipPlayerPosition()
{
Vector3 mousePos = Input.mousePosition;
Vector3 playerScreenPos = Camera.main.WorldToScreenPoint(transform.position);
if (mousePos.x < playerScreenPos.x)
{
mySpriteRenderer.flipX = true;
FacingLeft = true;
}
else
mySpriteRenderer.flipX = false;
FacingLeft = false;
}
}