Skip to content

Commit 76dca6d

Browse files
committed
fixing the pool to release another
1 parent c5103da commit 76dca6d

File tree

9 files changed

+6
-163
lines changed

9 files changed

+6
-163
lines changed

Assets/CustomTools/ObjectPooling/Scripts/ObjectPool/IPooledObject.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
void Init();
44
void OnObjectSpawn();
55
void OnObjectDespawn();
6+
void Despawn();
67
}
Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
1-
using System;
2-
using System.Collections;
3-
using System.Collections.Generic;
4-
using UnityEngine;
5-
using Random = UnityEngine.Random;
1+
using UnityEngine;
62

73
public class PooledObject : MonoBehaviour, IPooledObject
84
{
95

10-
private Rigidbody _rb;
116

127
public PooledObjectType Type;
138

14-
private float _timer = 3f;
159

1610

1711
public virtual void OnObjectSpawn()
1812
{
19-
_rb.velocity = Vector3.zero;
13+
2014
}
2115

2216
public virtual void OnObjectDespawn()
@@ -26,35 +20,13 @@ public virtual void OnObjectDespawn()
2620

2721
public virtual void Init()
2822
{
29-
_rb = GetComponent<Rigidbody>();
30-
AddRandomForce();
31-
_timer = 10f;
23+
3224
}
3325

34-
public virtual void AddRandomForce()
26+
public void Despawn()
3527
{
36-
int value = 300;
37-
Vector3 random =
38-
new Vector3(Random.Range(-value, value),
39-
Random.Range(-value, value),
40-
Random.Range(-value, value));
41-
42-
_rb.AddForce(random);
28+
ObjectPooler.Instance.Despawn(Type, gameObject);
4329
}
4430

45-
//private void Update()
46-
//{
47-
// //The timer stands for only demostration reasons .
48-
// //Remove it or comment it than you can despawn your objects whenever you want !.
49-
50-
// if (_timer > 0)
51-
// {
52-
// _timer -= Time.deltaTime;
53-
// }
54-
// else
55-
// {
56-
// ObjectPooler.Instance.Despawn(Type,gameObject);
57-
// }
58-
//}
5931

6032
}

Assets/CustomTools/ObjectPooling/Scripts/PooledObjects.meta

Lines changed: 0 additions & 8 deletions
This file was deleted.

Assets/CustomTools/ObjectPooling/Scripts/PooledObjects/Cube.cs

Lines changed: 0 additions & 26 deletions
This file was deleted.

Assets/CustomTools/ObjectPooling/Scripts/PooledObjects/Cube.cs.meta

Lines changed: 0 additions & 11 deletions
This file was deleted.

Assets/CustomTools/ObjectPooling/Scripts/PooledObjects/Sphere.cs

Lines changed: 0 additions & 27 deletions
This file was deleted.

Assets/CustomTools/ObjectPooling/Scripts/PooledObjects/Sphere.cs.meta

Lines changed: 0 additions & 11 deletions
This file was deleted.

Assets/CustomTools/ObjectPooling/Scripts/Spawner.cs

Lines changed: 0 additions & 36 deletions
This file was deleted.

Assets/CustomTools/ObjectPooling/Scripts/Spawner.cs.meta

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)