// Update is called once per frame void Update() { //start game if (Input.GetKeyDown(KeyCode.Space)) { terrainController.GenerateTerrain(0, 0); terrainController.isGenerated = true; currentChunkCoords = terrainController.terrainArray.GetChunkCoords(Mathf.RoundToInt(myRigidbody2D.position.x), Mathf.RoundToInt(myRigidbody2D.position.y)); hotbarController.ToggleVisible(); GetComponent <SpriteRenderer>().enabled = true; cursorSelection.GetComponent <SpriteRenderer>().enabled = true; startText.GetComponent <Text>().enabled = false; } if (Input.GetKey("escape")) { Application.Quit(); } if (terrainController.isGenerated) { if (Input.GetKeyDown(KeyCode.E)) { inventoryController.ToggleInventory(); inInventory = !inInventory; } //get movement inputs horizontalInputValue = Input.GetAxisRaw("Horizontal"); verticalInputValue = Input.GetAxisRaw("Vertical"); //mouse selection cursorScript.UpdateCursorPosition(); //mouse left click if (Input.GetMouseButtonDown(0) || mouseDown) { if (mouseDown == false) { doContinuousMouseActions = true; OnClick(); } mouseDown = true; if (Input.GetMouseButtonUp(0)) { mouseDown = false; } if (doContinuousMouseActions) { OnClickContinuous(); } } //mouse right click if (Input.GetMouseButtonDown(1) || mouseRightDown) { if (mouseRightDown == false) { OnRightClick(); } mouseRightDown = true; if (Input.GetMouseButtonUp(1)) { mouseRightDown = false; } OnRightClickContinuous(); } float scrollAmount = Input.GetAxis("Mouse ScrollWheel"); if (scrollAmount > 0f) { hotbarController.ScrollSelection(false); } else if (scrollAmount < 0f) { hotbarController.ScrollSelection(true); } } //Check if player has entered different chunk if (myRigidbody2D.velocity != Vector2.zero) { MoveCamera(); Tuple <int, int> nextChunkCoords = terrainController.terrainArray.GetChunkCoords(Mathf.RoundToInt(myRigidbody2D.position.x), Mathf.RoundToInt(myRigidbody2D.position.y)); if (!terrainController.ChunksEqual(nextChunkCoords, currentChunkCoords)) { //update terrain //terrainController.GenerateTerrain(x, y); //Debug.LogFormat("loading some terrain. coords from {0} to {1}", currentChunkCoords, nextChunkCoords); terrainController.GenerateTerrain(nextChunkCoords.Item1, nextChunkCoords.Item2); currentChunkCoords = nextChunkCoords; } } }