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);