#chicanary

1 messages Β· Page 1 of 1 (latest)

lucid hornet
#

hi

exotic marten
#

ok

#

so what step are we on now

lucid hornet
#

do i duplicate the SO

exotic marten
#

do you have a Blue thing in the assets that you can change the values of?

lucid hornet
#

yes

exotic marten
#

ok yes you can duplicate it and change the name and values

#

do this for every new gun you want

#

which is the point

lucid hornet
#

this seems alot more convenient actually

exotic marten
#

finally

grim yarrow
#
// 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..
}```
exotic marten
#

now even if you have just 1 GameObject with your weapon script

#

you can still have different guns

lucid hornet
#

okay wait wait

#

so i use that code there to like

#

implement the SO into the actual scripts im using

exotic marten
#

yeah

#

so instead of having these variables in your weapon script

#

you will just access them from the SO

lucid hornet
#

uhh i dont understand some parts

#

awake() and shoot()

#

and the bit below shoot

exotic marten
#

apart from CurrentAmmo and idk what else, that will be in your weapon script seperatly (because its constantly changing)

lucid hornet
#

do i need those

exotic marten
#

you already have this code

grim yarrow
#

just an example

exotic marten
#

for shooting

#

the only thing you need to look at there is referencing the SO and taking its data

lucid hornet
#

whats the difference between awake and start

#

is it cool if i use either here?

exotic marten
#

good for setting components like for a singleton for example

grim yarrow
#

think Awake as a constructor, it runs even if script is disabled. It will always run at least once (unless gameobject is disabled)

lucid hornet
#

seems kinda iffy especially seeing as i disable my scritps alot to find bugs

#

start is probably fine here

grim yarrow
#

dont even worry about it

#

use whatever

exotic marten
#

yeah you shouldnt be using Awake here anyway

lucid hornet
#

like this??

exotic marten
#

just delete that

#

its pointless

lucid hornet
#

i reference the ammo throughout the script

#

i need it

exotic marten
#

this is current ammo

grim yarrow
#

we didnt say remove the ammo...

lucid hornet
#

maxammo is the constant

exotic marten
#

yes

grim yarrow
#

remove ammo from SO

#

not Weapon

exotic marten
#

so just do ammo = weaponSO.maxAmmo;

lucid hornet
#

oh right

#

good point

grim yarrow
#

anything that changes should just make a copy and modify it in the weapon

exotic marten
#

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

lucid hornet
#

last thing i dont get is why i should still have a logic script

#

its literally identical to the SO

#

and is doing nothing

exotic marten
#

no its not

#

how is it?

#

you do your shooting here

#

instantiating

#

etc

lucid hornet
#

theyre holding the same data

exotic marten
#

your not supposed to hold the data on the script

#

apart from current ammo

grim yarrow
#

but now you dont have to attach so many LOGIC scripts to gameobjects just to define some values for each

lucid hornet
#

uh still confused but sure

grim yarrow
#

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

lucid hornet
exotic marten
#

you can just change 1 variable, and have a whole new gun by using scriptable objects

lucid hornet
#

iiii dont get it

grim yarrow
#

for example a weapon Pickup will only hold an SO of that DATA

lucid hornet
#

whatever its not important rn

exotic marten
#

just do it

#

and you will know

#

and understand it

lucid hornet
#

i have no idea what youre asking me to do

exotic marten
#

show your gun script

#

actually

lucid hornet
#

im getting an error wait

#

object reference not set to an instance of an object

#

on the fireRate line

exotic marten
#

in the inspector

lucid hornet
grim yarrow
#

those are runtime errors

lucid hornet
#

oh oops no

exotic marten
#

you need to drag your SO into the slot in the inspector

lucid hornet
#

got it

#

i cant even

#

use the other SO script yet

#

ive not been using actual guns

exotic marten
#

what other SO script

lucid hornet
#

the one with minor changes

#

AR

#

the bullets have coming from the player

#

so i dont have anywhere to use the AR one

grim yarrow
#

wat

exotic marten
#

literally no idea lmao

#

maybe some screenshots?

#

a video?

lucid hornet
#

ar and pistol

grim yarrow
#

show the updated scripts too while ur at it

lucid hornet
#
    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();


    }

    

}
grim yarrow
lucid hornet
#

oh oops

exotic marten
lucid hornet
#

too late

#

i cant drag both in

exotic marten
#

no

lucid hornet
#

im shooting from one place

exotic marten
#

because how can you have multiple guns at once

lucid hornet
#

i need another place to shoot from

#

and somehow

#

switch to it

exotic marten
#

if you make a new game object for each gun

#

you can make a FirePoint Transform to assign in the inspector

grim yarrow
#

you define a Transform shootPoint

exotic marten
#

and change the position for each gun

lucid hornet
#

would it be like

#

the tiniest incriment

#

so you cant tell

#

im confusing myself

exotic marten
#

uhh it will be whatever your gun sprite needs?

grim yarrow
#

it will be a separate gameobject you assign

exotic marten
#

wherever the barrel is

grim yarrow
#

that for example is not DATA so it goes on the actual Weapon script. Its a reference to another object (its firepoint)

exotic marten
#

a pistol will be 0.5 while a sniper might be 1.25 for example

lucid hornet
#

i dont have any gun sprites

exotic marten
#

for the shoot point X position

exotic marten
#

so not sure what the position matters to you

#

of where its firing from

lucid hornet
#

so do i

#

duplicate the fire point

#

put the script in each

#

and different SO

exotic marten
#

no

grim yarrow
#

show the hierarchy of your weapon

lucid hornet
#

this is what i just made

grim yarrow
lucid hornet
#

i assumed

exotic marten
#
Player
  WeaponHolder
    M4A1 - GameObject with weapon script
      FirePoint - Empty GameObject
``` your setup should be something like this
lucid hornet
#

