Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 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 /
  • Help Room /
This question was closed Jul 25, 2017 at 09:18 PM by GnomenxD for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by GnomenxD · May 05, 2016 at 03:36 PM · gridvector2coordinates

Getting World Space From Custom Grid

Hello everyone.

Thank you for taking the time to look through and possibly answer this question. So I have created a pretty easy custom grid that have weird coordinates, using this code:

     public Vector2 GridToWorldSpace(int x, int y)
     {
         Vector2 vector = Vector2.zero;
         if (x == y)
         {
             vector = new Vector2(0, y * 0.64f);
         }
         else if (x < y)
         {
             vector = new Vector2((y - x) * -0.64f, (y + x) * 0.32f);
         }
         else if(x > y)
         {
             vector = new Vector2((x - y) *    0.64f, (x + y) * 0.32f);
         }
         return vector;
     }

What I'm seeking help to do is making some kind of function that returns the grid object, when you press on it with the mouse. I believe that it's quite simple, and I'm just too blind to realise it.

Here example of how it gets to look when it runs. Each terrain block is scaled down to make it easier to see where they split. alt text

Thank you in advance and regards.

5db2f83c74b0d6b9a6ec3692ac100e63.png (185.3 kB)
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

  • Sort: 
avatar image
0
Best Answer

Answer by Glurth · May 05, 2016 at 03:44 PM

There are a few way to do this:

1-Take the mouse input screen coordinate and compute the position of that point of your plane (projection), then loop through all you blocks to see which one occupies that point. (looks like this is the method your trying to use now- I'm not going to be much help with this option. Tough I DO see you do NOT take a change in camera position/angle into account.)

2-A variant of this method is to assign trigger collider component to your tiles, and use RayCast to detect which object is clicked on. (http://docs.unity3d.com/Manual/CameraRays.html)

3-The best (IMHO) way to do this allow each block to respond to a click event. This might be a bit trickier to figure out, because you'll need to learn how to implement IPointerDownHandler and IPointerUpHadler interfaces. (http://docs.unity3d.com/ScriptReference/EventSystems.IPointerDownHandler.html)

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 GnomenxD · May 05, 2016 at 09:29 PM 0
Share

Thank you for your response, in the start I tried to go for the first option. But because this has to be a quick proof of concept, I've gone easy way and used RayCast.

$$anonymous$$ight should have mentioned it were in a 2D space as well, but it works now, thanks :) Regards

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Creating a Grid using an Array with C# 1 Answer

Get vector2 coordinate from one object to another 0 Answers

finding mouse click coordinates 1 Answer

gameobject.transform.position not working correctly, 0 Answers

Keeping track of a bunch of objects in a 3D grid 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