Game Development Reference
In-Depth Information
Listing 2.21 A Quick and Easy Script to Create a Virtual City
from One Building Object
var building:GameObject;
function Start()
{
for(var i = 0; i < 20; i++)
{
for(var j = 0; j < 20; j++)
{
var newPos: Vector3 =
new Vector3(
i*Random.Range(100,200),0,
j*Random.Range(100,200));
var b:GameObject =
Instantiate(building,newPos,Quaternion.identity);
}
}
}
function Update () {}
Step 3. Save the script and attach it to the First Person
Controller. Click on the FPC and locate the script component in
the Hierarchy. Drag and Drop the building prefab from the
Project onto the building property of the script in the Inspector.
In LOD Manager change the LOD Dist 1 to 500 and LOD Dist
2 to 1000.
Step 4. Play with both the Scene and the Game open. Orient your
view in the Scene to be looking down on the terrain. When you
first play the game note that all the buildings are created and
positioned by the instantCity script. After this, buildings that are a
certain distance from the FPC are removed. This is the LOD script
in action. You can modify the distance values for the buildings
LOD in the Inspector for the building prefab. In the Scene you will
also see the FPC frustum. If it is larger than the range of the drawn
buildings then it is too large.
Step 5. While playing, stand in one location and look around in the
Game. How far can you see? If you can't see the buildings at the
edge of the frustum, the far plane setting for the camera is too large.
Try reducing it to see if it will have any effect on the environment.
Remember, if you can't see a game object, there is no reason to try
to draw it.
Search Nedrilad ::




Custom Search