我尝试使用Unity for Android(水平滚动游戏)制作2D游戏,并使用4个不同的图像制作背景场景。问题是地形: 当速度增加地形滞后时。游戏相机是静态的,只有图像xOffset被改变了。 FPS:70。
BackgroundOffset
public GameObject[] layers;
public float speed;
public float globalSpeed;
private float xOffsetClouds;
private float xOffset_01;
private float xOffset_02;
public float xOffsetTerrain;
Renderer rendererClouds;
Renderer renderer_01;
Renderer renderer_02;
Renderer rendererTerrain;
// Use this for initialization
void Start () {
rendererClouds = layers[0].GetComponent<Renderer>();
renderer_01 = layers[1].GetComponent<Renderer>();
renderer_02 = layers[2].GetComponent<Renderer>();
rendererTerrain = layers[3].GetComponent<Renderer>();
rendererClouds.sharedMaterial.SetTextureOffset("_MainTex", new Vector2(0, 0));
renderer_01.sharedMaterial.SetTextureOffset("_MainTex", new Vector2(0, 0));
renderer_02.sharedMaterial.SetTextureOffset("_MainTex", new Vector2(0, 0));
rendererTerrain.sharedMaterial.SetTextureOffset("_MainTex", new Vector2(0, 0));
}
public void MoveBackground()
{
xOffsetClouds += Mathf.Repeat(Time.deltaTime * speed, 1);
xOffset_01 += Mathf.Repeat(Time.deltaTime * speed * 1.3f, 1);
xOffset_02 += Mathf.Repeat(Time.deltaTime * speed * 2, 1);
xOffsetTerrain += Mathf.Repeat(Time.deltaTime * speed * globalSpeed, 1);
rendererClouds.sharedMaterial.SetTextureOffset("_MainTex", new Vector2(xOffsetClouds, 0));
renderer_01.sharedMaterial.SetTextureOffset("_MainTex", new Vector2(xOffset_01, 0));
renderer_02.sharedMaterial.SetTextureOffset("_MainTex", new Vector2(xOffset_02, 0));
rendererTerrain.sharedMaterial.SetTextureOffset("_MainTex", new Vector2(xOffsetTerrain, 0));
}
图片设置:
Image: https://i.stack.imgur.com/4VP9k.png
Material: https://i.stack.imgur.com/qDPXr.png
GameObject: https://i.stack.imgur.com/66JcD.png
提前感谢。