#Learning with Totsnuk

1 messages Β· Page 1 of 1 (latest)

serene light
#

Here. Vertx wanted to create a thread, so I did that for yoy

gray karma
#

hah seems more like im the one teaching with that name

#

opens a childrens book

serene light
#

Haha, yeah. I thought it sounded fun

#

But basically that is a consideration that's important to consider (what happens at runtime vs the editor). It's a good reason for setting up prefabs properly

gray karma
#

im an intermediate composer/sfx designer and joined a few jams and got dissatisfied by the amount of people who never started work on the game so i just went all thanos and said "ill do it myself"

sick lintel
#

respect

gray karma
#

just dont remember shit

#

so i do have that base of logical thinking

#

it should be a little faster

#

ima try to do all of the optional stuff and ill come here if i need help

#

thx for the hospitality

serene light
#

No problem, and good luck!

gray karma
#

welp already just realized naming your sfx with "sfx" at the end is a good idea

#

just now from a coders perspective

gray karma
#

should i create a seperate script for all sfx or one giant one

#

whats more performant

#

i was contemplating editing the button script itself

#

but i was like would that be laggy

serene light
gray karma
#

actually just realized i can make a sfx script

#

and link onclick to it

serene light
#

Ok so the sound would be from the button? Got it, the sfx script can "subscribe" to the button itself in code. So you just attach the script to the button and add the clip and that's it

#

So like:
button.onClick.AddListener(PlaySound)

gray karma
#
using System.Collections.Generic;
using UnityEngine;

public class SFX : MonoBehaviour
{
    public AudioSource VisciiClick_rev3;
    void ButtonPress()
    {
        VisciiClick_rev3.Play();
    }
}```
#

does this work

sick lintel
#

Yeah it should

gray karma
#

is not

#

for some reason

#

this is empty

#

wont let me add the audio asset

serene light
#

The audiosource component is added there

#

And the audio assets are added to the audiosource i believe

#

It's been a while since I did any sound lol

gray karma
#

weird it just isnt good

#

lol

#

it allowed me

#

but i had to drag the audio file onto the button object

#

cuz if i click on the audio file

#

it changes my inspector

#

:<

#

fixed now

#

actually no

#

even though i have a function called ButtonPress

#

wont show up

sick lintel
#

ButtonPress isn't marked as public πŸ˜„

gray karma
#

tried that didnt work tho

sick lintel
#

πŸ€” it should be?

#

Might need to see it again

gray karma
#
using System.Collections.Generic;
using UnityEngine;

public class SFX : MonoBehaviour
{
    public AudioSource VisciiClick_rev3;
    public void ButtonPress()
    {
        VisciiClick_rev3.Play();
    }
}```
sick lintel
#

Can I see the function list your trying to find it in?

gray karma
#

u mean this?

sick lintel
#

hm

gray karma
#

does this work

sick lintel
#

show me the SFX file in unity

gray karma
#

or is this for something else

sick lintel
#

like in your asset window

gray karma
#

like the actual sound file

#

or script

sick lintel
#

Nah the SFX script

gray karma
sick lintel
#

hmm

gray karma
#

ik it should be in the scripts folder but ye

sick lintel
#

oh wait what did you drag into the onclick slot

serene light
#

It needs to be an object

sick lintel
#

the script file or the object with the script

serene light
#

Not the script

gray karma
#

so make a seperate object

#

and call it sfx

serene light
#

Well

gray karma
#

and put the script in

sick lintel
#

No no you already have SFX on a gameobject, the one with the audiosource

serene light
#

The way you are doing it, you COULD attach it to the button

#

But yes, generally it would be its own object.

#

And yeah, needs audiosource component

sick lintel
#

I think you just dragged in the sfx script and not the GameObject that has said script attatched to it

serene light
#

The button is looking for an instance to "report to"

gray karma
#

gotcha

sick lintel
#

As mentioned earlier, the SFX script in your asset window is like a blueprint of a building, it doesn't actually exist. the one on that GameObject is the real deal

gray karma
#

should i have the audio source on the button or the sfx object

sick lintel
#

sfx object

#

imo

gray karma
#

now for some unexplainable reason my text on the try again bar has disappeared

#

lmfao

serene light
gray karma
#

fixed

#

is my sound not playing because the game is reseting faster than it can play

#

or do the sounds play independently of the game

serene light
#

Probably because of resetting. Generally you would run a coroutine so the sound plays (and anything else like vfx and stuff), it waits for a few seconds, and then it resets the game

#

Or play the sound and invoke the method with a delay

#

But also put debug.log("this played") in the method to make sure it is actually getting called

gray karma
#

ok

#

noted

#

so for behavior invoke

#

2.0f stands for 2 seconds?

serene light
#

Yep

gray karma
#

k

#

so

#

how would i refer to this

#

is it a function?

#

i mean yeah

#

but

#

like

#

would this work

#

im assuming not?

#

nope didnt work

#

Severity Code Description Project File Line Suppression State
Warning CS8321 The local function 'GetActiveScene' is declared but never used Assembly-CSharp C:\Users\evanm\My project (1)\Assets\Scripts\LogicScript.cs 27 Active

#

it is saying its never used but invoke literally uses it

gray karma
#

just commented it out for now

sick lintel
#

probably fine

#

some warnings are ok to ignore sometimes somewhat

gray karma
#

sleepin

#

gn all thx

#

might ask for more tmorrow dk

serene light
# gray karma

For tomorrow, you want to move that GetActiveScene method outside of the restartScene method.

#

Gn

#

Oh, or the now named IERestartScene method

gray karma
#

ok im back on now

#

i tried that and it broke the restart scene code

#

just didnt work

#

so

#

yield return new WaitForSeconds(2);

#

am i supposed to put this before or after the code i want to delay by 2 seconds

#

this example doesnt make any sense to me

#

in the second example its almost as if they are refering to proximitycheck as an already existing function, yet it says underneath it in comments "perform some action here", as if you are supposed to put the code of the function there.

#

but doing that doesnt define the function itself

#

also what does for (; ; ) even mean

#

for what?

#

infinity?

#

just dont understand

#

figured it outtttt

#

yayyy

#

i had to start the coroutine itself

#

so i just end it after it waits 2 seconds

sick lintel
#

nice

#

then if you want to tweak how long that takes you can pass through your own float variable into the WaitForSeconds instead of specifically saying 2f

#

it's as easy as doing this, which adds a variable parameter to your function

    IEnumerator SpotOutlineCooldownCoroutine(float waitTime)
    {
        yield return new WaitForSeconds(waitTime);
        lerpSpottedOutline = true;
    }

then whenever you call that function you just give it what the parameter is looking for (this can be called passing in values)
SpotOutlineCooldownCoroutine(2f);

then you can also make a function paramater optional by giving it a default value, so if you don't pass in your own value it will instead default to whatever has been set like

    IEnumerator SpotOutlineCooldownCoroutine(float waitTime = 2f)
    {
        yield return new WaitForSeconds(waitTime);
        lerpSpottedOutline = true;
    }
gray karma
#

ah smart

#

i see how its important to think ahead

sick lintel
#

Honestly yes and no haha

#

general vibe is do it badly first, figure it out smartly later

gray karma
#

or go back and change your entire code later on

#

ye lol

sick lintel
#

it's very very easy to spend a million years over engineering a mechanic you end up removing for game design reasons haha

gray karma
#

ive seen a lot of devs on yt videos talk about that

sick lintel
#

its what im somewhat doing at this present moment πŸ˜›

gray karma
#

haha

#

Severity Code Description Project File Line Suppression State
Error CS1750 A value of type 'double' cannot be used as a default parameter because there are no standard conversions to type 'float' Assembly-CSharp C:\Users\evanm\My project (1)\Assets\Scripts\LogicScript.cs 25 Active

sick lintel
#

oh

#

c# is dumb

#

need an f at the end of the value

gray karma
#

oh shit rite

sick lintel
#

a double is different from an int and a float
imo you should have to specify doubles with a d and not floats with an f due to how more frequent floats are but its deep rooted into c# i guess

gray karma
#

ye double is 64 bit while float is 32

#

googled it

#

so does it have to be a string

sick lintel
#

Which

gray karma
#

cuz it needs an f at the end

#

oh wait

sick lintel
#

na literally just like 20f instead of 20

gray karma
sick lintel
#

ohhh

gray karma
#

correction

sick lintel
#
IEnumerator IERestartScene(float waitTime = 1.4f)
yield return new WaitForSeconds(waitTime)
gray karma
#

oh true can just type it in instead of putting f into the variable

sick lintel
#

yeah the f is just so visual studio understands you mean a float and not a double, not actually a part of the variable

gray karma
#

ohhhhh

#

