2d character rotation

Hello everyone. I’m doing a platform game in 2d (camera on the side of the character). I made motion animations and I have a problem with how to turn the character (animations) in both directions after pressing the “A” key.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Ruch : MonoBehaviour
{
    public float speed;
    public float jump;
    public Rigidbody2D bohater;
    public float stanPrzed;
    public float roznica;
    private Animator animacja;
    public Transform czujnik;
    public float promien;
    public LayerMask warstwa;
    public bool dotyk;

    void FixedUpdate()
    {
        stanPrzed = bohater.position.x;
        dotyk = Physics2D.OverlapCircle (czujnik.position, promien, warstwa);
    }

    void Start()
    {
        bohater = GetComponent<Rigidbody2D> ();
        animacja = GetComponent<Animator> ();
       
    }

    void Update()
    {
        roznica = Mathf.Abs(stanPrzed - bohater.position.x);
        animacja.SetFloat("kontrola", roznica);
        if (Input.GetKey (KeyCode.D)){
            bohater.velocity = new Vector2 (speed, bohater.velocity.y);
        }
        if (Input.GetKey (KeyCode.A)){
            bohater.velocity = new Vector2 (-speed, bohater.velocity.y);
           
        }
        if (Input.GetKey (KeyCode.Space) && dotyk){
            bohater.velocity = new Vector2 (bohater.velocity.x, jump);
        }
       
           
       
    }
}

“I have a problem” is not useful.

How to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

This is the bare minimum of information to report:

  • what you want
  • what you tried
  • what you expected to happen
  • what actually happened, especially any errors you see
  • links to documentation you used to cross-check your work (CRITICAL!!!)

You may edit your post above.