#i just want to know because i most of
1 messages · Page 1 of 1 (latest)
public class TestGunScript : MonoBehaviour {
int currentAmmo;
int maxAmmo = 10;
private void Start() {
currentAmmo = maxAmmo;
}
void Update(){
if (Input.GetKeyDown(KeyCode.R)){
ReloadGun();
}
}
void ReloadGun() {
currentAmmo = maxAmmo;
}
}```
this is the gun script, it has a currentAmmo count, which is whats in the gun, when you reload it'll set it to be the maxAmmo count that u defined in this class
the scriptable object can be used to hold all the data (like the max Ammo of that gun for example)
you plug in the reference to it and access its data, to reload ur still doing the reload logic inside the Monobehaviour script, only this time ur grabbing the information (maxAmmo) from teh scriptable object
you can do the reverse, you can have the gun script `jam` for example and u could modify a boolean inside the scriptable object to reflect that it has jammed
so if u go to fire u'd access the SO's Data (but again the logic is being done in the Monobehaviour)
```cs
using UnityEngine;
public class TestGunScript : MonoBehaviour
{
public GunData gunData;
int currentAmmo;
private void Start()
{
currentAmmo = gunData.maxAmmo;
}
void Update()
{
if (Input.GetKeyDown(KeyCode.R))
{
ReloadGun();
}
}
void ReloadGun()
{
currentAmmo = gunData.maxAmmo;
}
}```
gun data would be the SO
```cs
[CreateAssetMenu(menuName = "Gun Data")]
public class GunData : ScriptableObject
{
public int maxAmmo;
}```
hopefully this clears it up a bit, im not very good at SO's so this is about all the info i can provide in a way i think i might understand when i started learning
i am making a scriptable gun so i dont need to create new gun script
i watched a lot of videos and it helps
well good luck mate 🙂
what should not be in scriptable
any functions
or anything that uses monobehaviour stuff
just think of it like this
ur SO is only for data, numbers, words, pictures, colors etc
if u want to do anything with those, change the camera FOV, change the skybox color etc u do that inside another script that isnt the ScriptableObject
its just like data container
ok
is a way of organizing a group of data
thanx bro
np
thats why its used for things like gun types and stuff, every gun is gonna have a ammo count, every gun is gonna have a fire rate etc, u just have 1 Scriptable object for a pistol and it has all this data for u to use,
then u can use the same methods etc, if it has the same data for things like a machine gun etc