C# GameObject is Stuck along Two Axes

I’ve been working on this custom Input.GetAxis script and I’ve encountered a problem. My problem is that when I call InputX.GetAxis() it should be able to move from either the x axis or y axis. But instead for some reason it’s stuck along both the x and y axes. Any help would be appreciated.

using UnityEngine;
using System.Collections;

public class InputX{
public static float fPos;
public static float fNeg;
    public static float GetAxis(KeyCode kPos,KeyCode kNeg){
        if (Input.GetKey(kPos)){
            if (!Input.GetKey(kNeg)){
                if(fPos < 1){
                    fPos += Time.deltaTime;
                }
            }
        }
        if (Input.GetKey(kNeg)){
            if(!Input.GetKey(kPos)){
                if(fNeg > -1){
                    fNeg -= Time.deltaTime;
                }
            }
        }
        if (!Input.anyKey){
            if(fPos > 0){
                fPos -= Time.deltaTime;
            }
            if(fNeg < 0){
                fNeg += Time.deltaTime;
            }
        }
    return fPos + fNeg;
    }
}
                //Calling InputX.GetAxis()
                inputPositions = new Vector3(
                InputX.GetAxis(keyPosX,keyNegX),
                InputX.GetAxis(keyPosY,keyNegY),
                cam.transform.position.z
                );
                cam.transform.position = Vector3.Lerp(cam.transform.position, cam.transform.position + inputPositions * speed, Time.smoothDeltaTime);
  1. Don’t you want them to cancel out? What’s the expected behavior if the user is pressing both keys at once?

  2. Rather than having separate positive and negative, you should just have a single number that can be positive or negative.

Yeah the first problem was a mistake. I’ll get that fixed. But how would you use a single number in this instance? The positive and negative functions would leave the value stuck at zero.

using UnityEngine;
using System.Collections;

public class InputX{
public static float fPos;
    public static float GetAxis(KeyCode kPos,KeyCode kNeg){
        if (Input.GetKey(kPos)){
            if (!Input.GetKey(kNeg)){
                if(fPos < 1){
                    fPos += Time.deltaTime;
                }
            }
        }
        if (Input.GetKey(kNeg)){
            if(!Input.GetKey(kPos)){
                if(fPos > -1){
                    fPos-= Time.deltaTime;
                }
            }
        }
        if (!Input.anyKey){
            if(fPos > 0){
                fPos -= Time.deltaTime;
            }
            if(fPos< 0){
                fPos+= Time.deltaTime;
            }
        }
    return fPos;
    }
}