Головна‎ > ‎Unity‎ > ‎2D‎ > ‎Інші 2D скрипти‎ > ‎

Платформер

public float maxspeed = 10f;
public float move;
public float jumpForse = 700f;
private Rigidbody2D rb; 
bool LookRight = true;


 void Start () {
rb = GetComponent<Rigidbody2D>();
Cursor.lockState = CursorLockMode.Locked;
 }
 

 void FixedUpdate () {
move = Input.GetAxis("Horizontal");
 }

 void Flip(){
LookRight = !LookRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
 }
 
 void Update () {
rb.velocity = new Vector2(move*maxspeed, rb.velocity.y);

if (LookRight == true && move < 0) {
Flip ();
}
else if(move > 0 && LookRight == false){
Flip ();
}


if (Input.GetKeyDown(KeyCode.Escape)) {
Cursor.lockState = CursorLockMode.None;
}
 }