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.)
2 Answers
2
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;
Ok. Here’s the approach I would take:
- 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).
- Cast a ray from the mouse position to the ground, and store the hit location in a variable.
- 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).
- In advance, prepare a prefab with 4 particle systems that mimics the edges of a grid square.
- Instantiate the prefab at the closest centreObject.
- (Check each frame if the centreObject has changed, and if so, destroy the previous prefab, and instantiate a new one).
How about a screen shot instead of a prefab?
– robertbu@robertbu Just uploaded an image :D
– dovedevicthe 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.
– xandermacleod@xandermacleod I drew that box around the cell with paint. My question is how to do that...
– dovedevic