Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
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.

Follow this Question

Answers Answers and Comments

184 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

Related Questions

2D Tilemap stretching 2 Answers

Confused about ITilemap interface and concrete tilemap classes 0 Answers

2D tilemaps - separation of view and data, prototyping doubts 0 Answers

2D Tiles and sprites 1 Answer

How to assign individual data to a tiles? (Unity3D Tilemap) 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