smooth background change

how to make the change between background images smooth, like in the game terraria

public class BackgroundManager : MonoBehaviour
{
    [SerializeField] private SpriteRenderer[] backgroundSpriteRenderers; // Массив SpriteRenderer для фонов
    [SerializeField] private Sprite[] newBackgroundSprites; // Массивы новых спрайтов для фонов
    [SerializeField] private Sprite[] oldBackgroundSprites; // Массивы старых спрайтов для фонов

    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.tag == "Player")
        {
            // Отобразить новые фоны
            for (int i = 0; i < backgroundSpriteRenderers.Length; i++)
            {
                backgroundSpriteRenderers[i].sprite = newBackgroundSprites[i];
            }
        }
    }

    private void OnTriggerExit2D(Collider2D other)
    {
        if (other.gameObject.tag == "Player")
        {
            // Отобразить старые фоны
            for (int i = 0; i < backgroundSpriteRenderers.Length; i++)
            {
                backgroundSpriteRenderers[i].sprite = oldBackgroundSprites[i];
            }
        }
    }
}

9866829--1421997--Screen Shot 2024-05-31 at 5.33.43 PM.png

1 Like


I have already checked, if it is possible to write the code, then I will be glad

It is possible for you to write the code, yes. I suggest you start immediately with some tutorials.

The purpose of this forum is to assist people who are ready to learn by doing, and who are unafraid to get their hands dirty learning how to code, particularly in the context of Unity3D.

This assumes you have at least written and studied some code and have run into some kind of issue.

If you haven't even started yet, go check out some Youtube videos for whatever game design you have in mind. There are already many examples of the individual parts and concepts involved, as there is nothing truly new under the sun.

If you just want someone to do it for you, you need go to one of these places:

https://forum.unity.com/forums/commercial-job-offering.49/

https://forum.unity.com/forums/non-commercial-collaboration.17/

https://livehelp.unity.com/?keywords=&page=1&searchTypes=lessons

Remember this is YOUR game, not ours. We have our own games we're working on.