I am working on an fps and I want to make an automatic weapon but I can only seem to get it to work on click and it won’t continue to run the method when left click is held. I have tried a few different things online and I just can’t really find the answer.
Current action type for input action is button and initial state check is unticked.
The line of code that I’m trying to fix is onFoot.Attack.performed += ctx => attack.Shoot(); // When the Attack action is performed, call the Shoot method in PlayerAttack
InputManager script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class InputManager : MonoBehaviour
{
// Variables
private PlayerInput playerinput; // Reference to the PlayerInput component
public PlayerInput.OnFootActions onFoot; // Reference to the OnFootActions action map
private PlayerMotor motor; // Reference to the PlayerMotor script component
private PlayerLook look; // Reference to the PlayerLook script component
private PlayerAttack attack; // Reference to the PlayerAttack script component
private PlayerUI playerUI; // Reference to the PlayerUI script component
void Awake()
{
playerinput = new PlayerInput(); // Create a new PlayerInput instance
onFoot = playerinput.OnFoot; // Assign the OnFoot action map to the onFoot variable
// Get scripts on player object
motor = GetComponent<PlayerMotor>(); // Get the PlayerMotor component from the same game object
look = GetComponent<PlayerLook>(); // Get the PlayerLook component from the same game object
attack = GetComponent<PlayerAttack>(); // Get the PlayerAttack component from the same game object
playerUI = GetComponent<PlayerUI>(); // Get the PlayerUI component from the same game object
// PlayerMotor
onFoot.Jump.performed += ctx => motor.Jump(); // When the Jump action is performed, call the Jump method in PlayerMotor
onFoot.Crouch.performed += ctx => motor.Crouch(); // When the Crouch action is performed, call the Crouch method in PlayerMotor
onFoot.Sprint.performed += ctx => motor.Sprint(); // When the Sprint action is performed, call the Sprint method in PlayerMotor
// PlayerAttack
onFoot.Attack.performed += ctx => attack.Shoot(); // When the Attack action is performed, call the Shoot method in PlayerAttack
// PlayerUI
onFoot.Pause.performed += ctx => playerUI.Pause(); // When the Pause action is performed, call the Pause method in PlayerUI
}
void FixedUpdate()
{
// Tell the playermotor to move using the value from our movement action.
motor.ProcessMove(onFoot.Movement.ReadValue<Vector2>()); // Pass the value of the Movement action to the ProcessMove method in PlayerMotor
}
private void LateUpdate()
{
look.ProcessLook(onFoot.Look.ReadValue<Vector2>()); // Pass the value of the Look action to the ProcessLook method in PlayerLook
}
private void OnEnable()
{
onFoot.Enable(); // Enable the OnFoot action map
}
private void OnDisable()
{
onFoot.Disable(); // Disable the OnFoot action map
}
}