Skip to content

Instantly share code, notes, and snippets.

@foxqstm
Created August 22, 2021 05:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save foxqstm/9a6b60bb65845f73810a95a016c39b0c to your computer and use it in GitHub Desktop.
Save foxqstm/9a6b60bb65845f73810a95a016c39b0c to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public int speed = 1;
float sc = 0.3162f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
int key = 0;
if(Input.GetKeyDown(KeyCode.LeftArrow))
{
transform.Translate(-speed, 0, 0);
key = 1;
}
if (Input.GetKeyDown(KeyCode.RightArrow))
{
transform.Translate(speed, 0, 0);
key = -1;
}
if (key != 0)
{
transform.localScale = new Vector3(sc * key, sc, sc);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment