Use a mouse point to ray to check for where you clicked and then instantiate a building there:
To place several types of building you can store building prefabs in a game object array. Declare it like so:
This will turn into a drop down menu in the inspector where you can drag prefabs of mills, barracks, houses etc.
You need to be able to pick which building to instantiate so you store your selection in an int variable like buildIndex which you declare like so:
Array indexing starts at 0 so the first item in the list will be buildingTypes
Next you need a way to change the index so you might have a bunch of GUI Icons showing a picture of the building. You set up GUI icons like so:
Next you might want to stop the player spamming buildings so you'll do a cost for each building. You'll have to store costs in some variable as well as how much resources you have. e.g. for wood you might do:
That's not even the tip of the iceberg but I hope it sets you on the right path to writing your own game.
i wrote something like these :
it gives me an error, it says :
NullReferenceException: Object reference not set to an instance of an object NewBehaviourScript 1.Update () (at Assets\NewBehaviourScript 1.js:7)
answered Jul 05 '10 at 10:32 PM