Hello I apologize for my bad English.
I need a little help, I added xbox joltik support to my project, but I have a problem.
Any button that I add when pressed such as the menu opening button opens and closes very quickly, I have to press it several times to open it. Or, for example, the B button.
Does anyone have any idea how to fix this problem?
This is the original code:
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
[RequireComponent(typeof(FPSController))]
public class FPSInputController : NetworkBehaviour
{
private FPSController fpsControl;
void Start()
{
fpsControl = this.GetComponent<FPSController>();
MouseLock.MouseLocked = true;
}
void Update()
{
if (isLocalPlayer && fpsControl != null)
{
fpsControl.MoveCommand(new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")), Input.GetButton("Jump"));
if (Input.GetKeyDown(KeyCode.C))
{
fpsControl.Sit();
}
if (Input.GetKeyDown(KeyCode.F))
{
fpsControl.OutVehicle();
}
if (Input.GetKey(KeyCode.LeftShift))
{
fpsControl.Boost(1.4f);
}
if (MouseLock.MouseLocked)
{
fpsControl.Aim(new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y")));
fpsControl.Trigger1(Input.GetButton("Fire1"));
fpsControl.Trigger2(Input.GetButtonDown("Fire2"));
}
if (Input.GetKeyDown(KeyCode.F))
{
fpsControl.Interactive();
}
if (Input.GetKeyDown(KeyCode.V))
{
fpsControl.SwithView();
}
if (Input.GetKeyDown(KeyCode.B))
{
fpsControl.SwithSideView();
}
if (Input.GetKeyDown(KeyCode.R))
{
fpsControl.Reload();
}
fpsControl.Checking();
}
}
}
And this is revamped code.
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
[RequireComponent(typeof(FPSController))]
public class FPSInputController : NetworkBehaviour
{
private FPSController fpsControl;
void Start()
{
fpsControl = this.GetComponent<FPSController>();
MouseLock.MouseLocked = true;
}
void Update()
{
if (isLocalPlayer && fpsControl != null)
{
fpsControl.MoveCommand(new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")), Input.GetButton("Jump"));
if (Input.GetButton("B"))
{
fpsControl.Sit();
}
if (Input.GetButton("X"))
{
fpsControl.OutVehicle();
}
if (Input.GetButton("StickL"))
{
fpsControl.Boost(1.4f);
}
if (MouseLock.MouseLocked)
{
fpsControl.Aim(new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y")));
fpsControl.Trigger1(Input.GetButton("Fire1"));
fpsControl.Trigger2(Input.GetButtonDown("Fire2"));
}
if (Input.GetButton("X"))
{
fpsControl.Interactive();
}
if (Input.GetButton("StickR"))
{
fpsControl.SwithView();
}
if (Input.GetKeyDown(KeyCode.B))
{
fpsControl.SwithSideView();
}
if (Input.GetButton("X"))
{
fpsControl.Reload();
}
fpsControl.Checking();
}
}
}