- Home /
Draw Texture in a grid like Trainyard
Hello to everyone!!! Is there someone that knows a way to draw texture on a grid with continuous rails like game Trainyard??
That depends! Are you using OnGUI for your drawing, or something else?
Answer by robertbu · Jan 18, 2013 at 10:00 PM
I can think of few different ways, but here is a starting point for one way. Create a Tile class. The Tile class would have an array of textures. Each texture would represent one of the possible track runs. The Tile Class would detect when a finger move entered and exited the game object on which the Tile class was a component. Based on the finger move, a specific texture/state would be selected. For example if the finger move came in on the left and and exited at the bottom, a texture that started on the left and curved down would be selected from the array and dispalyed.
The board would consist of an array of game objects with the Tile class as a component. To run the train after the track has been constructed, you could start at the beginning and walk from tile to tile looking at the state of each tile to build a path for the train.
Answer by edoz78 · Jan 19, 2013 at 11:39 AM
Ok, i understand your way with tile map! Can you give me a code or a pseudo-code that implements this way? Thanks a lot!
For the textures, create a public array of texture. In C#:
public Texture[] artex;
In the inspector, drop in your textures.
To switch textures you can do something like:
renderer.material.texture = artex[4];
For the movement code you likely want to solve these problems:
What tile am I over? - Likely this will be handled by Raycasting.
How to I get access to the script for this tile? - Likely handled by GetComponent().
Who has the focus? - Will need to build some focus tracking mechanism.
What side am I near in a particular tile? - Will need to figure out out to transform the world coordinates into something local to the tile.
Your answer
Follow this Question
Related Questions
Paint Grid Texture 1 Answer
Assigning UV Map to model at runtime 0 Answers
How to make a grid plan as 3dsmax 0 Answers
[c#] Create visible appearence of a grid using texture or models 1 Answer
How to add a grid to an image? 1 Answer