#definitely, you should make one, and
1 messages · Page 1 of 1 (latest)
Here is a Gun script
using UnityEngine;
[CreateAssetMenu(fileName = "New Gun", menuName = "Weapon/Gun")]
public class GunData : ScriptableObject
{
public new string name;
public float damage;
public float maxDistance;
public int currentAmmo;
public int magSize;
public int maxAmmoReserves;
public float fireRate;
public float reloadTime;
public bool reloading;
[Header("Animations")]
public AnimationClip shootAnimation;
public AnimationClip reloadAnimation;
public void GiveAmmo(int ammoAmount)
{
magSize += ammoAmount; //give ammo to the player when they get ammo (duh)
}
}```
And "GunData"
The code is all over the place, I realise. Apologies for that
I'm still just learning the relationships between everything in c#
Ok so what issue are you having with this?
I mean I'm immediately seeing some things that don't make any sense to me
public void GiveAmmo(int ammoAmount)
{
magSize += ammoAmount; //give ammo to the player when they get ammo (duh)
}```
Why does giving the player ammo increase their magazine size?
Yeah lol
I don't quite remember what I was doing from before, this script was from quite a few months ago
For one thing, reloading doesn't actually reload the weapon
And the weapon is in a constant state of reloading as well
And yeah, from what you just pointed out, the mag size thing
I mean, I would just take 5 minutes to actually read your code.
I found that mag size thing in 5 seconds actually just reading it
You need to make sure what you're doing actually makes any sense
The other glaring issue I see here is you seem to have two different scripts keeping track of the same information separately
that's a recipe for disaster
For GunData, something like magSize and maxAmmoReserves makes sense, but currentAmmo does not make sense on GunData.
Likewise, for the Gun script, it doesn't make sense to track magSize, but it does make sense to track ammoReserves and currentAmmo
each of these things should be kept in only one place, and only the place that makes sense.
Would you suggest i combine my scriptable object script with the Gun script