using UnityEngine; public class PlayerController : MonoBehaviour { public float speed = 1.0f; public float jumpForce = 1.0f; private Rigidbody2D rb; private Transform tr; public bool facingRight = true; public Transform talp; public float talpMeret = 0.2f; public LayerMask miATalaj; // Start is called before the first frame update void Start() { rb = GetComponent(); tr = GetComponent(); } // Update is called once per frame void Update() { float irany = Input.GetAxis("Horizontal"); Vector2 eroVector = new Vector2(irany * speed, 0.0f); rb.AddForce(eroVector); if(facingRight && irany < 0.0f) { flip(); } else if(!facingRight && irany > 0.0f) { flip(); } if(Input.GetButtonDown("Jump")) { rb.AddForce(new Vector2(0.0f, jumpForce), ForceMode2D.Impulse); } float currentSpeed = Mathf.Abs(rb.velocity.x); GetComponent().SetFloat("Speed", currentSpeed); bool foldonAll = Physics2D.OverlapCircle( talp.position, talpMeret, miATalaj); GetComponent().SetBool("Jumping", !foldonAll); } void flip() { Vector3 regiSkala = tr.localScale; regiSkala.x *= -1; tr.localScale = regiSkala; facingRight = !facingRight; } }