void Awake() { if (detached == null) { detached = gameObject.GetComponent <CtrlDrag> (); } if (attached == null) { attached = gameObject.GetComponent <Module> (); } if (rb == null) { rb = gameObject.GetComponent <Rigidbody2D> (); } if (type == null) { type = gameObject.GetComponent <ItemType> (); } if (attachedCollider == null) { attachedCollider = gameObject.GetComponent <Collider2D> (); } attached.edges = edges; attached.main = this; attached.containingCollider = attachedCollider; attached.attachable = type.IsAttachable(); }
public void ReleasePickup(OldModule first) { //GameObject newPickup = Instantiate (pickup); CtrlDrag script = pickup.GetComponent <CtrlDrag> (); pickup.transform.position = parentObject.transform.TransformPoint(new Vector3(gridLocation [0], gridLocation [1], 0)); pickup.transform.localEulerAngles = new Vector3(0, 0, parentObject.transform.eulerAngles.z + gridRotation * 90 - 90); pickup.SetActive(true); if (first == this) { script.PickUp(); } else { float force = Mathf.Sqrt(Vector2.SqrMagnitude((gridLocation - first.gridLocation) * 20)); float angle = Conversion.DegToRad(pickup.transform.localEulerAngles.z + 90); pickup.GetComponent <Rigidbody2D> ().AddForce(new Vector2(Mathf.Cos(angle), Mathf.Sin(angle) * -1) * force); } }