public void Spawn(Vector3 trapPos, Vector3 leverPos) { GameStateManager gs = GameObject.Find ("GameState").GetComponent<GameStateManager> (); MapGen mg = GameObject.Find ("TileGenParent").GetComponent<MapGen> (); int layerMask = 1 << LayerMask.NameToLayer ("Default"); RaycastHit2D hit = Physics2D.Raycast (trapPos, Vector2.up, Mathf.Infinity, layerMask); GameObject trap = gs.CreateOverNetworkInstant (trapPrefab, trapPos); SpringJoint2D joint = trap.GetComponent<SpringJoint2D> (); Rigidbody2D trapBody = trap.GetComponent<Rigidbody2D> (); Rigidbody2D colliderRigidbody = hit.collider.gameObject.AddComponent<Rigidbody2D> (); joint.connectedBody = colliderRigidbody; joint.connectedAnchor = joint.connectedBody.transform.InverseTransformPoint (hit.point); colliderRigidbody.constraints = RigidbodyConstraints2D.FreezeAll; GameObject lever = gs.CreateOverNetworkInstant (leverPrefab, leverPos); TrapDeployer deployer = lever.GetComponent<TrapDeployer> (); deployer.droppingTrap = trap; deployer.raisingTrap = trap; MapGen.Room room = mg.GetRandomRoom (); float deltaX = Random.value * mg.roomWidth; float deltaY = Random.value * mg.roomHeight; Vector2 pos = new Vector2 (room.x + deltaX, room.y - deltaY); GameObject enemy = gs.CreateOverNetworkInstant (enemyPrefab, pos); tm = trap.GetComponent<TrapManager> (); tm.AddTarget(enemy, ((manager) => { Debug.Log("Captured enemy"); GameObject.Find("GameState").GetComponent<GameStateManager>().ResetGame(); return true; })); }
public void Spawn(Vector3 trapPos, Vector3 leverPos) { GameStateManager gs = GameObject.Find("GameState").GetComponent <GameStateManager> (); MapGen mg = GameObject.Find("TileGenParent").GetComponent <MapGen> (); int layerMask = 1 << LayerMask.NameToLayer("Default"); RaycastHit2D hit = Physics2D.Raycast(trapPos, Vector2.up, Mathf.Infinity, layerMask); GameObject trap = gs.CreateOverNetworkInstant(trapPrefab, trapPos); SpringJoint2D joint = trap.GetComponent <SpringJoint2D> (); Rigidbody2D trapBody = trap.GetComponent <Rigidbody2D> (); Rigidbody2D colliderRigidbody = hit.collider.gameObject.AddComponent <Rigidbody2D> (); joint.connectedBody = colliderRigidbody; joint.connectedAnchor = joint.connectedBody.transform.InverseTransformPoint(hit.point); colliderRigidbody.constraints = RigidbodyConstraints2D.FreezeAll; GameObject lever = gs.CreateOverNetworkInstant(leverPrefab, leverPos); TrapDeployer deployer = lever.GetComponent <TrapDeployer> (); deployer.droppingTrap = trap; deployer.raisingTrap = trap; MapGen.Room room = mg.GetRandomRoom(); float deltaX = Random.value * mg.roomWidth; float deltaY = Random.value * mg.roomHeight; Vector2 pos = new Vector2(room.x + deltaX, room.y - deltaY); GameObject enemy = gs.CreateOverNetworkInstant(enemyPrefab, pos); tm = trap.GetComponent <TrapManager> (); tm.AddTarget(enemy, ((manager) => { Debug.Log("Captured enemy"); GameObject.Find("GameState").GetComponent <GameStateManager>().ResetGame(); return(true); })); }