예제 #1
0
    void SetRopeSettings()
    {
        playerHingeJoint = GameObject.FindGameObjectWithTag("Player").GetComponent <HingeJoint2D>();
        GameObject newRope = new GameObject();

        newRope.AddComponent <Rope>();

        Rope ropeComponent = newRope.GetComponent <Rope>();

        ropeComponent.transform.position           = new Vector2(22.0f, 3.45f);
        ropeComponent.transform.rotation           = Quaternion.Euler(0.0f, 0.0f, -70.0f);
        ropeComponent.SegmentsPrefabs              = new SpriteRenderer[1];
        ropeComponent.SegmentsPrefabs[0]           = segmentPrefab;
        ropeComponent.HangFirstSegment             = true;
        ropeComponent.useBendLimit                 = false;
        ropeComponent.overlapFactor                = -0.17f;
        ropeComponent.WithPhysics                  = true;
        ropeComponent.FirstSegmentConnectionAnchor = new Vector2(-3.0f, 0.0f);

        ropeComponent.useBendLimit = true;
        ropeComponent.bendLimit    = 90;

        UpdateRope(ropeComponent);

        //set drag to every of the segments
        Component[] rbComponentsInChildren;

        rbComponentsInChildren = ropeComponent.GetComponentsInChildren <Rigidbody2D>();
        int numberOfSegments = rbComponentsInChildren.Length;

        foreach (Rigidbody2D rb in rbComponentsInChildren)
        {
            rb.drag        = 0.2f;
            rb.angularDrag = 0.6f;
        }
    }