Weapon system with projectiles, raycasts and melee

Hello, I am making an FPS game. I’m trying to make a weapon system that can be used to create melee, projectile and raycast weapons.

Currently I have created a script that is used to create scriptable objects that hold weapon data:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[CreateAssetMenu(fileName ="New weapon", menuName ="Weapons")]
public class WeaponConfig : ScriptableObject
{
    public enum WeaponType { Raycast, Projectile, Melee};
    public WeaponType weapomType;

    public int damage;

    [Header("Ammo")]
    public bool infiniteAmmo = false;
    public int clipSize;
    public int maxAmmo;
    public float reloadDuration;
    public float attackSpeed;

    public enum FireMode { Auto, Semi, Burst};
    public FireMode fireMode;

    public enum AmmoType { None, Pistol, Rifle, Shotgun, Energy};
    public AmmoType ammoType;

    [Header("Audio")]
    public AudioClip shootSound;
    public AudioClip reloadStartedSound;
    public AudioClip reloadFinishedSound;

    [Header("Visuals")]
    public Sprite crosshair;

    [Header("Raycast")]
    public float maxRange;
}

The problem is that I don’t know how to implement the shooting.

I’ve got a PlayerShoot script on the player (in which it checks for inputs) and I’ve created a Weapon_Raycast, Weapon_Melee and Weapon_Projectile scripts (in which the shooting happens) for all the diffrent weapons, but I’m just having a hard time implementing this sytem and I can’t get it working.

I would start with some tutorials… there are as many different approaches as there are tutorials to do it: raycasts, actual projects, use physics or don’t use physics, move the physics yourself, etc. Youtube is your friend. I suggest trying four or five totally different tutorials with different ways of doing it to see which way you want to use.

1 Like

Thanks! I’ll try looking more into this!