Answer the question
In order to leave comments, you need to log in
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;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question