J
J
JonnOneCock2022-02-07 17:50:15
C++ / C#
JonnOneCock, 2022-02-07 17:50:15

How to display level prefabs via addressables?

Good day, I want to display levels through addressables. I can not understand how to get objects from groups. So far, I'm getting it through the name.

private readonly List<GameObject> levels = new List<GameObject>();

    private void Awake()
    {
        instantiateButton.onClick.AddListener(InstantiateLevel);
        destroyButton.onClick.AddListener(DestroyLevel);
    }
    private void InstantiateLevel()
    {
        var position = levels.Count * 1.25f * Vector3.forward;
        Addressables.InstantiateAsync("Level 1", position, Quaternion.identity).Completed += handle =>
         {
             levels.Add(handle.Result);
         };

    }
    private void DestroyLevel()
    {
        if(levels.Count > 0)
        {
            for (int i = 0; i < levels.Count; i++)
            {
                Addressables.ReleaseInstance(levels[i]);
                levels.RemoveAt(i);
            }
        }
        else
        {
            return;
        }
    }

How to add data to an array from a group created in Addressables.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question