Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
1
Question by Caerex · Mar 10, 2016 at 03:51 PM · c#generationwall

How to generate the Top and Right border for my game's arena?

Hello, I am relatively new to C# and Unity as a whole and am making a game involving randomly generated boards of different sizes. However when I generate the board the Left and Bottom edge generate fine whereas the Top and Right do not generate at all.

I believe the error is located in this line:

 if ( x == -2.23f || x == (columns * 2.23f) ||y == -2.23f || y == (rows * 2.23f))

I am using this Unity tutorial as a guideline.

Here is the full code:

 using UnityEngine;
 using System.Collections;
 using System;
 using System.Collections.Generic;
 using Random = UnityEngine.Random;
 
 public class BoardManager : MonoBehaviour {
 
     [Serializable]
     public class Count
     {
         public int minimum;
         public int maximum;
 
         public Count (int min, int max)
         {
             minimum = min;
             maximum = max;
 
         }
     }
     //Number of Columns on board
     public int columns = 5;
     //Number off Rows on board
     public int rows = 4;
     //Number of inner walls to be made between (x, y)
     public Count wallCount = new Count(9,11); 
 
     public GameObject[] floorTiles;
     public GameObject[] innerWallTiles;
     public GameObject[] outerWallTiles; 
 
     private Transform boardHolder;
     private List<Vector3> gridPositions = new List<Vector3>();
 
 
 
     //2.23 is the size of each tile
     void InitialiseList()
     {
         //Empties previous grid positions
         gridPositions.Clear();
         //For each Column.....
         for (float x = 2.23f; x < (columns*2.23f) -2.23f; x+=2.23f) {
             //...Do each Row....
             for (float y = 2.23f; y < (rows*2.23f) -2.23f; y+=2.23f) {
                 //... To create a List of possible positions for each tile
                 gridPositions.Add(new Vector3(x, y, 0f)); 
 
             }
         }
 
     }
     //Creates "Canvas" with outer wall and background of floor
     void BoardSetUp() 
     {
         boardHolder = new GameObject("Board").transform;
         //Goes to columns +-2.23 is to create edge
         for (float x = -2.23f; x <(columns*2.23f) + 2.23f; x+=2.23f){
             //Goes to rows +-2.23 to create edge
             for (float y = -2.23f; y <( rows*2.23f) + 2.23f; y+=2.23f){
                 //Randomly chooses a Floor tile design (Allows more to be added later due to length not being specified)
                 GameObject toInstantiate = floorTiles[Random.Range(0, floorTiles.Length)];
                 //Checks whether it is the games border
                 if ( x == -2.23f || x == (columns * 2.23f) ||y == -2.23f || y == (rows * 2.23f))
                 {
                     //Picks a random outer wall tile to instantiate
                     toInstantiate = outerWallTiles[Random.Range(0, outerWallTiles.Length)]; 
                 }
                 //Creates tile at correct coordinates (x,y,0) with no rotation (quaternion) as a new gameobject
                 GameObject instance = Instantiate(toInstantiate, new Vector3(x, y, 0f), Quaternion.identity) as GameObject;
                 //Sets parent as board Holder for easy management
                 instance.transform.SetParent(boardHolder); 
             }
         }
     }
 
     Vector3 RandomPosition()
     {
         //Selects random positions
         int randomIndex = Random.Range(0, gridPositions.Count); 
         Vector3 randomPosition = gridPositions[randomIndex];
         //Removes the Position
         gridPositions.RemoveAt(randomIndex);
         //Returns the value random position
         return randomPosition; 
 
     }
 
     void LayoutObjectAtRandom (GameObject[] tileArray, int minimum, int maximum)
     {
         //Controls how many of an object spawn
         int objectCount = Random.Range(minimum, maximum + 1);
         //For the number in objectCount.....
         for (int i=0; i < objectCount; i++) 
         {
             Vector3 randomPosition = RandomPosition();
             //Picks a Tile
             GameObject tileChoice = tileArray[Random.Range(0, tileArray.Length)];
             //Creates The tile
 
             Instantiate(tileChoice, randomPosition, Quaternion.identity); 
         }
     }
     //Public so can be accessed outside of file by GameManager script
     public void SetupScene() 
     {
         BoardSetUp();
         InitialiseList();
         //Lays out the tiles
         LayoutObjectAtRandom(innerWallTiles, wallCount.minimum,wallCount.maximum); 
     }
 }

Thank you for helping me.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

131 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Procedural Cave Generation Can´t understand?? 0 Answers

Can you use the superformula in unity? 0 Answers

C# Unity - Roguelike room generation HELP 1 Answer

How to add programatically animationClips to one animation from Resources folder? 0 Answers

Understanding Procedural Level Generation A LA Alto's Adventure 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges