#Learning with Totsnuk
1 messages Β· Page 1 of 1 (latest)
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
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"
respect
obv this will take a while but i did learn javascript back in middle school
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
Js is also pretty different too, but all languages have the same "ingredients" (loops, variables, functions, etc). It's just the syntax that is different
No problem, and good luck!
welp already just realized naming your sfx with "sfx" at the end is a good idea
just now from a coders perspective
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
There shouldn't be much of a difference in terms of performance.
I'd say consider how easy it is to write and extend.
Are the sfx all played by different things? You might want an sfx player script with a clip field. So you can just play the sound and it'll play whatever is in that field
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)
using System.Collections.Generic;
using UnityEngine;
public class SFX : MonoBehaviour
{
public AudioSource VisciiClick_rev3;
void ButtonPress()
{
VisciiClick_rev3.Play();
}
}```
does this work
Yeah it should
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
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
ButtonPress isn't marked as public π
tried that didnt work tho
using System.Collections.Generic;
using UnityEngine;
public class SFX : MonoBehaviour
{
public AudioSource VisciiClick_rev3;
public void ButtonPress()
{
VisciiClick_rev3.Play();
}
}```
Can I see the function list your trying to find it in?
hm
show me the SFX file in unity
or is this for something else
like in your asset window
Nah the SFX script
hmm
ik it should be in the scripts folder but ye
oh wait what did you drag into the onclick slot
It needs to be an object
the script file or the object with the script
Not the script
Well
and put the script in
No no you already have SFX on a gameobject, the one with the audiosource
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
I think you just dragged in the sfx script and not the GameObject that has said script attatched to it
The button is looking for an instance to "report to"
gotcha
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
should i have the audio source on the button or the sfx object
now for some unexplainable reason my text on the try again bar has disappeared
lmfao
Whichever one HAS the sfx script.
I'm not sure your use case. Is each button playing its own sound? If so, may as well have the source and script on the button. If it's ANYTHING but that, use a separate object with both source and script
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
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
Yep
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
For tomorrow, you want to move that GetActiveScene method outside of the restartScene method.
Gn
Oh, or the now named IERestartScene method
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
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;
}
Honestly yes and no haha
general vibe is do it badly first, figure it out smartly later
it's very very easy to spend a million years over engineering a mechanic you end up removing for game design reasons haha
ive seen a lot of devs on yt videos talk about that
its what im somewhat doing at this present moment π
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
oh shit rite
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
Which
na literally just like 20f instead of 20
ohhh
IEnumerator IERestartScene(float waitTime = 1.4f)
yield return new WaitForSeconds(waitTime)
oh true can just type it in instead of putting f into the variable
yeah the f is just so visual studio understands you mean a float and not a double, not actually a part of the variable
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
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
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
What do you mean by not appearing? Is it not what you have selected?
well ienumerator is for coroutines right
Ye
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
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
ok
don't sweat about having functions that only have 1 or 2 lines π
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
wym
just try StartCoroutine(IERestartScene)
IEnumerator stuff can be a little odd and quirky
that gives me 3 errors
π
lol
so i cant adjust it externally
it will work
just not modular
unless its something dumb
ok ill ask
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
Youd have to share code my friend
what line is 26
hol up
ill use bin
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
have you used many debug.log's before
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
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
yup
i fuggin hate those icons
debug.logs are so so handy for confirming if the code your working with is actually running
thx will mess around with those
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
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)
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
Code Time π
i wanted to learn to debug stuff
gotta share how you tried to do it
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
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())
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
yup, thats the next part about enums which is cool
instead of just keycode.space
oh?
is the name keycode.space misleading?
wait nvm im confused
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
so the name keycode.space doesnt actually reference the hardware button itself but its more so a true false interface for the input?
yup
gotchaaaaa
noticed that
as soon as you told me it was a variable i was wondering why it was in caps
inconsistency to keep people on their toes perhaps π
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
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
yeah mark brown is fantastic
ill have to find a use case and mess with this
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 π
yup
thats good for organization
its literally just if and else if statements internally, just a way to look pretty
cool
From what I understand, it looks like they are actually jump tables. They assign all options an int and simply jump to the int
But I guess it also comes down to the compiler
This is an interresting read on it:
https://www.codeproject.com/Articles/100473/Something-You-May-Not-Know-About-the-Switch-Statem
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
good to know
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)
might be worth asking in the outside channels friend
threads on discord suck for getting new people to see them
ah