Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Bug Generate C# Classes isn't working correctly anyone know why?

Discussion in 'Input System' started by Evan_Reid, Dec 24, 2023.

?

I really don't know what to do input system is being strange

Poll closed Dec 31, 2023.
  1. IDK

    0 vote(s)
    0.0%
  2. IDK

    0 vote(s)
    0.0%
Multiple votes are allowed.
  1. Evan_Reid

    Evan_Reid

    Joined:
    Mar 18, 2023
    Posts:
    3
    This is very weird since when i delete the C# script everything works but the input actions are completly different for example i changed the sprint key from Control to Shift and it still thinks its Control here is a screenshot of The input action and it clearly shows shift. I'm just confused to why it works without having a C# class generated
    upload_2023-12-24_19-42-57.png
    Here is the compile errors i get when generating a C# class for it
    upload_2023-12-24_19-41-21.png

    This is the only way i am interacting with the input system.

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using UnityEngine.InputSystem;
    4.  
    5. public class Controls : MonoBehaviour
    6. {
    7.     private PlayerControl input;
    8.     private Movement movement;
    9.     public GunHandler gunHandler;
    10.  
    11.     [Header("Axis")]
    12.     public Vector2 movementVector = Vector2.zero;
    13.     public Vector2 lookVector = Vector2.zero;
    14.  
    15.     [Header("Detection")]
    16.     public bool isInteracting = false;
    17.     public bool isSprinting = false;
    18.     public bool isCrawling = false;
    19.     public bool isAiming = false;
    20.  
    21.     private void Awake()
    22.     {
    23.         input = new PlayerControl();
    24.         movement = GetComponent<Movement>();
    25.  
    26.         if (input == null || movement == null)
    27.         {
    28.             Debug.LogError("Input or Movement component is missing.");
    29.         }
    30.     }  
    31.  
    32.     private void OnEnable()
    33.     {
    34.         input.Enable();
    35.         input.Player.Movement.performed += ctx => movementVector = ctx.ReadValue<Vector2>();
    36.         input.Player.Movement.canceled += _ => movementVector = Vector2.zero;
    37.  
    38.         input.Player.Crawl.performed += ToggleCrouch;
    39.  
    40.         input.Player.Look.performed += ctx => lookVector = ctx.ReadValue<Vector2>();
    41.         input.Player.Look.canceled += _ => lookVector = Vector2.zero;
    42.  
    43.         input.Player.Interact.performed += _ => isInteracting = true;
    44.         input.Player.Interact.canceled += _ => isInteracting = false;
    45.  
    46.         input.Player.Sprint.performed += _ => isSprinting = true;
    47.         input.Player.Sprint.canceled += _ => isSprinting = false;
    48.  
    49.         input.Player.Jump.performed += _ => movement.Jump();
    50.  
    51.         input.Player.Aim.performed += _ => isAiming = true;
    52.         input.Player.Aim.canceled += _ => isAiming = false;
    53.  
    54.         input.Player.Fire.performed += _ => gunHandler.Fire();
    55.     }
    56.  
    57.     private void ToggleCrouch(InputAction.CallbackContext value)
    58.     {
    59.         isCrawling = !isCrawling;
    60.     }
    61.  
    62.     private void OnDisable()
    63.     {
    64.         input.Disable();
    65.     }
    66.  
    67.     private void OnDestroy()
    68.     {
    69.         input.Dispose();
    70.     }
    71.  
    72.     // Other methods and properties can be added as needed
    73. }
    74.  
    upload_2023-12-24_19-47-16.png
     
  2. These two should give you the clue that you have duplicated
    PlayerControl.cs
    file in your project somewhere.
     
  3. Evan_Reid

    Evan_Reid

    Joined:
    Mar 18, 2023
    Posts:
    3
    Ah i see i don't know how i didn't notice lol thanks alot man!