Skip to content

Commit bcff55a

Browse files
committed
Enhance bullet system with prefab and owner tracking
Added an ammunitionPrefab reference to Ammunition data and updated BasicBullet to include a particle effect, owner vehicle tracking, and improved collision handling. Bullet prefab now uses a particle system, disables gravity, and constrains movement. These changes improve bullet visuals and allow for more robust damage and collision logic.
1 parent 5bf0ce0 commit bcff55a

39 files changed

+4996
-3545
lines changed

Red Strike/Assets/AmmunitionSystem/Ammunition.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ public class Ammunition : ScriptableObject
1010
public float damage;
1111
public float speed;
1212
public float range;
13+
public GameObject ammunitionPrefab;
1314
}
1415
}

Red Strike/Assets/AmmunitionSystem/Ammunitions/Ammunition.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ namespace AmmunitionSystem.Ammunitions
55
public class Ammunition : MonoBehaviour
66
{
77
public AmmunitionSystem.Ammunition ammunitionData;
8+
public VehicleSystem.Vehicles.Vehicle ownerVehicle;
89
}
910
}

Red Strike/Assets/AmmunitionSystem/Ammunitions/Ammunitions/BasicBullet/BasicBullet.asset

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ MonoBehaviour:
1717
damage: 10
1818
speed: 80
1919
range: -1
20+
ammunitionPrefab: {fileID: 8118776881868709922, guid: 108d2182eb2ae5c4e9967e0bb40af6dd, type: 3}

Red Strike/Assets/AmmunitionSystem/Ammunitions/Ammunitions/BasicBullet/BasicBullet.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,23 @@ private void Awake()
1414

1515
private void Start()
1616
{
17+
Debug.Log($"Firing bullet with Damage: {ammunitionData.damage}, Speed: {ammunitionData.speed}");
1718
rb.linearVelocity = transform.forward * ammunitionData.speed;
18-
Destroy(gameObject, ammunitionData.range / ammunitionData.speed);
1919
}
2020

2121
private void OnCollisionEnter(Collision collision)
2222
{
23-
Destroy(gameObject);
23+
if (collision.gameObject.CompareTag("Enemy"))
24+
{
25+
Debug.Log($"Hit enemy: {collision.gameObject.name}, Damage: {ammunitionData.damage}");
26+
// Here you would typically access the enemy's health component and apply damage
27+
}
28+
29+
if (ownerVehicle.gameObject != collision.gameObject)
30+
{
31+
Debug.Log("Bullet collided with: " + collision.gameObject.name);
32+
Destroy(gameObject);
33+
}
2434
}
2535
}
2636
}

0 commit comments

Comments
 (0)