#chicanary
1 messages Β· Page 1 of 1 (latest)
do i duplicate the SO
do you have a Blue thing in the assets that you can change the values of?
yes
ok yes you can duplicate it and change the name and values
do this for every new gun you want
which is the point
this seems alot more convenient actually
finally
// Weapon.cs
[SerializeField] WeaponSO weaponSO;
private int currentAmmo;
Awake()
currentAmmo = weaponSO.maxAmmo
...
Shoot()
for(int i = 0; i < weaponSO.bulletsPerShot; i++){
currentAmmo --;
//Shoot Bullet Instantiate etc..
}```
now even if you have just 1 GameObject with your weapon script
you can still have different guns
okay wait wait
so i use that code there to like
implement the SO into the actual scripts im using
yeah
so instead of having these variables in your weapon script
you will just access them from the SO
apart from CurrentAmmo and idk what else, that will be in your weapon script seperatly (because its constantly changing)
do i need those
just an example
for shooting
the only thing you need to look at there is referencing the SO and taking its data
awake is called before
good for setting components like for a singleton for example
think Awake as a constructor, it runs even if script is disabled. It will always run at least once (unless gameobject is disabled)
seems kinda iffy especially seeing as i disable my scritps alot to find bugs
start is probably fine here
yeah you shouldnt be using Awake here anyway
actually take time at some point to read these. bookmark them
https://docs.unity3d.com/Manual/ExecutionOrder.html
awake
start
like this??
forget the whole "ammo" variable in the SO though
just delete that
its pointless
this is current ammo
we didnt say remove the ammo...
maxammo is the constant
yes
so just do ammo = weaponSO.maxAmmo;
anything that changes should just make a copy and modify it in the weapon
because ammo will be changing all the time
it shouldnt be stored on the SO
however MaxAmmo doesnt change, so it can be stored there
last thing i dont get is why i should still have a logic script
its literally identical to the SO
and is doing nothing
theyre holding the same data
well thats your design flaw π
your not supposed to hold the data on the script
apart from current ammo
but now you dont have to attach so many LOGIC scripts to gameobjects just to define some values for each
uh still confused but sure
each weapon will need a LOGIC script with its own values . You have to place multiple of them and link each weapon to its own LOGIC
instead of just simply swapping an SO for diff data

you can just change 1 variable, and have a whole new gun by using scriptable objects
iiii dont get it
for example a weapon Pickup will only hold an SO of that DATA
whatever its not important rn
i have no idea what youre asking me to do
im getting an error wait
object reference not set to an instance of an object
on the fireRate line
did you reference your SO
in the inspector
here
those are runtime errors
oh oops no
you need to drag your SO into the slot in the inspector
what other SO script
the one with minor changes
AR
the bullets have coming from the player
so i dont have anywhere to use the AR one
wat
ar and pistol
show the updated scripts too while ur at it
private Rigidbody2D myBullet;
private float fireRate;
private float reloadTime;
private int ammo;
private int maxAmmo;
private bool cooldown = true;
private bool reloading = true;
[SerializeField]
private GameObject player;
[SerializeField]
private Text ammoText;
[SerializeField] SO weaponSO;
public Transform bulletTransform;
void Start()
{
fireRate = weaponSO.fireRate;
reloadTime = weaponSO.reloadTime;
ammo = weaponSO.maxAmmo;
maxAmmo = weaponSO.maxAmmo;
}
private IEnumerator FireRate()
{
cooldown = false;
yield return new WaitForSeconds(fireRate);
cooldown = true;
}
private IEnumerator Reload()
{
reloading = false;
yield return new WaitForSeconds(reloadTime);
ammo = maxAmmo;
reloading = true;
}
// Update is called once per frame
void Update()
{
if (ammo == 0 && reloading)
{
StartCoroutine(Reload());
}
if (Input.GetMouseButton(0) && cooldown && reloading)
{
var spawnedBullet = Instantiate(myBullet, bulletTransform.position, Quaternion.identity);
spawnedBullet.transform.position = player.transform.position;
ammo -= 1;
StartCoroutine(FireRate());
Destroy(spawnedBullet.gameObject, 3);
}
ammoText.text = ammo.ToString();
}
}
use the paste sites like https://gdl.space
oh oops
ar and pistol is what you should be dragging into your weapon script in the inspector
is that what you have done?
no
im shooting from one place
because how can you have multiple guns at once
if you make a new game object for each gun
you can make a FirePoint Transform to assign in the inspector
you define a Transform shootPoint
and change the position for each gun
uhh it will be whatever your gun sprite needs?
it will be a separate gameobject you assign
wherever the barrel is
that for example is not DATA so it goes on the actual Weapon script. Its a reference to another object (its firepoint)
a pistol will be 0.5 while a sniper might be 1.25 for example
i dont have any gun sprites
for the shoot point X position
i know
so not sure what the position matters to you
of where its firing from
no
show the hierarchy of your weapon
this is what i just made
why do you have 2
i assumed
Player
WeaponHolder
M4A1 - GameObject with weapon script
FirePoint - Empty GameObject
``` your setup should be something like this
made sense to me like
what
because each weapon have different barrel sizes.
i dont care about little details like that rn
they shoot from diff spots
switch between the two
and you add the weapon scrfipt
change the SO
thats what im asking
you can make them different gameObjects too each their own SO assigned, then put them in array to switch which one is selected
this is why your supposed to do this <#1282787002571296883 message>
i have no idea what this even means sob
Put them in an array
thats the hierarchy setup
change the index
[]
is it like
Weapon[] weapons
a python list
int[] thisIsAnArray
idk i dont code python lol
wha
or List<int> thisIsAList
just send the whole thing
c# also has List thats why
what more do you wanna see
huh
thats how you make a list and an array
theres nothing more to it
Arrays are fixed sized lists, Lists can be expanded and are not fixed
change the index
currentIndex ++ ?
mySO = weapons[0]
mySO = weapons[1]
thats why having the grasps for C# basic is important before you attempt to makea game
Weapon[] weapons
so you know how to switch indexes
that creates the array where you can store the SO's yes
yes that would change mySO to the FIRST weapon in your array
in Weapon do i put
ideally you want the index be a variable so you can switch it
wait n o im confused again
you put your weapons
the AR and Pistol, from here
how wouold i put those in from the inspector
make your array public or [SerializeField]
ScriptableObjects are Serializable so they show up in the inspector (as long as its written like above ^)
your so class isnt named Weapon...
well what is your Weapon script
replace it, cause you know examples
i take things literally
hence why its taking you 3x longer to do something than a normal person
well give you examples dont copy and paste every line, try to understand what is being sent
what did you do
show the console window
nothing
bulletFire
i thiink
it might be
because of this
this ones showing up
its not doing anything so ill remove it
oh wait
thats the one that is doing something
you can make it private
since you need this to store the current SO
still not showing up
show the whole console window
theres nothing
show it
the whole thing
which script did you put this on btw . show script + inspector for it
this one
well its an array π
ive never used one grin emoji
got it
so for the rest of the code itd be like
if input e
switch array
how exactly would i do that
you dont switch array
no
this
switch guns
you switch the index.
right but how would i likee
toggle it
if its on 0 it goes to 1
and vice verca
if input e and myso == 0?
and the opposite
void NextWeapon()
gunIndex ++;
currentWeapon = Guns[gunIndex ]
also need a check to see if gunIndex is the same as your array size, then make it 0 so you dont get out of bounds error
you dont need to do this rn
yup exactly
this doesnt work
guns ++;
without the space
that too
cause you probably are just jamming a bunch of stuff otgether thining it would work
no
not even close, read how an array works first before moving onto it
gunindex is an int/float to determine the index of your array
thats not learning
let me just ask
i know myself better
will you be adding picking up weapons for example in the next few days?
its not because so far you probably have no idea why you are even doing this in the first place
i figure it out as i go
maybe
not sure
then for now just do what you said
gunsIndex doesnt work either
stop what you're doing and learn the tools at hand
im so close to getting this out of the way
ill learn the tools after
i want something functional
if you dont know how an array works, look it up first then move on
you're just guessing, this isn't a guessing game
its precise math
ill look up on array after we do this
do "this" is part of it
you dont paste random text and expect it to work.. then complain here "doesnt work"
I can make it work just fine, the problem isnt the code
as simple as that
thats not what you told me to write at all
.Length - 1 π
arrays 0 indexed
array.Lenth = 2
max
array[1] //index 1
SO[] myWeapons;
SO currentWeapon;
int arrayIndex;
you need to think for yourself
its not learning if you dont think at all
and get stuck on an error
and complain about the error
wheres the learning? try figuring the error out
SO[] was said prior
currentWeapon and arrayIndex
arrayIndex is the only one we didnt "SPECIFICALLY" tell you
which you couldve easily figured out
is it not evident to you that im just not that smart
im trying my best here
this is what ive got
smart has nothign to do here
it has everything to do here
.Length - 1 as well
where do i put that
perhaps where you already have a .Length π€
it couldve been a seperate line i cant just guess
last time i assumed stuff i was pointed out for it
or you couldve read what navarone said
because arrays are counted from 0
the length is always -1 for index or you will go out of bounds
now when you input you can call this method of next index
what
you don't call an SO
what did i say here?
thats what im asking
i dont know what you mean by method of next index
the void is called next index
so i asked do you mean the void
its not called "the void"
void is a return value of a method
whatever you prefer
you know what i mean
again no, you have to be precise
in code i have to be precise
when im talking to people who know this stuff
it can be a little more leniant
when they say function/method they mean a function, "a void" you know is a method.. that should be clear what they meant
if you want to capture Input every frame
you put it whenever you plan on switching it
so if Input listens , usually polling in Update() for keypress
what doesnt seem to be working
please
specifics
every time
it isnt switching
yeah you probably have some other sytnax error lol
that means what to us without showing what you did
did you actually assign weapons into the array?
{
NextIndex();
}```
you probably didnt
show it
{
if (arrayIndex == guns.Length - 1) arrayIndex = 0;
else arrayIndex++;
currentWeapon = guns[arrayIndex];
}
and this bit
show the inspector
any errors when you play?
no
and how did you verify its not actually switching
where is this
again
stop hiding code
update
update or Update
no difference in ammo or shotspeed
because you dont update the values
put the inspector in debug mode and see what currentWeapon is
you do it in Start
you need to do it elsewherealso
each time you change the weapon
yup you need another method to update the new values in weapon
make a new method UpdateGunValues for example and set the values there
and run this in Start and when you change the index
yeah sure
your IDE doesnt even look configured 
its been working fine the whole time
yeah, but im pretty sure it is?
what about this isnt configured
ok
pretty sure i saw a red line before, and someone said its not configured
methods normally default to Yellow so i wonder if its theme issue
did you actually change the values between the ar and pistol?
put the inspector in Debug mode (3 dots in the inspector window)
then check what the private values are at runtime when you switch with E
(on the weapon script ofc)
then what
then thats it, you check the values
it switches
i see it go from pistol to ar
but it doesnt actually
keep any of the stats
numbers?
fireRate etc.
π
nope
did you save when you added UpdateGunValues ?
yeah
and so the numbers dont match to the SO ?
no
they stay as the pistol SO
never assume, ensure 100% its running that method
can you put the update values after you set the current weapon?
in the change index method
instead of when you input
void Start()
{
UpdateGunValues()
}
in nextindex
do i remove the first one entirely or just duplicate it
big ass red arrow says yes
well you were saying start earlier
yes
both.
key words here
youve lost me
put 1 in start
where should i put them
put one at the beginning of update gun values
Debug.Log("Updating Values"); just for now
yeah for now
goes off at the start and then goes off everytime i press e
ok
change it to
Debug.Log($"Updating Values: {weaponSO} MaxAmmo: {weaponSO.maxAmmo}");
so its not changing basically
its probably
from the uh
public SO weaponSO;
that i set as the pistol
ages ago
thats like
without a doubt gotta be the issue right
why do you have a current weapon and a weapon so
use 1 or the other
and make it private
i dont know ive never used this before so i followed your instructions
my instructions were make it private
not make a new one
obviously if your changing X
BUT USING Y
your gonna have the wrong results π
i know for a fact that i
literally mentioned
the other SO
but nobody said anything then
and i was following both of your guides
perhaps because we mentioned a few times to have 1 thats private
works now grin
yeah and we did that
only issue is the reload is a little
funky
but honestly fuck this project anyway HOLY MOLY this has been so stressful
learned alot in the bin you go
agreed 100%
makes lots of this confusing
your naming convention is the worst thing of all this
but at least for the next few projects you will figure that out
now you know
instantiating, coroutines, arrays, etc
it becomes less overwhelming the more you do it and practice..
well it doesnt help that im made fun of for not knowing alot
which i know is my fault but grr humbug humbug
we arent making fun
no one made fun
its just harder when someone doesnt listen
and just complain straight away instead of trying to figure it out
also don't misunderstand being direct as anything but that
I think generally people in coding/development very direct and to the point (no sugar coating)
Not be mixed up with being rude/mean or whatever. We prob wouldn't have been this patient tbh lol
i think everyone else gave up on helping π
moreso the fact that i hate annoying people with my not so smart-ness
hehe we've been at it for an hour and half almost lol
with osteel literally threatening they wont put up with it any longer just because i dont like to learn the way everyone else does
baaah humbug
well its actually so many times you can get someone to be tutoring you all the way through.. Having to explain every little thing that are easily covered by basic courses is furstrating and after a while comes off lazy (just being honest)
if you need a tutor perhaps consider hiring one, if thats not possible then you do what we all do and start research and testing.
well trying is all we can ask for as helping hands π