unrelated ```Severity Code Description Project File Line Suppression State
Warning CS8032 An instance of analyzer Unity.MonoScriptGenerator.MonoScriptInfoGenerator cannot be created from C:\Program Files\Unity\Hub\Editor\2023.1.2f1\Editor\Data\Tools\Unity.SourceGenerators\Unity.SourceGenerators.dll: Could not load file or assembly 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.. Assembly-CSharp C:\Program Files\Unity\Hub\Editor\2023.1.2f1\Editor\Data\Tools\Unity.SourceGenerators\Unity.SourceGenerators.dll 1 Active

sick lintel
#

if you had a rounded number I think visual studio sees that as an int and automatically "casts" (converts) it into a float for you, but because you had the decimal it defaults to a double which visual studio doesn't automatically help with

#

no clue on that one

gray karma
#

could be visual studio being weird im guessing

#

could i start a coroutine inside of this?

#

not appearing

#

contemplating if i need this void

#

i'd rather instill efficiency inside myself early than have to fix all my code later

#

i mean it doesnt take up much arguably

sick lintel
gray karma
#

well ienumerator is for coroutines right

sick lintel
#

Ye

gray karma
#

so couldnt they make it where you can just run the ienumerator inside of that menu

#

instead of making a seperate function

#

or is that not how it works

#

they have stop all but not run specific ones

sick lintel
#

I don't know enough about IEnumerators to answer that properly but I don't think so haha

#

You'll probably end up having seperate functions anyway down the line for various reasons

gray karma
#

ok

sick lintel
#

don't sweat about having functions that only have 1 or 2 lines πŸ˜›

gray karma
#

understood

#

oof

#

requires parameters

#

but it has a default

sick lintel
#

oh thats odd

#

try removing the "" from the startcoroutine

#

it might be a quirk related to passing it in as a string rather than the IEnumerator itself

gray karma
#

wym

sick lintel
#

just try StartCoroutine(IERestartScene)

#

IEnumerator stuff can be a little odd and quirky

gray karma
#

that gives me 3 errors

sick lintel
#

😭

gray karma
#

oh i mean one error

#

cant convert from method group to string

gray karma
#

so i cant adjust it externally

#

it will work

#

just not modular

#

unless its something dumb

sick lintel
#

might be worth asking in code-beginner

#

im probably being dumb

gray karma
#

ok ill ask

gray karma
#

my game is broken and i have no idea why

#

😭

#

trying to integrate fmod

#

i get this

#

also

#

my game is just playing random ass sfx from the fmod project

#

in addition to the ones ive added

#

just utterly confusing

sick lintel
#

Youd have to share code my friend

gray karma
#

lol

sick lintel
#

what line is 26

gray karma
#

hol up

#

ill use bin

sick lintel
#

have you used many debug.log's before

gray karma
gray karma
#

should i?

sick lintel
#

yup. Debug.Log's are the #1 go to for error solving, espicially null ref exceptions

#

basicially your telling it to do something using something but that something isn't there when it trys to find it

#

so using debug.logs, we can check what certain values are, and also if code makes it past if statements

#

26 is when it errors so im guessing you haven't dragged in your audioManager, you can check this by doing

Debug.Log(audioManager); right before line 26 and it should tell you that it's null in the console

gray karma
#

god damn that was so simple

#

decieving little icons

#

didnt even notice that

sick lintel
#

yup

gray karma
#

i fuggin hate those icons

sick lintel
#

debug.logs are so so handy for confirming if the code your working with is actually running

gray karma
#

thx will mess around with those

gray karma
#

quick question

#

the commented bit

#

that i commented out

#

what is the point of putting this on a prefab if theoretically public LogicScript logic; does that already

#

nvm im dumb

#

is that a quirk of unity

sick lintel
#

LogicScript logic is just a variable of the type LogicScript, it's more or less just a cardboard box with "LogicScript" written in sharpie

#

you gotta fill the box

#

can do that either with the FindObjectWithTag.GetComponent or manually dragging it into that public slot (which is a unity specific thing yes)

gray karma
#

ye i realized this lol

#

so its only needed for objects that are created at runtime

#

so im trying to add debug features to this game

#

and im using input.getkeydown

#

i want to log the key that is down in debug

#

but to do this i'd have to put a string into getkeydown and define it as "KeyCode.Space"

#

but it spits errors at me

#

the unity websites doesnt talk abt this

#

simple solution would be just log that a jump was inputed and not the actual key pressed but

sick lintel
#

Code Time 🌈

gray karma
#

i wanted to learn to debug stuff

sick lintel
#

gotta share how you tried to do it

gray karma
#

well shit i just deleted it

#

hol up

#
    void Update()
    {
        
        if (Input.GetKeyDown(keyDown) && birdIsAlive)
        {
            Debug.Log("jump input detected as " + keyDown);
            myRigidBody.velocity = Vector2.up * flapStrength;
        }
        if (transform.position.y > 15 || transform.position.y < -15)
        {
            GameOver();
        }
    }```
#

ik ur supposed to convert it from string to smthing else

#

it says keycode.space is an enum

#

so i googled convert string to enum

#

and found nothing lol

#

(btw i have no idea what enum even are still)

#

also tried putting 32 in there as an int

#

didnt work either

#

oh shit

#

nvm unity thought of that

