1

I would like to know how to create clickable zones in unity using c#. I am working on a managing type game, and I lack experience when it comes to code.

My idea is to move a character (rather a token) on a map to interact with the different tiles. I already managed the simple part of getting the token to follow my clicks. Now, I would like to constrain my token to move only in specific zones, like the center of each district of the map.

It is to be able to assign consequences to the moves my character will do (for instance moving will cost energy and take some time), but I'll manage it later, it's just to explain what I have in mind.

Any help will be appreciated, Thanks for reading :) Gregoire C.

tRuEsAtM
  • 3,517
  • 6
  • 43
  • 83
  • If I understand correctly, you have a click to move game and want to limit the clickable areas? If you are using Unity's nav system, you can use the NavMesh.SamplePosition function to check if the clicked position is valid. https://docs.unity3d.com/ScriptReference/AI.NavMesh.SamplePosition.html – Chairs Mar 06 '17 at 18:29
  • You got it for the first part : i want to limit the clickable areas. Well, i believe it's a way to do it, but i didn't plan on using the navmesh system : in fact i thought using game objects with colliders since i won't properly get a character to move as in a RTS like game. Thank you for your answer, i will keep searching :) – Grégoire Chevalier Mar 06 '17 at 18:37
  • Hmm, I suppose you could place invisible quads with a clickable tag to represent valid spaces (or if you want to get fancy you could assign them to their own layer for raycasting). – Chairs Mar 06 '17 at 18:48
  • Yes ! That seems to fit what i've in mind. In fact, there is pretty much everything i need at the moment :) Could you lead me to the corresponding scripting reference please ? Once again, thank you for your answer ! – Grégoire Chevalier Mar 06 '17 at 19:00
  • Take a look here at the Unity docs for Layers. About half way down there is an example of selective raycasting that should suit your purposes. https://docs.unity3d.com/Manual/Layers.html – Chairs Mar 06 '17 at 19:09
  • Well, thank you ! I will try this :) – Grégoire Chevalier Mar 06 '17 at 19:21

0 Answers0