Q:

how to make player flip when pressing a d unity 2d

//Fixed the issues with the previous controller
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraLook : MonoBehaviour
{
	public float minX = -60f;
	public float maxX = 60f;

	public float sensitivity;
	public Camera cam;

	float rotY = 0f;
	float rotX = 0f;

	void Start()
	{
		Cursor.lockState = CursorLockMode.Locked;
		Cursor.visible = false;
	}

    void Update()
    {
		rotY += Input.GetAxis("Mouse X") * sensitivity;
		rotX += Input.GetAxis("Mouse Y") * sensitivity;

		rotX = Mathf.Clamp(rotX, minX, maxX);

		transform.localEulerAngles = new Vector3(0, rotY, 0);
		cam.transform.localEulerAngles = new Vector3(-rotX, rotY, 0);

		if (Input.GetKeyDown(KeyCode.Escape))
		{
        	//Mistake happened here vvvv
			Cursor.lockState = CursorLockMode.None;
			Cursor.visible = true;
		}

		if (Cursor.visible && Input.GetMouseButtonDown(1))
		{
			Cursor.lockState = CursorLockMode.Locked;
			Cursor.visible = false;
		}
	}
}
9
 void  Update ()
    {  //This short code makes player flip when the A and D or arrow keys are pressed.

        Vector3 charecterScale = transform.localScale;
        if (Input.GetAxis("Horizontal") < 0)
        {
            charecterScale.x = -10;
        } 
        if (Input.GetAxis("Horizontal") > 0)
        {
            charecterScale.x = 10;
        }
        transform.localScale = charecterScale;
    }
1
   if (isRight == true && isLeft == false) {         transform.eulerAngles = new Vector3(0, 0 ,0);   }   if (isRight == false && isLeft === true) {         transform.eulerAngles = new Vector3(0, 180, 0);   }
0

New to Communities?

Join the community