# City builder

**URL:** <https://discussions.unity.com/t/city-builder/416772>\
**Category:** Scripting\
**Tags:** Scripting\
**Created:** [June 27, 2010, 7:28pm UTC](https://discussions.unity.com/t/city-builder/416772 "2010-06-27T19:28:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon\_71583187](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@anon\_71583187](https://discussions.unity.com/u/anon_71583187)\
**Post date:** [June 27, 2010, 7:28pm UTC](https://discussions.unity.com/t/city-builder/416772/1 "2010-06-27T19:28:10Z")

</div>

Is there any kind of tutorials or sites with info on how to make a simple City Builder game in Unity3d?

---

<div class="post-metadata">

**Author:** ![mVlipka](https://avatars.discourse-cdn.com/v4/letter/m/9de0a6/32.png) [@mVlipka](https://discussions.unity.com/u/mVlipka)\
**Post date:** [June 27, 2010, 11:47pm UTC](https://discussions.unity.com/t/city-builder/416772/2 "2010-06-27T23:47:16Z")

</div>

Well, the way I would do this, is that you have a variable for your money.  
You have a bunch of buttons for each building type, when a building button is clicked, you check the players money.  
If the player’s money \>= buildingPrice then money -= buildingPrice.

From there I would set a variable like,  
building = true  
and another variable, like,  
Skyscraper = true.  
Then you can have an if for when the mouse button is down and do

if building = true Skyscraper == true then createBuilding(hit.point)

Of course, this isn’t the actual code, but it is real easy to figure out once you look at a few examples:

Here is how I make a player summon walls, based on their cursor position:

```auto
if(Physics.Raycast(ray, out hit) hit.transform != this.transform)
            {
                GameObject wall = Instantiate(wallPrefab, hit.point, Quaternion.identity) as GameObject;
}

```

You can also check if there is a building already there, or in a certain distance of the building by using a Physics.OverlapSphere

For roads, there is a plugin for Unity that allows roads to be made in the editor (if I remember correctly at least…), I’m sure there is a way to create them at runtime.

I hope I helped, I don’t actually have enough time to write up a full tutorial for you. You can talk to me on MSN or AIM, and I should be able to find the time to help you at some point.

Good luck on your game, I’m a fan of city builder type games!
