public void AttempCoupling() { Vector2 direction = PhysicsU.Dir2Vec(dir); RaycastHit2D hit = Physics2D.Raycast(transform.position, PhysicsU.Dir2Vec(dir), 0.2f, layerMask.value); if (!hit) { return; } if (hit.collider.gameObject == gameObject) { return; } GameObject Anchor = hit.collider.gameObject; Anchor_script anchor_script = Anchor.GetComponent <Anchor_script>(); //check if Raycast hit foreign organism if (anchor_script.cell.GetComponent <Cell_script>().GetOrganism() != cell.GetComponent <Cell_script>().GetOrganism()) { return; } Couple(Anchor); }
public void Uncouple() { if (coupled == null) { return; } Anchor_script anchor_script = coupled.GetComponent <Anchor_script>(); fixedJoint2D.connectedBody = null; coupled = null; anchor_script.Uncouple(); }
public void Couple(GameObject Anchor) { if (coupled != null) { return; } Anchor_script anchor_script = Anchor.GetComponent <Anchor_script>(); coupled = Anchor; if (fixedJoint2D == null) { CreateJoint(); } fixedJoint2D.connectedBody = anchor_script.cell.GetComponent <Rigidbody2D>(); anchor_script.Couple(gameObject); }
private GameObject GetAnchorCouple(GameObject Anchor) { Anchor_script Anchor_script = Anchor.GetComponent <Anchor_script>(); return(Anchor_script.GetCoupledCell()); }