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(); }
public override void OnClick() { GameObject newEndItem = Instantiate(endItemPrefab.gameObject, playField.transform); newEndItem.transform.rotation = stick.transform.rotation; newEndItem.transform.position = stick.transform.position + new Vector3(0, stick.GetComponent <MeshRenderer>().bounds.extents.y, transform.position.z); newEndItem.transform.rotation = transform.rotation; Vector3 normalizedDir = (transform.position - stick.transform.position).normalized; Vector3 dir1or0 = new Vector3(Mathf.RoundToInt(normalizedDir.x), Mathf.RoundToInt(normalizedDir.y), 0); newEndItem.transform.position = stick.transform.position + (dir1or0 * jointOffset); stick.AddFixedJoint(); stick.ConnectRigidBody(newEndItem.GetComponent <Rigidbody>()); newEndItem.GetComponent <EndItem>().attachedToStick = stick.GetComponent <Rigidbody>(); arrows.SetActive(false); newEndItem.GetComponent <EndItem>().arrows = arrows; }