made sense to me like

grim yarrow
#

each one goes on weapon

#

each weapon has its own firepoint

lucid hornet
#

what

grim yarrow
#

because each weapon have different barrel sizes.

lucid hornet
#

i dont care about little details like that rn

grim yarrow
#

they shoot from diff spots

exotic marten
#

then what in the fuck do you care about

#

what are you trying to do

#

i dont get it

lucid hornet
#

just

#

trying to

#

use each weapon type

exotic marten
#

you make a game object

#

you call it gun

lucid hornet
#

switch between the two

exotic marten
#

and you add the weapon scrfipt

lucid hornet
#

how would i switch

#

from pistol to ar

exotic marten
#

change the SO

lucid hornet
#

right but thats like

#

really scuffed and wouldnt work in an actual game setting

exotic marten
#

huh

#

you gotta change it somehow

lucid hornet
#

thats what im asking

grim yarrow
#

you can make them different gameObjects too each their own SO assigned, then put them in array to switch which one is selected

exotic marten
lucid hornet
#

would it be like

#

if input e

#

switch

lucid hornet
grim yarrow
#

Put them in an array

exotic marten
grim yarrow
#

change the index

lucid hornet
#

i dont know how to make an array

exotic marten
#

[]

lucid hornet
#

is it like

grim yarrow
lucid hornet
#

a python list

exotic marten
#

int[] thisIsAnArray

grim yarrow
#

idk i dont code python lol

lucid hornet
#

wha

exotic marten
#

or List<int> thisIsAList

lucid hornet
#

just send the whole thing

grim yarrow
#

c# also has List thats why

lucid hornet
#

so i can see

#

instead of little snip bits

exotic marten
#

what more do you wanna see

#

huh

#

thats how you make a list and an array

#

theres nothing more to it

lucid hornet
#

the array

#

and how theyd switch

grim yarrow
#

Arrays are fixed sized lists, Lists can be expanded and are not fixed

#

change the index

lucid hornet
#

h o w

#

during the game

#

how would i do that

grim yarrow
#

currentIndex ++ ?

exotic marten
#
mySO = weapons[0]
mySO = weapons[1]
lucid hornet
#

right

#

thats what i was asking for

#

so its something like

grim yarrow
#

thats why having the grasps for C# basic is important before you attempt to makea game

lucid hornet
#

Weapon[] weapons

grim yarrow
#

so you know how to switch indexes

lucid hornet
#

if input e

#

myso = weapons[0]

exotic marten
exotic marten
lucid hornet
#

in Weapon do i put

grim yarrow
#

ideally you want the index be a variable so you can switch it

lucid hornet
#

wait n o im confused again

