Hello, I’m trying to implement a simple UI that allows users to select their preferred locomotion and turn type. I’m running into an issue where the logic seems to only work when switching from Continuous Move to Teleport. If I try to switch back to Continuous Move it does not work. The same is happening when switching from Continuous Turn to Snap Turn.
Worth noting that Continuous Move and Continuous Turn are both the default values (enabled by default when scene starts), so changing from default setting to another setting works, but reverting to the original setting does not.
I’m using 2 scripts for this, they are attached to the UI menu and the functions to SetActiveFromIndex are called from the respective dropdowns. My scripts attached below… any insights on what I’m doing wrong here?
Movement Script:
public class SetActiveMovementFromDropdown : MonoBehaviour
{
[SerializeField] DynamicMoveProvider continuousMove;
[SerializeField] TeleportationProvider teleport;
[SerializeField] GameObject leftTeleport;
[SerializeField] GameObject rightTeleport;
[SerializeField] CharacterControllerDriver driver;
public void SetActiveFromIndex(int index)
{
if (index == 0)
{
DisableTeleportation();
EnableContinousMovement();
}
else if (index == 1)
{
DisableContinuousMovement();
EnableTeleportation();
}
}
private void DisableTeleportation()
{
leftTeleport.SetActive(false);
rightTeleport.SetActive(false);
teleport.enabled = false;
}
private void EnableTeleportation()
{
leftTeleport.SetActive(true);
rightTeleport.SetActive(true);
teleport.enabled = true;
driver.locomotionProvider = teleport;
}
private void DisableContinuousMovement()
{
continuousMove.enabled = false;
}
private void EnableContinousMovement()
{
continuousMove.enabled = true;
driver.locomotionProvider = continuousMove;
}
}
Turn Script:
public class SetActiveTurnFromDropdown : MonoBehaviour
{
[SerializeField] ActionBasedContinuousTurnProvider continuousTurn;
[SerializeField] ActionBasedSnapTurnProvider snapTurn;
public void SetActiveFromIndex(int index)
{
if(index == 0)
{
DisableSnapTurn();
EnableContinuousTurn();
}
else if(index == 1)
{
DisableContinuousTurn();
EnableSnapTurn();
}
}
private void DisableSnapTurn()
{
snapTurn.enabled = false;
}
private void EnableSnapTurn()
{
snapTurn.enabled = true;
}
private void DisableContinuousTurn()
{
continuousTurn.enabled = false;
}
private void EnableContinuousTurn()
{
continuousTurn.enabled = true;
}
}