0

I am working on object manipulation and I am trying to apply constraint manager at run time by script,

In this, I want to select manual constraint and add rotation axis constraint by script if anyone know how to do it If so please help me.

1 Answers1

0

You need to refer to ConstraintManager Class (Microsoft.MixedReality.Toolkit.UI) | Microsoft Docs to understand this component, then you can refer to the example below.

using UnityEngine;
using Microsoft.MixedReality.Toolkit.UI;
using Microsoft.MixedReality.Toolkit.Utilities;

public class ConstraintTest : MonoBehaviour
{
    void Start()
    {
        RotationAxisConstraint rotationConstraint = this.gameObject.AddComponent<RotationAxisConstraint>();
        rotationConstraint.ConstraintOnRotation = AxisFlags.YAxis;

        ConstraintManager manager = GetComponent<ConstraintManager>();
        manager.AutoConstraintSelection = false;
        manager.AddConstraintToManualSelection(rotationConstraint);
    }
}