using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PlayerController : MonoBehaviour
{
public int haraketHizi = 10;
public float speed = 5f;
public float min_X, max_X;
private float yatayHareket;
private Rigidbody2D rb;
public GameObject panel;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
yatayHareket = Input.GetAxis("Horizontal");
rb.velocity = new Vector2(yatayHareket * haraketHizi * Time.deltaTime, rb.velocity.y);
// Oyuncunun sınırlarını kontrol et
float clampedX = Mathf.Clamp(rb.position.x, min_X, max_X);
rb.position = new Vector2(clampedX, rb.position.y);
// Sağ ve Sol hareket için düğmeleri kontrol et
if (Input.GetKey(KeyCode.LeftArrow))
{
Sol();
}
else if (Input.GetKey(KeyCode.RightArrow))
{
Sag();
}
else
{
Dur();
}
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.CompareTag("para"))
{
panel.SetActive(true);
}
}
public void Sol()
{
yatayHareket = -1;
if (rb.position.x > max_X)
rb.position = new Vector2(max_X, rb.position.y);
}
public void Sag()
{
yatayHareket = 1;
if (rb.position.x < min_X)
rb.position = new Vector2(min_X, rb.position.y);
}
public void Dur()
{
yatayHareket = 0;
}
}