Why does Mathf.Sign(deltaX) return 1 when I face right and -1 when I face left ,Why does Mathf.Sign(deltaX) return 1 when I face right and -1 when I face left

private Animator _ainm;
private Rigidbody2D _body;
public float speed = 250.0f;
// Use this for initialization
void Start () {
_body = GetComponent();
_ainm = GetComponent();

}

// Update is called once per frame
void Update ()
{
    float deltaX = Input.GetAxis("Horizontal") * speed * Time.deltaTime;
    Vector2 movement = new Vector2(deltaX, _body.velocity.y);
    _body.velocity = movement;
    _ainm.SetFloat("Speed", Mathf.Abs(deltaX));
    Debug.Log(deltaX);
    if (!Mathf.Approximately(deltaX, 0))
    {
        transform.localScale = new Vector3(Mathf.Sign(deltaX), 1, 1);

    }
}

},

Uhm because “Sign” returns just the sign of the number provided. So it will return “+1” when the number is positiveor 0 and “-1” when the number is negative. I just repeated what the documentation says.

I’m not sure what else we can tell you here since you haven’t mentioned what you actually want to do or what problem you have.