void Spawn(type_node_edge inType) { // // locate the initial position outside the screen at random.. // int sideOfOffStage = (int)(Random.Range(0.0f, 3.0f)); Vector2 p = new Vector2(); switch (sideOfOffStage) { case 0: p = new Vector2(-6.0f, 0.0f); break; case 1: p = new Vector2(0.0f, +8.0f); break; case 2: p = new Vector2(+6.0f, 0.0f); break; case 3: p = new Vector2(0.0f, +8.0f); break; } float r = Random.Range(0.0f, 3.0f); float theta = Random.Range(0.0f, 2 * Mathf.PI); Vector2 posOffset = new Vector2(r * Mathf.Cos(theta), r * Mathf.Sin(theta)); Vector2 pos = p + posOffset; // // locate destination position in the screen. // int sideOfScreen = (int)(Random.Range(0.0f, 3.0f)); Vector2 d = new Vector2(); switch (sideOfScreen) { case 0: d = new Vector2(-2.0f, 0.0f); break; case 1: d = new Vector2(0.0f, +4.0f); break; case 2: d = new Vector2(+2.0f, 0.0f); break; case 3: d = new Vector2(0.0f, +4.0f); break; } d = new Vector2(0.0f, 0.0f); float dr = Random.Range(0.0f, 2.0f); float dTheta = Random.Range(0.0f, 2 * Mathf.PI); Vector2 dPosOffset = new Vector2(dr * Mathf.Cos(dTheta), r * Mathf.Sin(dTheta)); Vector2 dPos = d + dPosOffset; Vector2 rPos = dPos - pos; SpawnInfo spawnInfo = new SpawnInfo(); spawnInfo.SetPosition(pos); spawnInfo.SetRPosition(rPos); spawnInfo.SetCurrentPosition(pos); // // spawn nodes. // if (inType == type_node_edge.random) { int typeToGenerate = Random.Range(0, 7); switch (typeToGenerate) { case 0: Spawn1Node0Edge(spawnInfo); break; case 1: Spawn2Node1Edge(spawnInfo); break; case 2: Spawn3Node3Edge(spawnInfo); break; case 3: Spawn3Node2Edge(spawnInfo); break; case 4: Spawn4Node4Edge(spawnInfo); break; case 5: Spawn4Node3Edge(spawnInfo); break; case 6: Spawn4Node5Edge(spawnInfo); break; } } else { switch (inType) { case type_node_edge.type_1node0edge: Spawn1Node0Edge(spawnInfo); break; case type_node_edge.type_2node1edge: Spawn2Node1Edge(spawnInfo); break; case type_node_edge.type_3node3edge: Spawn3Node3Edge(spawnInfo); break; case type_node_edge.type_3node2edge: Spawn3Node2Edge(spawnInfo); break; case type_node_edge.type_4node4edge: Spawn4Node4Edge(spawnInfo); break; case type_node_edge.type_4node3edge: Spawn4Node3Edge(spawnInfo); break; case type_node_edge.type_4node5edge: Spawn4Node5Edge(spawnInfo); break; case type_node_edge.type_4node6edge2occupy: Spawn4Node6Edge2Occupy(spawnInfo); break; case type_node_edge.type_4node4edge2occupy: Spawn4Node4Edge2Occupy(spawnInfo); break; case type_node_edge.type_4node3edge3occupy: Spawn4Node3Edge3Occupy(spawnInfo); break; case type_node_edge.type_4node3edge2occupy: Spawn4Node3Edge2Occupy(spawnInfo); break; case type_node_edge.type_4node3edge2occupy1: Spawn4Node3Edge2Occupy1(spawnInfo); break; case type_node_edge.type_4node3edge2occupy2: Spawn4Node3Edge2Occupy2(spawnInfo); break; case type_node_edge.type_3node2edge2occupy: Spawn3Node2Edge2Occupy(spawnInfo); break; case type_node_edge.type_3node2edge1occupy: Spawn3Node2Edge1Occupy(spawnInfo); break; case type_node_edge.type_3node3edge2occupy: Spawn3Node3Edge2Occupy(spawnInfo); break; case type_node_edge.type_3node3edge1occupy: Spawn3Node3Edge1Occupy(spawnInfo); break; case type_node_edge.type_2node1edge1occupy: Spawn2Node1Edge1Occupy(spawnInfo); break; } } // // spawn Loop Enter object and give initial parameters. // GameObject loopEnter = Instantiate(loopEnterPrefab); LoopEnterComponent loopEnterComponent = loopEnter.GetComponent <LoopEnterComponent>(); LoopComponent lc = loop.GetComponent <LoopComponent>(); loopEnterComponent.SetLoop(lc.GetLoop()); Transform tr = loopEnter.GetComponent <Transform>(); tr.position.Set(pos.x, pos.y, 0); LoopEnterComponent loopEnterComp = loopEnter.GetComponent <LoopEnterComponent>(); loopEnterComp.SetSpawnInfo(spawnInfo); }