예제 #1
0
    void CreateFixedJoint()
    {
        var rigidbody = TargetObject.GetOrAddComponent <Rigidbody>();
        var joint     = TargetObject.GetOrAddComponent <FixedJoint>();

        rigidbody.mass                   = 1;
        rigidbody.drag                   = 0;
        rigidbody.angularDrag            = 0;
        rigidbody.useGravity             = false;
        rigidbody.isKinematic            = false;
        rigidbody.interpolation          = RigidbodyInterpolation.None;
        rigidbody.collisionDetectionMode = CollisionDetectionMode.Discrete;
        rigidbody.constraints            = RigidbodyConstraints.None;

        joint.connectedBody       = null;
        joint.breakForce          = float.PositiveInfinity;
        joint.breakTorque         = float.PositiveInfinity;
        joint.enableCollision     = false;
        joint.enablePreprocessing = true;

        var    animation = _containerOff.GetComponent <Animation>().clip;
        string path      = AnimationUtility.CalculateTransformPath(
            TargetObject.transform,
            _containerOff.transform);

        animation.SetCurve(
            path,
            typeof(Transform),
            "localPosition.x",
            AnimationCurve.Linear(0, 0, frame, 0));

        animation.SetCurve(
            path,
            typeof(Transform),
            "localPosition.y",
            AnimationCurve.Linear(0, 0, frame, 0));

        animation.SetCurve(
            path,
            typeof(Transform),
            "localPosition.z",
            AnimationCurve.Linear(0, 0, frame, 0));
    }