Skip to content

Commit 35f121a

Browse files
refactored code
1 parent 66c83d8 commit 35f121a

File tree

3 files changed

+16
-20
lines changed

3 files changed

+16
-20
lines changed

Combat/Projectile.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,19 +127,16 @@ private IEnumerator ReturnToPoolWithDelay(float delay) {
127127
/// <param name="instigator"></param>
128128
/// <param name="damage"></param>
129129
/// <param name="updateUI"></param>
130-
public void SetTarget(Health target, GameObject instigator, float damage, Action updateUI) {
130+
public void SetTarget(Health target, GameObject instigator, float damage, Action updateUI, string tag) {
131131
this.target = target;
132132
this.damage = damage;
133133
this.instigator = instigator;
134134
this.updateUI = updateUI;
135135
speed = originalSpeed;
136-
PointTowardsTarget();
137-
}
138-
139-
public void SetPoolTag(string tag) {
140136
if (string.IsNullOrEmpty(poolTag)) {
141137
poolTag = tag;
142138
}
139+
PointTowardsTarget();
143140
}
144141
}
145142
}

Combat/WeaponConfig.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ public void LaunchProjectile(Transform rightHand, Transform leftHand, Health tar
8585
Projectile projectileInstance = instance.GetComponent<Projectile>();
8686
projectileInstance.transform.position = GetTransform(rightHand, leftHand).position;
8787
projectile.transform.rotation = Quaternion.identity;
88-
projectileInstance.SetTarget(target, instigator, calculatedDamage, updateUI);
89-
projectileInstance.SetPoolTag(projectileTag);
88+
projectileInstance.SetTarget(target, instigator, calculatedDamage, updateUI, projectileTag);
9089
}
9190
}
9291
}

Util/ObjectPooler.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@ private void Awake() {
2323
FillPools();
2424
}
2525

26+
private void FillPool(string tag) {
27+
if (!poolDict.ContainsKey(tag)) {
28+
return;
29+
}
30+
Pool pool = pools.Find(p => p.tag == tag);
31+
for (int j = 0; j < pool.size; j++) {
32+
GameObject obj = Instantiate(pool.prefab);
33+
obj.transform.SetParent(transform);
34+
obj.SetActive(false);
35+
poolDict[tag].Enqueue(obj);
36+
}
37+
}
38+
2639
private void FillPools() {
2740
for (int i = 0; i < pools.Count; i++) {
2841
Queue<GameObject> objectPool = new Queue<GameObject>();
@@ -36,19 +49,6 @@ private void FillPools() {
3649
}
3750
}
3851

39-
public void FillPool(string tag) {
40-
if (!poolDict.ContainsKey(tag)) {
41-
return;
42-
}
43-
Pool pool = pools.Find(p => p.tag == tag);
44-
for (int j = 0; j < pool.size; j++) {
45-
GameObject obj = Instantiate(pool.prefab);
46-
obj.transform.SetParent(transform);
47-
obj.SetActive(false);
48-
poolDict[tag].Enqueue(obj);
49-
}
50-
}
51-
5252
public void AddToPool(string tag, GameObject instance) {
5353
if (!poolDict.ContainsKey(tag)) {
5454
return;

0 commit comments

Comments
 (0)