• 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 /
avatar image
0
Question by Neoletum · Nov 24, 2017 at 08:48 PM · 2dscripting problemtilemaptilehealth

Tilemap2017 Access position & sprite of specific Tile in new Grid System 2dGame

Hey everyone! I try to access the Vector3 of a specific Tile in the Tilemap2017, maybe anyone can help me? I drew a map and I wanted to store each position of each Tile in a dictionary or list so the player can change a specific tile ingame for a ingame building mode. And I also could save the map ingame if any changes happen.

So, how can I access the position of a specific tile in a grid/tilemap and store into a List/Dictionary?

I hope someone can help me

@aldonaletto I hope a bit you can help me with your great knowledge :]

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Cherno · Nov 24, 2017 at 10:03 PM

Instead of Vector3, use a custom class that is similar but doesn't involve expensive and postentially inaccurate floating point operations. I wrote one that uses integers instead of floating point numbers:

 using UnityEngine;
 using System.Collections;
 using System;
 
 [System.Serializable]
 public struct Coordinate3 : IEquatable<Coordinate3> {
     public int x;
     public int y;
     public int z;
 
     
     public Coordinate3() {
         x = 0;
         y = 0;
         z = 0;
     }
     
 
     public Coordinate3(int a, int b, int c) {
         x = a;
         y = b;
         z = c;
     }
 
     public Coordinate3(Vector3 v3) {
         x = Mathf.RoundToInt(v3.x);
         y = Mathf.RoundToInt(v3.y);
         z = Mathf.RoundToInt(v3.z);
     }
 
     public bool Equals(Coordinate3 other) {
 
         if (this.x == other.x && this.y == other.y && this.z == other.z) {
             return true;
         }
         else {
             return false;
         }
     }
 
     public override int GetHashCode() {
         return x.GetHashCode() ^ y.GetHashCode() ^ z.GetHashCode();
     }
 
 }
 
 

Your dictionary would looke like this, assuming that you have a class called Tile:

 public Dictionary<Coordinate3,Tile> tiles = new Dictionary<Coordinate3,Tile>();
 
 tiles.Add(new Coordinate3(2,65,7), new Tile());
Comment
Add comment · Show 1 · 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 Neoletum · Nov 25, 2017 at 12:47 PM 0
Share

Hey, thank you for your hint, I will consider it but I'm still confused how to access a single Tile in the new Unity Tilemap-System, normally I create my 2d-$$anonymous$$aps by using loops and add each tile to the next, so I would the position just by looking at the number of the loop but now I just paint the Tile on the map and as a Rookie I don't have any idea how to access it ^^

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

185 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 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

2D Tilemap stretching 2 Answers

How to assign individual data to a tiles? (Unity3D Tilemap) 0 Answers

Object Squeezing Between Tiles 0 Answers

Help with scriptable tiles PLEASE HELP URGENT!!! 1 Answer

2D/Orthographic Tile Alignment Issue 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges