private void placeShip() { float outOfViewRange = 3f; float x = this.dropLocation.x; float y = this.dropLocation.y; CameraMeasurements camera = new CameraMeasurements(); float xb1 = camera.getHorizontalMax() + outOfViewRange; float xb2 = camera.getHorizontalMin() - outOfViewRange; float yb1 = camera.getVerticalMax() + outOfViewRange; float yb2 = camera.getVerticalMin() - outOfViewRange; Vector2[] possiblePositions = { new Vector2(x, yb1), new Vector2(x, yb2), new Vector2(xb1, y), new Vector2(xb2, y) }; this.startLocation = possiblePositions[Random.Range(0, 3)]; Debug.Log("startLocation: x=" + startLocation.x + " y=" + startLocation.y); float rotation; if (this.startLocation.x == xb1) { rotation = 90; } else if (this.startLocation.x == xb2) { rotation = 270; } else if (this.startLocation.y == yb1) { rotation = 180; } else { rotation = 0; } this.ship = (GameObject)Instantiate(this.ship, this.startLocation, Quaternion.Euler(0, 0, rotation)); if (!GlobalVariables.local) { NetworkServer.Spawn(ship); } this.ship.name = "Support_Ship"; SupportShipAction action = this.ship.GetComponent <SupportShipAction>(); action.startPosition = this.startLocation; action.dropPosition = this.dropLocation; }
// Start is called before the first frame update void Start() { if (GlobalVariables.local) { enabled = false; } else { supAction = gameObject.GetComponent <SupportShipAction>(); } }