exotic marten
exotic marten
lucid hornet
#

how wouold i put those in from the inspector

exotic marten
#

make your array public or [SerializeField]

grim yarrow
#

ScriptableObjects are Serializable so they show up in the inspector (as long as its written like above ^)

lucid hornet
#

uhhh uh hold on

#

im geekin out

exotic marten
grim yarrow
#

well what is your Weapon script

lucid hornet
#

ohh right

#

right

grim yarrow
#

replace it, cause you know examples

lucid hornet
#

i take things literally

exotic marten
#

hence why its taking you 3x longer to do something than a normal person

grim yarrow
#

well give you examples dont copy and paste every line, try to understand what is being sent

lucid hornet
#

im autistic catto

#

im trying my best give me a sec

#

not showing up in the inspector

exotic marten
#

what did you do

lucid hornet
exotic marten
#

do you have any errors?

#

did you save

lucid hornet
#

no

#

and yeah

grim yarrow
#

show the console window

exotic marten
#

actually

#

what script

lucid hornet
#

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

exotic marten
#

since you need this to store the current SO

lucid hornet
#

still not showing up

exotic marten
#

show the whole console window

lucid hornet
#

theres nothing

exotic marten
#

show it

lucid hornet
exotic marten
#

the whole thing

lucid hornet
grim yarrow
# lucid hornet

which script did you put this on btw . show script + inspector for it

exotic marten
#

its right there

#

πŸ’€

#

Guns 0

lucid hornet
#

oh its

#

oohh

#

well

#

its formatted differently

exotic marten
#

well its an array πŸ˜„

lucid hornet
#

ive never used one grin emoji

exotic marten
#

click the arrow to expand it

#

or just type a number in 2 is all you need rn

lucid hornet
#

got it

#

so for the rest of the code itd be like

#

if input e

#

switch array

#

how exactly would i do that

grim yarrow
#

you dont switch array

exotic marten
lucid hornet
#

you know what i mean

#

im not using the right words

grim yarrow
#

I dont

#

code is precise

exotic marten
lucid hornet
#

switch guns

grim yarrow
#

you switch the index.

lucid hornet
#

but you knew what i meant

#

talking is not as precise

lucid hornet
#

toggle it

#

if its on 0 it goes to 1

#

and vice verca

#

if input e and myso == 0?

#

and the opposite

grim yarrow
#

void NextWeapon()
gunIndex ++;
currentWeapon = Guns[gunIndex ]

exotic marten
#

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

lucid hornet
#

uh wha

#

give me a minute

exotic marten
#

you dont need to do this rn

exotic marten
#

i wouldnt do it at all tbh

#

make a WeaponHolder later and do the logic there

lucid hornet
#

guns ++;

exotic marten
lucid hornet
#

that too

exotic marten
#

you need to show your code

#

we cant work from nothing

grim yarrow
#

cause you probably are just jamming a bunch of stuff otgether thining it would work

lucid hornet
#

its literally just that

grim yarrow
#

thats not even what i wrote lmao

#

are you trolling?

lucid hornet
#

?? what

#

gunindex is guns

exotic marten
#

no

grim yarrow
#

not even close, read how an array works first before moving onto it

exotic marten
#

gunindex is an int/float to determine the index of your array

lucid hornet
#

im learning as i go

#

now i know how it works

grim yarrow
#

thats not learning

lucid hornet
#

it literally is

#

if i watch a tutorial im gonna forget literally everything

exotic marten
#

let me just ask

lucid hornet
#

i know myself better

exotic marten
#

will you be adding picking up weapons for example in the next few days?

grim yarrow
lucid hornet
#

i figure it out as i go

exotic marten
lucid hornet
#

gunsIndex doesnt work either

grim yarrow
#

stop what you're doing and learn the tools at hand

lucid hornet
#

im so close to getting this out of the way

#

ill learn the tools after

#

i want something functional

grim yarrow
#

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

lucid hornet
#

ill look up on array after we do this

grim yarrow
#

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

exotic marten
lucid hornet
#

thats not what you told me to write at all

grim yarrow
#

arrays 0 indexed
array.Lenth = 2
max
array[1] //index 1

lucid hornet
#

i dont get the variables at the top

#

what replaces what here

exotic marten
lucid hornet
#

you didnt tell me to add those other two sob sob

