VladimirPirozhenko 45b277e7d1 Initial commit
2022-08-07 07:31:16 +03:00

37 lines
1.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using UnityEngine;
public class ObstaclePool : MonoBehaviour
{
//[SerializeField] private Obstacle defaultObstaclePrefab;
private ObjectPool<Obstacle> pool;// { get; private set; } //ВЫНЕСТИ В ОТДЕЛЬНЫЙ КЛАСС, ЗДЕСЬ ХРАНИТЬ СПИСКИ
public void CreateObstaclePool(Obstacle obstaclePrefab) // ВЫНЕСТИ В КЛАССЫ
{
Func<Obstacle> createObstacle = () =>
{
Obstacle obstacle = Instantiate(obstaclePrefab);
obstacle.gameObject.SetActive(false);
obstacle.transform.SetParent(gameObject.transform, false);
return obstacle;
};
Action<Obstacle> getObstacle = (Obstacle obstacle) =>
{
obstacle.gameObject.SetActive(true);
};
Action<Obstacle> releaseObstacle = (Obstacle obstacle) =>
{
obstacle.transform.SetParent(gameObject.transform, false);
obstacle.gameObject.SetActive(false);
};
pool = new ObjectPool<Obstacle>(createObstacle, getObstacle, releaseObstacle,100);
}
public Obstacle GetFromPool()
{
return pool.Get();
}
public void ReturnToPool(Obstacle obstacle)
{
pool.ReturnToPool(obstacle);
}
}