Answers for "how to make player flip when pressing a d unity 2d"

C#
3

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

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;
    }
Posted by: Guest on October-03-2020
8

first person camera controller unity

//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, 0, 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;
		}
	}
}
Posted by: Guest on May-25-2020

Code answers related to "how to make player flip when pressing a d unity 2d"

C# Answers by Framework

Browse Popular Code Answers by Language