Re: Unity C# Terrain Scripting

Posted 16 September 2013 - 09:10 AM

I more less just wanted to include a grid on the terrain that I had already created. I am a beginner in Unity, so I have no idea what you mean by UV. The idea is to keep the bump map attributes as well as terrain textures.
The game will have game pieces like chess that will be able to move and I would like to make it so that when the player selects a piece with the mouse it will highlight the allowed path or the amount of allow squares on the grid. I plan to write a script that will use the grid to move the pieces as well.

Re: Unity C# Terrain Scripting

Posted 16 September 2013 - 12:19 PM

I'm having difficulty picturing what you are talking about.

By "terrain" I assume you mean something like this where you have something like hills and valleys but basically based off of a grid. The terrain in that picture is wireframe; a normal terrain would have a grass texture on it.

If you are trying to make the grid lines visable and highlight a selected "square", I can see where my suggestion would not work.

So, the way I imagine the problem is a grass textured terrain, where we need to make visable grid lines and highlight a selected grid square.

I would be inclined to approach this with High Level Shader Language. (I'm not even sure if you can do that without the Unity Pro version).

Without HLSL, I think what I would do is similar to what I suggested before, although I'm not sure how good the results would look. I would basically have a square grass texture and draw lines around the four edges very thinly in black or whatever color I want the grid lines to be.

Then I would apply the texture to the terrain. So, that the texture repeats across the terrain at the exact same rate as each grid square. So, if a grid square is a meter wide, I would have the texture repeat (through UV wrapping) every meter. Then you should see "grid lines" that perfectly match the shape of the terrain.

For highlighting a single grid square, I think I would create a "square" mesh the same size as a grid square. I might make it yellow, but I would use an alpha transparency to make it almost completely transparent. Then I could place it and turn it on and off to highlight a given grid square.

But I'm not sure I'm even understand your question; so I may be way off on what you are trying to do.

I just started studying Unity. Maybe if I learn it, I'll be able to give a better answer in a couple of weeks.

Re: Unity C# Terrain Scripting

Posted 16 September 2013 - 06:54 PM

I would create both a grid and terrain and overlay the terrain. The grid would not be rendered and would handle all the logic and the movement. The terrain itself does not need to know how to do any of that stuff. Just make sure the origin of the grid and the origin of the terrain match.

Re: Unity C# Terrain Scripting

Well I have looked into this and it seems that this line of code is what is messing everything up.

//ShowGrid is a bool
obj.SetActive(ShowGrid);

Here is the error I get

Assets/Scripts/TerrainGrid.cs(39,29): error CS1061: Type `UnityEngine.GameObject' does not contain a definition for `SetActive' and no extension method `SetActive' of type `UnityEngine.GameObject' could be found (are you missing a using directive or an assembly reference?)

Re: Unity C# Terrain Scripting

Posted 17 September 2013 - 10:42 AM

Okay i figured that out I was out dated, but now I am fully up to date. I now get no error but it does not display the cube grid. I can see the cubes in the empty game object I created and they do activate by going from grey to solid black, but visually all I can see is the placement tools(x,y,z) of each cube.

Re: Unity C# Terrain Scripting

Posted 17 September 2013 - 02:12 PM

Toadill, on 17 September 2013 - 10:42 AM, said:

Okay i figured that out I was out dated, but now I am fully up to date. I now get no error but it does not display the cube grid. I can see the cubes in the empty game object I created and they do activate by going from grey to solid black, but visually all I can see is the placement tools(x,y,z) of each cube.

SetActiveRecursively has been depreciated in Unity 4, you want to use gameObject.SetActive Also, in Unity 4, if you disable a parent object all of it's children will also be disabled. That might be what you have going on with the invisible objects.