#

lol

#

actually no thats just for languages

#

idk 🀷

#

basically how do i convert from a string to actual code

sick lintel
#

oh

#

ok so a couple of things

#

enums are another type of variable just like int, string, bool etc. etc. you can think of them as a multiple choice bool in a lot of cases. Internally they are just an int. So KeyCode is a built in enum that contains every keyboard key that you can use like a bool. kinda like a list of bools.

#

KeyCode.Space is just the 32nd enum value in KeyCode. C# is fine with you giving it by it's direct name or it's value

#

In this case you'd just want Input.GetKeyDown(KeyCode.Space)

Then for debugging there's this built in function called ToString(), which converts pretty much any value you throw at it into a string. letting you do

Debug.Log(KeyCode.Space.ToString())

gray karma
#

but thats not exactly what i want though

#

i want to make a variable out of "keycode.space" or rather define keyDown as that

#

and then put keydown into the input

sick lintel
#

yup, thats the next part about enums which is cool

gray karma
#

instead of just keycode.space

#

oh?

#

is the name keycode.space misleading?

#

wait nvm im confused

sick lintel
#

Enums are like a two step thing (theres proper terminology that I just don't remember right now because im dumb haha)

theres the enum itself which you explicitly declare though code, like. By design this never changes through code because it's exclusively only what you manually tell it to be. The value in that is static things like this can be referenced in any class you want without reference, because C# knows they will never change.

public enum MyCoolEnum {Option1, Option2, Option3, Option4}

that means you can also have a variable of that specific enum, like this

public MyCoolEnum myCoolEnumToggle

And that just contains a selection of one of those MyCoolEnum options, kind of like how you have LogicScript but also references to it (but a little different)

#

so you can just have public KeyCode myJumpButton and that can contain a selected KeyCode option

gray karma
#

so the name keycode.space doesnt actually reference the hardware button itself but its more so a true false interface for the input?

sick lintel
#

yup

gray karma
#

gotchaaaaa

sick lintel
#

enum settings are Capitalised

#

couldn't tell you why

#

Β―_(ツ)_/Β―

gray karma
#

noticed that

#

as soon as you told me it was a variable i was wondering why it was in caps

sick lintel
#

inconsistency to keep people on their toes perhaps πŸ˜›

gray karma
#

i cant believe im genuinely learning and not quitting within 3 seconds

#

lol

#

actually have to hand it to game makers toolbox for giving these challenges

#

he basically says at the end, heres all this shit, figure it out but heres a lil hint

#

that meshes with how my brain learns very well

#

also thx btw

sick lintel
#

enums are great for handling a lot of logic. if you for example had a bunch of related bools like isGrounded, isJumping, isFalling etc. instead of doing like

if (isGrounded)

else if (isJumping)

else if (isFalling)

you can store it all in a single enum like

public Enum JumpStates {Grounded, Jumping, Falling}
public JumpStates jumpStatesToggle

and use a built in c# thing called a switch (which is basically just if statements but they look nicer)

switch (jumpStatesToggle )
case JumpStates.Grounded

case JumpStates.Jumping

case JumpStates.Falling

and itll only run the code in the state that jumpStatesToggle is set to

sick lintel
gray karma
sick lintel
#

for a practical example i'm doing a stealth guard mechanic thing and i have a debug line that changes colour based on the current state of the detection (red if the guard is slowly unnoticing you, green if they are noticing you etc.)

#

just makes it look nice and neat πŸ˜„

gray karma
#

so case just means "in the case of"

#

basically same as "if this is true"

sick lintel
#

yup

gray karma
#

thats good for organization

sick lintel
#

its literally just if and else if statements internally, just a way to look pretty

gray karma
#

cool

serene light
#

But I guess it also comes down to the compiler

gray karma
#

codin' timeeee

#

ayo, is visual scripting worth doin?

serene light
#

Nah

#

You need to know coding concepts for it anyway, so it's just the words you need to learn for real coding

#

Plus it's so hard to organize vs properly

#

plus it's pretty limited in what it can do

#

and honestly, it's way harder to do anything imo

gray karma
#

good to know

gray karma
#

so ive been struggling with getting my sprites implemented for like 2 days

#

i want them in first before i do any scripting

#

trying to use sprite sheets but just cant figure it out

#

unitys animation system is so confusing :<

#

there is not any good videos i can find about it either

#

they all use single layer sprites

#

i have multiple layers (different color eyes, special effects for a super attack)

#

is it ideal to have sprite sheets or should i just use individuals

#

(i've read a few forums and no one seems to have come to a general consensus about it)

sick lintel
#

might be worth asking in the outside channels friend

#

threads on discord suck for getting new people to see them

gray karma
#

ah