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
0
Question by KBCreater · Jun 14, 2017 at 03:24 AM · gridgrid based gamestates

How to make certain tiles a certain state

I am trying to make a grid system and I finally found a grid generator using tiles. But, my next step is to make a system that creates allows me to create boundaries between the different "counties". I thought maybe I could define each individual tile and then define the tile to wich county it belonged to (for starters neutral, red blue, green, yellow). Since I am a noob at C# I need help integrating this into what I believe is the correct place to put it in.

So far my code is as fallows

 using UnityEngine;
 using System.Collections;
 
 public class mapGenerator : MonoBehaviour {
 
     public Transform tilePrefab;
     public Vector2 mapSize;
 
     [Range(0,1)]
     public float outlinePercent;
 
     void Start() {
         genMap ();
     }
 
     public void genMap(){
 
         string holderName = "Generated map";
         if (transform.FindChild (holderName)) {
             DestroyImmediate (transform.FindChild (holderName).gameObject);
         }
 
         Transform mapHolder = new GameObject (holderName).transform;
         mapHolder.parent = transform;
 
         for (int x = 0; x < mapSize.x; x++) {
             for (int y = 0; y < mapSize.y; y++) {
                 Vector3 tilePos = new Vector3 (-mapSize.x / 2 + 0.5f + x, 0, -mapSize.y/2 + 0.5f + y);
                 Transform newTile = Instantiate (tilePrefab, tilePos, Quaternion.Euler(Vector3.right*90)) as Transform;
                 newTile.localScale = Vector3.one * (1 - outlinePercent);
                 newTile.parent = mapHolder;
             }
         }
 
     }
 }
 
Comment
Add comment · Show 2
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
avatar image NoseKills · Jun 14, 2017 at 06:08 AM 0
Share

You should probably make a Tile script that you add to your tile prefab. $$anonymous$$ake tilePrefab to be of type Tile ins$$anonymous$$d of Transform and whatever info you need each tile to have, add a variable for it in the Tile class.

avatar image KBCreater NoseKills · Jun 14, 2017 at 01:21 PM 0
Share

What do you mean @Nose$$anonymous$$ills How would I do that exactly. Im quite noobish and the only thing that made sense and actually worked was making the tile script. And to clear this up. That script generates a 100x100 tile area and I would need to make a way to create the borders and also have them change throughout time.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by NoseKills · Jun 14, 2017 at 04:21 PM

Create a tile class

 public class Tile : MonoBehaviour {
     public bool Walkable;
     public bool IsCountyBorder;
     public int SomeInt;
 }

Drag that script onto your tile prefab. Then change the type of your prefab variable

 public Transform tilePrefab;

to

 public Tile tilePrefab;

Then drag the prefab to the tilePrefab field again in inspector. Now you can get a reference to the Tile script of the tile every time you instantiate one

 Tile newTile = Instantiate (tilePrefab, tilePos, Quaternion.Euler(Vector3.right*90)) as Tile;
 newTile.IsCountyBorder = true;

I would imagine you want to put the created tiles into an array so you can reference them later and for example easily check which tile some actor in your game is on. Also you probably need a way to determine the locations of county tiles etc beforehand so you can create the tilemap based on that data.

There's many things here that i think you could learn more easily by following some grid based game tutorial. Or a tutorial for a graphically tile based game, depending on what tou actually want from the tile-basedness. Otherwise you might have to ask about 50 more questions to get things going.

Comment
Add comment · Show 2 · Share
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
avatar image KBCreater · Jun 14, 2017 at 07:38 PM 0
Share

I think I have found another way to do it. Thanks anyway @Nose$$anonymous$$ills I will check out the tutorials though. Also The tiles would change owner... from one player to another based on if it is captured. Any ideas if you got them but I am pretty sure I got this one covered... I think.

avatar image NoseKills KBCreater · Jun 14, 2017 at 07:49 PM 0
Share

Nothing special there. Just add

 public int ownerId:

to your tiles... int or whatever type you want to use to store the tile owner as.

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

108 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

Related Questions

I am very new to coding and was wondering how I would be able to turn this square grid script into a rectangle grid. 0 Answers

0.32 by 0.32 2D grid in Unity using Mathf.Round? 0 Answers

How can I pre-generate a grid instead of generating it on each runtime? 1 Answer

Is ther a way to base movement translation through the grid map of the tilemap? 1 Answer

Grid territory system 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