using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class movement : MonoBehaviour
{
Rigidbody2D rb;
float horizontal;
public float speed;
bool jump;
public float jumpforce;
bool turnright = true;
Vector3 scale;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void FixedUpdate()
{
horizontal = Input.GetAxisRaw("Horizontal");
rb.velocity = new Vector2(horizontal * speed * Time.deltaTime, rb.velocity.y);
if(Input.GetKeyDown(KeyCode.Space) && jump == true)
{
rb.AddForce(new Vector2(0, jumpforce));
jump = false;
}
if(horizontal < 0 && turnright == true)
{
Cevir();
}
}
private void OnCollisionEnter2D(Collision2D collision)
{
if(collision.gameObject.tag == "platform")
{
jump = true;
}
}
void Cevir()
{
turnright = !turnright;
scale = gameObject.transform.localScale;
scale.x = scale.x * -1;
gameObject.transform.localScale = scale;
}
}