public void HoldBox(BotBox box) { heldBox = box; heldBox.transform.parent = heldBoxLocation.transform; heldBox.transform.position = heldBoxLocation.transform.position; heldBox.transform.rotation = heldBoxLocation.transform.rotation; }
public void GenerateArena() { float startX = transform.position.x - ((cellsX - 1) * cellSpacing * 0.5f); float startZ = transform.position.z - ((cellsZ - 1) * cellSpacing * 0.5f); bool[,] hasObj = new bool[cellsX, cellsZ]; // Place bots for (int i = 0; i < botsCount; i++) { // Find open space Vector2Int cellPos = GetNextEmpty(hasObj); hasObj[cellPos.x, cellPos.y] = true; // Translate open space location into world space float xPos = startX + (cellPos.x * cellSpacing); float zPos = startZ + (cellPos.y * cellSpacing); // Instantiate and place object SortBot newBot = GameObject.Instantiate <SortBot>(botPrefab, transform); newBot.transform.position = new Vector3(xPos, 0, zPos); newBot.transform.Rotate(new Vector3(0, Random.Range(0, 360), 0)); } // Place boxes for (int i = 0; i < boxesCount; i++) { // Find open space Vector2Int cellPos = GetNextEmpty(hasObj); hasObj[cellPos.x, cellPos.y] = true; // Translate open space location into world space float xPos = startX + (cellPos.x * cellSpacing); float zPos = startZ + (cellPos.y * cellSpacing); // Instantiate and place object BotBox boxPrefab = boxPrefabs[Random.Range(0, boxPrefabs.Count)]; BotBox newBox = GameObject.Instantiate <BotBox>(boxPrefab, transform); newBox.transform.position = new Vector3(xPos, 0.25f, zPos); } ScaleArena(); }
private void BumpCollider(Collider theCol) { // Apply turning around isTurningAround = true; turnNegative = Random.Range(0, 2) == 0; amountToTurn = Random.Range(180 - turnaroundVariance, 180 + turnaroundVariance); // Pick up or set down box BotBox asBox = (BotBox)theCol.gameObject.GetComponent <BotBox>(); if (asBox != null) { if (heldBox == null) { HoldBox(asBox); } else if (asBox.boxType == heldBox.boxType) { PlaceBox(); } } }
public void PlaceBox() { heldBox.transform.parent = null; heldBox.transform.position = placeBoxLocation.transform.position; heldBox = null; }