#

okay lets see

exotic marten
#

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

grim yarrow
#

pay attention

lucid hornet
#

i said the other two

#

i already had that one

exotic marten
#

theres not 2

#

because you KNOW you need 2

grim yarrow
#

SO[] was said prior

lucid hornet
#

currentWeapon and arrayIndex

grim yarrow
#

weaponSO was current

#

while SO[] was said at different point. So that makes 2 so far

exotic marten
#

arrayIndex is the only one we didnt "SPECIFICALLY" tell you

#

which you couldve easily figured out

lucid hornet
#

is it not evident to you that im just not that smart

#

im trying my best here

#

this is what ive got

exotic marten
#

smart has nothign to do here

lucid hornet
#

it has everything to do here

lucid hornet
#

im not good with common sense

exotic marten
lucid hornet
#

where do i put that

exotic marten
#

perhaps where you already have a .Length πŸ€”

lucid hornet
#

it couldve been a seperate line i cant just guess

#

last time i assumed stuff i was pointed out for it

exotic marten
lucid hornet
#

i dont understand that

#

okay what now

grim yarrow
#

the length is always -1 for index or you will go out of bounds

exotic marten
#

now when you input you can call this method of next index

lucid hornet
#

huh,,

#

do i call currentWeapon

exotic marten
#

what

lucid hornet
#

oh wait do you mean

#

the void

grim yarrow
#

you don't call an SO

exotic marten
lucid hornet
#

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

grim yarrow
#

its not called "the void"

exotic marten
#

its not called a void

#

its called a method

#

or a function

grim yarrow
#

void is a return value of a method

exotic marten
#

whatever you prefer

lucid hornet
#

you know what i mean

exotic marten
#

you know what i mean

#

or well you probably dont

grim yarrow
lucid hornet
#

in code i have to be precise

#

when im talking to people who know this stuff

#

it can be a little more leniant

grim yarrow
#

when they say function/method they mean a function, "a void" you know is a method.. that should be clear what they meant

exotic marten
#

anyway, when you get your input or whatever you wanna do

#

you can call this method

lucid hornet
#

im used to function

#

not method

#

do i put the input in update?

exotic marten
grim yarrow
#

you put it whenever you plan on switching it

#

so if Input listens , usually polling in Update() for keypress

lucid hornet
#

doesnt seem to be working

exotic marten
#

please

#

specifics

#

every time

lucid hornet
#

it isnt switching

grim yarrow
#

yeah you probably have some other sytnax error lol

grim yarrow
exotic marten
#

did you actually assign weapons into the array?

