Unity无限背景变化与过渡

时间:2018-12-05 15:25:00

标签: c# unity3d

我使用从右到左移动的平铺方法设置了无限的背景,我要做的是,如果玩家达到一定的分数(例如1000),我想更改背景通过过渡,就像下一个背景会像另一个背景一样从左向右移动,但是当它移动时,它会一直停留到玩家达到另一个分数(例如2000)。然后它再次发生,但是现在有了其他纹理。

当前脚本如下:

public class BackgroundScroll : MonoBehaviour {

Material material;
public Material materialChange;
Vector2 offset;

public int xVelocity, yVelocity;
private float backgroundSpeed = 1f;
public static float speed = 10f;
private float speedUp = 0.1f;
private int changed = 0;

private void Awake()
{
    material = GetComponent<Renderer>().material;
    speedUp = 0.1f;
}

// Use this for initialization
void Start () {
    changed = 0;
    //offset = new Vector2(xVelocity, yVelocity);
    StartCoroutine(Speed());
}

// Update is called once per frame
void Update () {
    offset = new Vector2(xVelocity, yVelocity);
    material.mainTextureOffset += offset * Time.deltaTime * backgroundSpeed;
    BackgroundChange();
}

void BackgroundChange()
{
    if (ScoreHandler.score >= 100 && changed == 0) 
    {
        material.mainTexture = materialChange.mainTexture;
        changed = 1;
    }
}

IEnumerator Speed()
{
    yield return new WaitForSeconds(20);
    speed += speedUp;
    backgroundSpeed += speedUp;
    }
}

此行更改了背景,但根本没有动画或过渡,只是更改了它:material.mainTexture = materialChange.mainTexture;

所以我的问题是我如何用动画改变背景,先滑动它,然后一直停留到另一个滑动,然后再保持。等等...

0 个答案:

没有答案