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 dovedevic · Dec 14, 2013 at 05:03 AM · key pressed

Highlight one cell on a GridObject (prefab included)

Hello Unity forums! I am trying to make a simple game, well kinda i guess. Anyways, i have a grid that i downloaded off of the internet, ill upload it in a sec, but my question you all of you people is, how am i able to highlight individual cells around their cell borders on this grid while holding down a key. The holding down a key parts easy, but im assuming i have to use ray cast? maybe? I'm unfamiliar with the topic. But any help with this would greatly be appreciated!

https://www.dropbox.com/s/1zb2r8pv1opf0au/BuildPlane.prefab

An example of what i want to do: (I drew the red box with paint, but this is the effect i would like to achieve.)

https://www.dropbox.com/s/4jcvtn4nqe9nkrw/grid.png

Comment
Add comment · Show 4
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 robertbu · Dec 14, 2013 at 05:44 AM 0
Share

How about a screen shot ins$$anonymous$$d of a prefab?

avatar image dovedevic · Dec 14, 2013 at 05:23 PM 0
Share

@robertbu Just uploaded an image :D

avatar image xandermacleod · Dec 14, 2013 at 05:26 PM 0
Share

the image you uploaded makes it look like the cell is already highlighted with a red border. Is you're question how to only make this red border appear when a button is held down rather than a mouse over?

Trying to understand the question better.

avatar image dovedevic · Dec 14, 2013 at 05:29 PM 0
Share

@xandermacleod I drew that box around the cell with paint. $$anonymous$$y question is how to do that...

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by halukdemir · Dec 14, 2013 at 06:35 PM

You cannot draw cells directly. You should use game object prefab to place on grid as same size of cells. After that you can change their colors when on holding a key.

Ex: transform.renderer.material.color = Color.white;

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 halukdemir · Dec 14, 2013 at 11:14 PM 0
Share

You can store objects public positions on awaking.

Ex: tile.gridPositionX = 0; tile.gridPositionY = 0;

so you can easily compare these values in list.

avatar image
0

Answer by xandermacleod · Dec 14, 2013 at 07:36 PM

Ok. Here's the approach I would take:

  1. Create an array of empty gameobjects each of which should be positioned at the centre of each grid square. (Hence forth referred to as centreObjects).

  2. Cast a ray from the mouse position to the ground, and store the hit location in a variable.

  3. Compare the distance between the hit location and all of the centreObjects and find out which centreObject has the smallest distance to the hit location (distance can be found through Vector3 magnitude).

  4. In advance, prepare a prefab with 4 particle systems that mimics the edges of a grid square.

  5. Instantiate the prefab at the closest centreObject.

  6. (Check each frame if the centreObject has changed, and if so, destroy the previous prefab, and instantiate a new one).

Comment
Add comment · Show 3 · 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 xandermacleod · Dec 14, 2013 at 07:40 PM 0
Share

Take note, if your grid undulates then the approach to take is to have a flat grid of gameObjects high in the sky, then cast a ray downward and use the hit location for your centreObjects.

avatar image dovedevic · Dec 14, 2013 at 09:38 PM 0
Share

Well if i have maybe 2000 grid squares, is there any way to shorten the method. Wouldn't casting a ray and comparing the distances lag up the game?

avatar image xandermacleod · Dec 15, 2013 at 01:33 AM 0
Share

It sure would at 2000+.

Another solution is to have box colliders on each centerObject. that way you can avoid the 2k+ for loop and just directly read out the centreObject associated with the hit.collider.

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

19 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

Related Questions

How to create a countdown counter based off of a Key press. 1 Answer

Ways to reduce draw cells 1 Answer

Inspector doesn't want to show keys in Scripts 2 Answers

Use the same input key 1 Answer

Switch from GUI button to toggle key 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