lucid hornet
#
 {
     NextIndex();
 }```
exotic marten
lucid hornet
#

eres the input

#

i did

grim yarrow
lucid hornet
#
 {
     if (arrayIndex == guns.Length - 1) arrayIndex = 0;
     else arrayIndex++;
     currentWeapon = guns[arrayIndex];
 }
#

and this bit

exotic marten
#

show the inspector

lucid hornet
exotic marten
#

any errors when you play?

lucid hornet
#

no

grim yarrow
#

and how did you verify its not actually switching

exotic marten
#

again

#

stop hiding code

lucid hornet
#

update

exotic marten
#

update or Update

lucid hornet
#

i said id put it in update

#

Update

lucid hornet
exotic marten
grim yarrow
exotic marten
#

you do it in Start

#

you need to do it elsewherealso

#

each time you change the weapon

grim yarrow
#

yup you need another method to update the new values in weapon

exotic marten
#

make a new method UpdateGunValues for example and set the values there

#

and run this in Start and when you change the index

lucid hornet
#

like this,,?

#

bit of extra code in the way

exotic marten
#

yeah sure

grim yarrow
#

your IDE doesnt even look configured notlikethis

lucid hornet
#

its been working fine the whole time

exotic marten
#

yeah, but im pretty sure it is?

lucid hornet
#

what about this isnt configured

grim yarrow
#

idk colors look off.

#

if you type . do you get all the unity methods?

lucid hornet
#

uh not right now because its just a dot in empty space

#

but ive seen it before

grim yarrow
#

ok

lucid hornet
#

when i switch i just gain my ammo back

#

nothing else changes

exotic marten
#

pretty sure i saw a red line before, and someone said its not configured

grim yarrow
#

methods normally default to Yellow so i wonder if its theme issue

exotic marten
lucid hornet
#

yes

grim yarrow
#

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)

lucid hornet
#

then what

exotic marten
#

then thats it, you check the values

lucid hornet
#

it switches

#

i see it go from pistol to ar

#

but it doesnt actually

#

keep any of the stats

grim yarrow
#

the SO changes but what about the numbers?

#

are they Updating

lucid hornet
#

numbers?

grim yarrow
#

fireRate etc.

exotic marten
#

πŸ’€

lucid hornet
#

nope

exotic marten
#

i see

#

wait nvm

grim yarrow
#

did you save when you added UpdateGunValues ?

lucid hornet
#

yeah

grim yarrow
#

and so the numbers dont match to the SO ?

exotic marten
#

when in doubt

#

throw in a bunch of Debug.Logs

lucid hornet
#

they stay as the pistol SO

grim yarrow
#

never assume, ensure 100% its running that method

exotic marten
#

can you put the update values after you set the current weapon?

#

in the change index method

#

instead of when you input

lucid hornet
#

can you see this?

exotic marten
#

yeah

#

remove lines 31-34

#

in Start

lucid hornet
#

nothing

#

now i just start with 0 ammo

exotic marten
#

yeah

#

just do update gun values there instead

lucid hornet
#

huh

#

in start,,?

grim yarrow
#

void Start()
{
UpdateGunValues()
}

exotic marten
#

move it there

#

for this one

lucid hornet
#

in nextindex

exotic marten
#

yes

#

at the bottom

lucid hornet
#

do i remove the first one entirely or just duplicate it

grim yarrow
lucid hornet
#

well you were saying start earlier

exotic marten
#

yes

grim yarrow
exotic marten
lucid hornet
#

youve lost me

exotic marten
#

put 1 in start

lucid hornet
#

i put update gun values

#

yeah

exotic marten
#

and move this one

lucid hornet
#

and in nextindex

#

nothing

exotic marten
#

ok

#

debug.logs....

lucid hornet
#

where should i put them

exotic marten
#

put one at the beginning of update gun values

#

Debug.Log("Updating Values"); just for now

lucid hornet
#

yeah

#

is that it?

exotic marten
#

yeah for now

lucid hornet
#

goes off at the start and then goes off everytime i press e

exotic marten
#

ok

#

change it to

#

Debug.Log($"Updating Values: {weaponSO} MaxAmmo: {weaponSO.maxAmmo}");

lucid hornet
#

little funky

#

i tried pasting it in and its kinda weird

exotic marten
#

whats weird

#

oh

#

i missed a }

#

after maxAmmo

lucid hornet
#

yeah got it

exotic marten
#

so its not changing basically

lucid hornet
#

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

exotic marten
#

huh

#

show me all your variables

lucid hornet
exotic marten
#

why do you have a current weapon and a weapon so

#

use 1 or the other

#

and make it private

lucid hornet
#

i dont know ive never used this before so i followed your instructions

exotic marten
#

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 πŸ˜„

lucid hornet
#

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

exotic marten
#

perhaps because we mentioned a few times to have 1 thats private

lucid hornet
#

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

exotic marten
#

the most important thing is your variable names

#

absolute trash 🀣

grim yarrow
#

agreed 100%

exotic marten
#

makes lots of this confusing

grim yarrow
#

your naming convention is the worst thing of all this

exotic marten
#

but at least for the next few projects you will figure that out

#

now you know
instantiating, coroutines, arrays, etc

grim yarrow
lucid hornet
#

well it doesnt help that im made fun of for not knowing alot

#

which i know is my fault but grr humbug humbug

exotic marten
#

we arent making fun

grim yarrow
#

no one made fun

exotic marten
#

its just harder when someone doesnt listen

#

and just complain straight away instead of trying to figure it out

grim yarrow
#

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

exotic marten
#

i think everyone else gave up on helping πŸ˜‚

lucid hornet
#

moreso the fact that i hate annoying people with my not so smart-ness

grim yarrow
lucid hornet
#

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

grim yarrow
#

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.

lucid hornet
#

i mean ill try

#

takes ages and i always forget most of it

grim yarrow
#

well trying is all we can ask for as helping hands πŸ˜‰