I am trying to make a small 2D proof of concept where the player can enter and exit different vehicles with different move scripts. I am trying to use the new input system so I can test functionality with a gamepad.
When I play test in the editor I can use the gamepad & keyboard to move the player. When I enter the vehicle I can use the gamepad & keyboard to move the vehicle. But as soon as I exit the vehicle the vehicle retains the gamepad scheme and the player is left with only the keyboard. I suspect it is treating the vehicle as player 1.
If the player exits the vehicle, I disable the vehicle in the inspector, then refresh (disable and reenable) the player I can move with the gamepad again.
Vehicle
private void Awake()
{
controls = new PlayerControls();
controls.Disable();
}
#region OnEnable
private void OnEnable()
{
controls.Enable();
}
#endregion
#region OnDisable
private void OnDisable()
{
controls.Disable();
}
#endregion
public override void Interaction()
{
if (playerInside)
{
player.transform.parent = null;
controls.Disable();
Debug.Log("VehicleControls Disabled");
player.SetActive(true);
playerInside = false;
Debug.Log("Player Not Inside");
collide.isTrigger = true;
rb.Sleep();
rb.bodyType = RigidbodyType2D.Kinematic;
}
else if (playerFound && !playerInside)
{
player.transform.parent = vehicleCenter.transform;
player.transform.localPosition = Vector2.zero;
player.SetActive(false);
playerInside = true;
controls.Enable();
Debug.Log("VehicleControls Enabled");
player.GetComponent<PlayerController>().canDash = true;
Debug.Log("Player Inside");
collide.isTrigger = false;
rb.WakeUp();
rb.bodyType = RigidbodyType2D.Dynamic;
rb.gravityScale = vehicleGravityScale;
}
Debug.Log("Interaction triggered");
}
Player
#region Find Controls
private void Awake()
{
controls = new PlayerControls();
Debug.Log("Player Controls Searched for " + this.name);
}
private void OnEnable()
{
controls.Enable();
Debug.Log("PlayerControls Enabled");
}
private void OnDisable()
{
controls.Disable();
Debug.Log("PlayerControls Disabled");
}
#endregion