My fire code does print action in console

here’s my code
‘’` {
[SerializeField]InputAction movement;
[SerializeField] float xSpeed = 20f;
[SerializeField] float ySpeed = 20f;
[SerializeField] float xRange = 10f;
[SerializeField] float yRange = 5f;
[SerializeField] float pitchFactor = -4.5f;
[SerializeField] float controlPitchFactor = -10f;
[SerializeField] float yawFactor = 3.5f;
[SerializeField] float rollFactor = 0f;

[SerializeField] InputAction fire;


float horizontalThrow;
float verticalThrow;
                   


private void OnEnable()
{

    movement.Enable();
    fire.Enable();
    
}

private void OnDisable()
{

    movement.Disable();
    fire.Disable();

}
void Update()
{
    ProccessTranslation();
    ProccessRotaion();
}

private void ProccessRotaion()
{
    float pitchByPosition = transform.localPosition.y * pitchFactor;
    float pitchByVThrow = verticalThrow * controlPitchFactor;

    float pitch = pitchByPosition + pitchByVThrow; 
    float yaw = transform.localPosition.x * yawFactor;
    float roll = horizontalThrow * rollFactor;
    transform.localRotation = Quaternion.Euler(pitch, yaw, roll);

 

}

private void ProccessTranslation()
{
    horizontalThrow = movement.ReadValue<Vector2>().x;
   // Debug.Log("Xthrow");
    verticalThrow = movement.ReadValue<Vector2>().y;
   // Debug.Log("Ythrow");

    float xOffset = horizontalThrow * Time.deltaTime * xSpeed;
    float newXPos = transform.localPosition.x + xOffset;
    float limitXPos = Mathf.Clamp(newXPos, -xRange, +xRange);

    float yOffset = verticalThrow * Time.deltaTime * ySpeed;
    float newYPos = transform.localPosition.y + yOffset;
    float limitYPos = Mathf.Clamp(newYPos, -yRange, +yRange);


    transform.localPosition = new Vector3(limitXPos, limitYPos, transform.localPosition.z);
}

void ProccessFire() 
{
    if (fire.ReadValue<float>()> 0.5)
    {
        Debug.Log("shooting");
    }

 
}

}```

I’m not sure what the question is. The only code that will print to the console is in the ProcessFire() method, but nothing is calling that method

1 Like

ohk there a typo soo the code is not printing the shooting message on pressing the fire key.
whats missing in the code?

There is no code running that checks if the key is pressed. You have the code in a ProccessFire() method, but that doesn’t matter because there is nothing calling ProccessFire() so that code never runs.

You probably want to change your update method to this

void Update()
{
    ProccessTranslation();
    ProccessRotaion();
    ProccessFire(); // <- this will call the method
}
1 Like

ohh thank you soo much i forgot about update i thought on enable and disabled was the the place where methods got called in the new Input system

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.