public override void Attach(DirectionalArrow arrow, Transform arrowTransform, Jonko joint)
    {
        playField = FindObjectOfType <PlayField>().gameObject;
        GameObject newStick         = Instantiate(Resources.Load("Stick", typeof(GameObject)) as GameObject, playField.transform);
        float      halfObjectLength = newStick.GetComponent <AttachToStick>().stick.GetComponent <MeshRenderer>().bounds.extents.y;

        newStick.transform.rotation = arrowTransform.rotation;
        Vector3 normalizedDir = (arrowTransform.position - transform.position).normalized;
        Vector3 dir1or0       = new Vector3(Mathf.RoundToInt(normalizedDir.x), Mathf.RoundToInt(normalizedDir.y), 0);

        newStick.transform.position = anchor.transform.position + (dir1or0 * jointOffset);
        if (joint != null)
        {
            HingeJoint newHingeJoint = joint.gameObject.AddComponent <HingeJoint>();
            newHingeJoint.connectedBody = newStick.GetComponent <Rigidbody>();
        }
        else
        {
            if (anchor.GetComponent <FixedJoint>())
            {
                anchor.GetComponent <FixedJoint>().connectedBody   = newStick.GetComponentInChildren <Rigidbody>();
                anchor.GetComponent <FixedJoint>().connectedAnchor = new Vector3(0, 2, 0);
            }
            else if (anchor.GetComponent <HingeJoint>())
            {
                anchor.GetComponent <HingeJoint>().connectedBody   = newStick.GetComponentInChildren <Rigidbody>();
                anchor.GetComponent <HingeJoint>().connectedAnchor = new Vector3(0, 2, 0);
            }
        }
        base.Attach(arrow, arrowTransform, joint);
    }
Example #2
0
    public override void Attach(DirectionalArrow arrow, Transform arrowTransform, Jonko joint)
    {
        playField = FindObjectOfType <PlayField>().gameObject;
        GameObject newStick = Instantiate(Resources.Load("JointAndStick", typeof(GameObject)) as GameObject, playField.transform);

        newStick.transform.rotation = arrow.gameObject.transform.rotation;
        Vector3 normalizedDir = (arrowTransform.position - transform.position).normalized;
        Vector3 dir1or0       = new Vector3(Mathf.RoundToInt(normalizedDir.x), Mathf.RoundToInt(normalizedDir.y), 0);

        newStick.transform.position = stick.transform.position + (dir1or0 * jointOffset);

        stick.AddFixedJoint();
        stick.ConnectRigidBody(newStick.transform.Find("HingeJoint").GetComponent <Rigidbody>());
        base.Attach(arrow, arrowTransform, joint);
        createEndItem.visible = false;
        createEndItem.ApplyVisibility();
    }
Example #3
0
 public virtual void Attach(DirectionalArrow arrow, Transform arrowTransform, Jonko joint)
 {
     arrow.visible = false;
     arrow.ApplyVisibility();
 }
Example #4
0
 public void ToggleJoint()
 {
     Instantiate(jointPrefab, transform.position + (transform.position - attachedToStick.transform.position).normalized * jointOffset, transform.rotation);
     Jonko connectionJoint = jointPrefab.GetComponent <Jonko>();
 }
Example #5
0
 public void RemoveConnectionJoint(Jonko connectionJoint)
 {
     Joints.Remove(connectionJoint);
     //CheckConnectionJointRequirementMet();
     CheckAllRequirements();
 }
Example #6
0
 public void AddConnectionJoint(Jonko connectionJoint)
 {
     Joints.Add(connectionJoint);
     //CheckConnectionJointRequirementMet();
     CheckAllRequirements();
 }