Oyun Kütüphanesi

Çok Tuşlu Input Manager

Etkileşim & Input Unity C# 2
ÇokTuşluInputManager .cs
C#
using UnityEngine;

public class InputManager : MonoBehaviour
{
    // Singleton pattern - her yerden erişim için
    public static InputManager Instance { get; private set; }

    // ===== Ham Değerler =====
    public float Horizontal { get; private set; }   // A / D
    public float Vertical { get; private set; }     // W / S

    // ===== Tuş Durumları =====
    public bool Jump { get; private set; }           // Space (tek basış)
    public bool JumpHeld { get; private set; }       // Space (basılı tutuluyor)
    public bool Sprint { get; private set; }         // Sol Shift
    public bool Interact { get; private set; }       // E
    public bool Crouch { get; private set; }         // Sol Ctrl
    public bool Inventory { get; private set; }      // Tab veya I
    public bool Pause { get; private set; }          // Escape

    // Mouse
    public float MouseX { get; private set; }
    public float MouseY { get; private set; }

    void Awake()
    {
        if (Instance != null && Instance != this)
            Destroy(gameObject);
        else
            Instance = this;
    }

    void Update()
    {
        Horizontal = Input.GetAxis("Horizontal");
        Vertical = Input.GetAxis("Vertical");

        Jump = Input.GetButtonDown("Jump");
        JumpHeld = Input.GetButton("Jump");
        Sprint = Input.GetKey(KeyCode.LeftShift);
        Interact = Input.GetKeyDown(KeyCode.E);
        Crouch = Input.GetKey(KeyCode.LeftControl);
        Inventory = Input.GetKeyDown(KeyCode.Tab) || Input.GetKeyDown(KeyCode.I);
        Pause = Input.GetKeyDown(KeyCode.Escape);

        MouseX = Input.GetAxis("Mouse X");
        MouseY = Input.GetAxis("Mouse Y");
    }
}

// ---- KULLANIM (diğer scriptlerde) ----
// InputManager.Instance.Jump     -> Space'e bu karede basıldı mı?
// InputManager.Instance.Sprint   -> Shift basılı mı?
// InputManager.Instance.Vertical -> 0 ile 1 arası ileri/geri değer

Açıklama

Tüm oyun giriş tuşlarını tek bir yerde toplayan, kolayca genişletilebilir yapıda Input yönetim scripti.

Etiketler

Input Tuş Yönetim Manager GetKey

Nasıl Kullanılır?

1. Sahneye boş bir GameObject ekle (örn: 'InputManager').

2. Bu scripti ekle — Singleton olduğu için sahnede tek kalır.

3. Diğer scriptlerde 'InputManager.Instance.Jump' gibi erişebilirsin.

4. Bu yapı, kullanıcı tuş atamalarını merkezi olarak yönetmeni sağlar.

Unity 2022+ ve Unity 6 ile uyumludur.

MonoBehaviour tabanlı scriptleri Assets klasörüne .cs olarak kaydedin.