This section's code example should be relatively straightforward and we should be able to complete it in two steps, as follows:
- Let's start by implementing our drone, as this is the entity that we will pool. Because it is such a lengthy class, we are going to split it into two segments. You can see the first segment here:
using UnityEngine;
using UnityEngine.Pool;
using System.Collections;
namespace Chapter.ObjectPool
{
public class Drone : MonoBehaviour
{
public IObjectPool<Drone> Pool { get; set; }
public float _currentHealth;
[SerializeField]
private float maxHealth = 100.0f;
[SerializeField]
private float timeToSelfDestruct = 3.0f;
void Start()
{
_currentHealth = maxHealth;
}
void OnEnable()
{
AttackPlayer();
StartCoroutine(SelfDestruct());
}
void OnDisable()
{
ResetDrone...