Skip to content

Commit

Permalink
Extracted projectile logic from TowerLogic
Browse files Browse the repository at this point in the history
...to the separate script, `ProjectileTowerLogic`.
  • Loading branch information
ddabble committed Nov 17, 2021
1 parent 50aa5cc commit eb2ed8a
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 26 deletions.
4 changes: 0 additions & 4 deletions Assets/Prefabs/Towers/AxeTurret/AxeTurret.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -772,10 +772,6 @@ MonoBehaviour:
m_EditorClassIdentifier:
canInteract: 1
input: {fileID: 0}
bullet: {fileID: 0}
bulletSpawnPoint: {fileID: 0}
bulletSpeed: 0
bulletDamage: 0
rotAxis: {fileID: 929849385462332844}
arrowPointer: {fileID: 0}
--- !u!114 &8637078598552028505
Expand Down
4 changes: 0 additions & 4 deletions Assets/Prefabs/Towers/LightningTurret/LightningTurret.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -570,10 +570,6 @@ MonoBehaviour:
m_EditorClassIdentifier:
canInteract: 1
input: {fileID: 0}
bullet: {fileID: 0}
bulletSpawnPoint: {fileID: 0}
bulletSpeed: 0
bulletDamage: 0
--- !u!54 &1378390819816396464
Rigidbody:
m_ObjectHideFlags: 0
Expand Down
17 changes: 15 additions & 2 deletions Assets/Prefabs/Towers/WheelTurret/WheelTurret.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ GameObject:
m_Component:
- component: {fileID: 2462899330894574527}
- component: {fileID: 5783301673282278111}
- component: {fileID: 2609491176346275453}
- component: {fileID: 3515612305777872196}
- component: {fileID: 1759242131}
- component: {fileID: 3531771237580499680}
Expand Down Expand Up @@ -162,12 +163,24 @@ MonoBehaviour:
m_EditorClassIdentifier:
canInteract: 1
input: {fileID: 0}
rotAxis: {fileID: 769070955576516685}
arrowPointer: {fileID: 8557351424284430801}
--- !u!114 &2609491176346275453
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2983117196373584133}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c9aab47f9c6e15941975dfb0bc7c8db4, type: 3}
m_Name:
m_EditorClassIdentifier:
bullet: {fileID: 4237738930188430962, guid: 1cacc95863cb82a4da5dcf8bb67f5ef2, type: 3}
bulletSpawnPoint: {fileID: 7245097492267856000}
bulletSpeed: 5
bulletDamage: 5
rotAxis: {fileID: 769070955576516685}
arrowPointer: {fileID: 8557351424284430801}
--- !u!95 &3515612305777872196
Animator:
serializedVersion: 3
Expand Down
17 changes: 15 additions & 2 deletions Assets/Prefabs/Towers/tower_pendulum.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ GameObject:
m_Component:
- component: {fileID: 3686963311025437781}
- component: {fileID: 1350360576178508834}
- component: {fileID: 2175461025215403135}
- component: {fileID: 8466527481623126138}
- component: {fileID: 8528154779301624128}
- component: {fileID: 154197252}
Expand Down Expand Up @@ -81,12 +82,24 @@ MonoBehaviour:
m_EditorClassIdentifier:
canInteract: 1
input: {fileID: 0}
rotAxis: {fileID: 0}
arrowPointer: {fileID: 4911675975082342184}
--- !u!114 &2175461025215403135
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 423603099658726498}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c9aab47f9c6e15941975dfb0bc7c8db4, type: 3}
m_Name:
m_EditorClassIdentifier:
bullet: {fileID: 0}
bulletSpawnPoint: {fileID: 0}
bulletSpeed: 0
bulletDamage: 0
rotAxis: {fileID: 0}
arrowPointer: {fileID: 4911675975082342184}
--- !u!136 &8466527481623126138
CapsuleCollider:
m_ObjectHideFlags: 0
Expand Down
20 changes: 20 additions & 0 deletions Assets/Scripts/Towers/ProjectileTowerLogic.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ProjectileTowerLogic : MonoBehaviour
{
public GameObject bullet;
public GameObject bulletSpawnPoint;
public float bulletSpeed;
public float bulletDamage;

public void LaunchProjectile()
{
GameObject newBullet = Instantiate(bullet, bulletSpawnPoint.transform.position, bulletSpawnPoint.transform.rotation);
newBullet.transform.SetParent(transform);
BulletLogic newBulletLogic = newBullet.GetComponent<BulletLogic>();
newBulletLogic.Damage = bulletDamage;
newBulletLogic.BulletSpeed = bulletSpeed;
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/Towers/ProjectileTowerLogic.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 0 additions & 14 deletions Assets/Scripts/Towers/TowerLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ public class TowerLogic : Interactable
{
public TurretInput input;

public GameObject bullet;
public GameObject bulletSpawnPoint;
public float bulletSpeed;
public float bulletDamage;

protected void Start()
{
HexGrid hexGrid = GameObject.FindGameObjectWithTag("Grid").GetComponent<HexGrid>();
Expand All @@ -32,13 +27,4 @@ public override void Unfocus(PlayerStateController player)

public override void Interact(PlayerStateController player)
{}

private void LaunchProjectile()
{
GameObject newBullet = Instantiate(bullet, bulletSpawnPoint.transform.position, bulletSpawnPoint.transform.rotation);
newBullet.transform.SetParent(transform);
BulletLogic newBulletLogic = newBullet.GetComponent<BulletLogic>();
newBulletLogic.Damage = bulletDamage;
newBulletLogic.BulletSpeed = bulletSpeed;
}
}

0 comments on commit eb2ed8a

Please sign in to comment.