Game Development Reference
In-Depth Information
private Vector3 lastCamPos;
void Start()
{
lastCamPos = myCamera.transform.position;
}
void Update()
{
Vector3 currCamPos = myCamera.transform.position;
float xPosDiff = lastCamPos.x - currCamPos.x;
adjustParallaxPositionsForArray(clouds,
cloudLayerSpeedModifier, xPosDiff);
adjustParallaxPositionsForArray(nearHills,
nearHillLayerSpeedModifier, xPosDiff);
adjustParallaxPositionsForArray(farHills,
farHillLayerSpeedModifier, xPosDiff);
lastCamPos = myCamera.transform.position;
}
void adjustParallaxPositionsForArray(GameObject[]
layerArray, float layerSpeedModifier, float xPosDiff)
{
for(int i = 0; i < layerArray.Length; i++)
{
Vector3 objPos =
layerArray[i].transform.position;
objPos.x += xPosDiff * layerSpeedModifier;
layerArray[i].transform.position = objPos;
}
}
}
2.
Create a new GameObject in your scene and call it _ParallaxLayers .
This will act as the container for all the parallax layers.
3.
Create three more GameObjects and call them _CloudLayer , _
NearHillsLayer , and _FarHillsLayer , respectively.
4.
Place these three objects inside the _ParallaxLayers object, and place
the Parallax Controller component onto the _ParallaxLayers object.
 
Search WWH ::




Custom Search