- Home /
Question by
aloxbii · Sep 08, 2021 at 01:38 PM ·
vroculusinteractiontoolkit
How to change Action based controller prefab/model with a script during game?
So far I have this and it is changing the fields in the editor but not reflecting that in the game:
public class HandSwitcher : MonoBehaviour
{
private bool isPressed;
private ActionBasedController controller;
[SerializeField] private GameObject sword;
[SerializeField] private GameObject gun;
private void Start()
{
controller = GetComponent<ActionBasedController>();
controller.selectAction.action.performed += Action_performed;
controller.selectAction.action.canceled += Action_canceled;
}
private void Update()
{
if (isPressed)
{
controller.modelPrefab = gun.transform;
controller.model = gun.transform;
}
else
{
controller.modelPrefab = sword.transform;
controller.model = sword.transform;
}
}
private void Action_canceled (InputAction.CallbackContext obj)
{
isPressed = false;
Debug.Log("Grip released");
}
private void Action_performed(InputAction.CallbackContext obj)
{
isPressed = true;
Debug.Log("Grip pressed");
}
}
Comment
Did you find a solution to this problem. I am about to try the same thing.
Your answer
Follow this Question
Related Questions
Unity XR Interaction toolkit socket not working when game is built 1 Answer
XR Interaction Toolkit - Grab Object Persistent 0 Answers
Layers vs Interaction Layers for XR Interaction Toolkit 0 Answers
Unable to add interactions to oculus handtracking in Unity 0 Answers
Oculus Store VRC issue (TestSubmitFramesWhenNotVisible) 1 Answer