Skip to content

Commit

Permalink
fixing the pool to release another
Browse files Browse the repository at this point in the history
  • Loading branch information
ertanturan committed Mar 19, 2020
1 parent c5103da commit 76dca6d
Show file tree
Hide file tree
Showing 9 changed files with 6 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
void Init();
void OnObjectSpawn();
void OnObjectDespawn();
void Despawn();
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Random = UnityEngine.Random;
using UnityEngine;

public class PooledObject : MonoBehaviour, IPooledObject
{

private Rigidbody _rb;

public PooledObjectType Type;

private float _timer = 3f;


public virtual void OnObjectSpawn()
{
_rb.velocity = Vector3.zero;

}

public virtual void OnObjectDespawn()
Expand All @@ -26,35 +20,13 @@ public virtual void OnObjectDespawn()

public virtual void Init()
{
_rb = GetComponent<Rigidbody>();
AddRandomForce();
_timer = 10f;

}

public virtual void AddRandomForce()
public void Despawn()
{
int value = 300;
Vector3 random =
new Vector3(Random.Range(-value, value),
Random.Range(-value, value),
Random.Range(-value, value));

_rb.AddForce(random);
ObjectPooler.Instance.Despawn(Type, gameObject);
}

//private void Update()
//{
// //The timer stands for only demostration reasons .
// //Remove it or comment it than you can despawn your objects whenever you want !.

// if (_timer > 0)
// {
// _timer -= Time.deltaTime;
// }
// else
// {
// ObjectPooler.Instance.Despawn(Type,gameObject);
// }
//}

}
8 changes: 0 additions & 8 deletions Assets/CustomTools/ObjectPooling/Scripts/PooledObjects.meta

This file was deleted.

26 changes: 0 additions & 26 deletions Assets/CustomTools/ObjectPooling/Scripts/PooledObjects/Cube.cs

This file was deleted.

This file was deleted.

27 changes: 0 additions & 27 deletions Assets/CustomTools/ObjectPooling/Scripts/PooledObjects/Sphere.cs

This file was deleted.

This file was deleted.

36 changes: 0 additions & 36 deletions Assets/CustomTools/ObjectPooling/Scripts/Spawner.cs

This file was deleted.

11 changes: 0 additions & 11 deletions Assets/CustomTools/ObjectPooling/Scripts/Spawner.cs.meta

This file was deleted.

0 comments on commit 76dca6d

Please sign in to comment.