Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 jvt619 · Apr 03, 2015 at 04:26 PM · guiraycastmap

Knowing the position of the next GUI Image

alt text

This is sort of a map and is on the uGUI system.

How can I make the Blue pointer knows that there is a circle on the right when I want to move to the right or knows when there is no circle downwards on the current circle where the Blue pointer is currently pointing?

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
1
Best Answer

Answer by DoTA_KAMIKADzE · Apr 03, 2015 at 05:39 PM

If you don't want to manage it yourself then consider adding all "circle" UI images to a single List and then just iterate through whole list and check ~like that:

     Image nextImage = null;
     Vector3 currImgPos = currImg.transform.position;
     //for going right:
     foreach (Image img in mylist)
     {
         Vector3 iteratedImgPos = img.transform.position;
         if (iteratedImgPos.y == currImgPos.y) //or allow some variation +/-
         {
             if (iteratedImgPos.x > currImgPos.x) //check if there is any circle on the right
             {
                 if (nextImage == null || iteratedImgPos.x < nextImage.transform.position.x) // check if any circle was already found to the right, if was check if that circle is closer
                 nextImage = img; //if not closer then next circle should be this one
             }
         }
     }
     if (nextImage != null) //if there is next circle to the right
     {
         //do whatever you like
     }
     else //if not
     {
         //do something else
     }
     //where currImg is your "current circle" and mylist is a collection of all available "circles"

Do pretty much the same for left, but instead you should check if next X position is lower. Same will do for Up/Down but instead you should check for equal X and higher/lower Y.

Though it will be better for performance to manage it yourself, for example it can be X:Y Map like multidimensional Array:

 bool[,] moveArray = new bool[10, 10];

Where True value represent a circle and false nothing, then if you want to move right you just check like this:

         if (moveArray[currXvalue + 1, currYvalue])
         {
             //i can move
         }
         else
         {
             //i can't move
         }

Else it can be managed with Tags which you can manually add to images, and so on.

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 jvt619 · Apr 04, 2015 at 05:54 AM 0
Share

Should I instantiate the 'circles' and make the dimensional array in a text file or is there a way to know the dimensional array based on the picture?

avatar image DoTA_KAMIKADzE · Apr 04, 2015 at 10:38 AM 0
Share

That is yet again your choice.

For example if you want to fetch from "screen" you can on Awake() collect all "Circles" in some sort of

 Dictionary<Vector2,Image>

that represents X:Y of circle as a Vector2 $$anonymous$$ey and the circle itself as a value and then on any single Start() function map from those Vector2 values a multidimensional array map.

And example if you'd like to mange yourself - yet again you can create a

 Dictionary<Vector2,Image>

but this time Vector2 will represent the multidimensional array X:Y position ins$$anonymous$$d of circles real position and in order to fetch their real position you will do so from the Image value.

Remember that those are only examples and there are many more ways to do the same thing. The more "circles" you have and the more complex their layout is the more advantageous for performance would be to go down the "manage myself" road, though you may end up consu$$anonymous$$g more RA$$anonymous$$ in the end, and yet again - you got the point :D

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

20 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

Related Questions

Making raycasts go to the centre of the screen 1 Answer

Vertical distance indication 1 Answer

How to activate a button? 1 Answer

How to disable a part of a script to avoid replayed camera animations ? 0 Answers

Making a GUI image appear when hovering over a RigidBody Object 1 Answer


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