#💻┃code-beginner
1 messages · Page 166 of 1
- Configure your ide
- Do you know the basics of c#?
Sort of but really like this is my first game
Alr
Well I’d reccomend learning the basics, it makes writing your own code and debugging much easier
Also, instead of following an online tutorial, I’d reccomend using unity learn, cause in online tutorials you don’t really learn anything, cause ur just copying whoever’s in the video
That’s what I’d personally do but if an online tutorial works for you, than go ahead, do what’s right for you
Okay that makes sense I have been trying to use unity learn when possible but for specific things I have been using youtube
I made it work by sort of hack
thanks for your help nonetheless
I shifted two vertices out of the plane and made the collider convex, resulting in unfortunately not precise collider mesh, since it overlaps in places, but at least the ray hits it.
Technically I made the mesh collider 3D
Hmm okay so it didn't like a flat mesh?
If anyone would know a better way how to bypass this, please let me know, it would be greatly appreciated as the current sollution is kinda meh.
I think it is more about the new mesh having volume due to the 3d dimension
Yeah that's what I mean
then yes haha
It's not a problem with imported meshes but maybe there's something different when you generate it yourself
yeah
I thought about using sprite
SVG or something
but then I want users to be able to draw two shapes, arrow and a complex line, and the sizing and stuff would be worse than generating it 😄
actually now I think about it and it sucks because the complex shape, when having convex collider, would occupy also the empty space 😐
Just a tip, in case you want to see in real time where your raycast is being blocked, you can see it in inspector of "Event System"
Helps me a lot when I feel like some raycast should detect an object but turns out something else was blocking the ray
It shows the name of object your mouse is hovering over (if it blocks raycast)
may I know where? 😄 is it the selected object?
cause I dont see the thing I hover over
Uh it's like the bottom of the inspector, try pulling the "line" up
Can't describe what it's called
And it shows up only in play mode
Hi everyone, i wanted to know if any of you can see where the problem is, i want that when i click on the button, a panel close for another to open, so here is my code, but the problem is that when i click on the button nothing happen. You can see that the button named 'BoutonOutils' in the TableCraft GameObject don't work, normally when i do that, it should close the 'TableCraft' GameObject and open the 'OutilsCategory' GameObject'. Here is the code :
void Start()
{
isOpen = false;
OutilsBouton = CraftingScreen.transform.Find("BoutonOutils").GetComponent<Button>();
OutilsBouton.onClick.AddListener(delegate
{
OpenOutilsCategory();
});
//Hache
HacheBesoin1 = OutilsScreen.transform.Find("Hache").transform.Find("besoin1").GetComponent<TextMeshProUGUI>();
HacheBesoin2 = OutilsScreen.transform.Find("Hache").transform.Find("besoin2").GetComponent<TextMeshProUGUI>();
HacheBouton = OutilsScreen.transform.Find("Hache").transform.Find("Construire").GetComponent<Button>();
HacheBouton.onClick.AddListener(delegate
{
Construire(PlanHache);
});
}
void OpenOutilsCategory()
{
CraftingScreen.SetActive(false);
OutilsScreen.SetActive(true);
}```
Does it detect the button click at all? As in when you are debugging, via some Debug.Log or IDE debugging?
Also a hint, you you can nest hierarchy finds and use OutilsScreen.transform.Find("Hache/besoin1").GetComponent<TextMeshProUGUI>();
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
when i do this : void OpenOutilsCategory() { Debug.Log("Ouverture de la catégorie Outils"); CraftingScreen.SetActive(false); OutilsScreen.SetActive(true); } It doesn't detect the button and i don't know why
So it does not output the log, correct?
Can I see the button in the unity? Is it interactable and enabled?
Well I see its enabled
yes it's interactable
And the rest of the inspector interface? 😄
Hello, my sprite is not flipping, the code and i dont know why but ive seen something a bit odd and i really dont know why, the sprite renderer in the scrip is not the same as the sprite renderer
Also, are EventSystem and Input Modules present?
I am afraid I have to leave the answering to others then
And you have Input Module correct?
are you talking about the input system ? if it's that then no:
As far as I can tell the FlipSprite script is not even attached
oh might be a good thing to do
ah no i don't have this
but the flipsprite is in the movement sprite tho
If you open the event system while you're running the game, it'll tell you on the bottom window of it what object you're hovering over or interacting with. See what it says when you're trying to click the button, there might be something in front of it taking that click event before it can hit the button
try add it and check if the button works
I am getting this error code for my code, any help would be amazing
when i click on it, the eligibleForClicl become true
ok yea i have separated the flip script to the movements script and it works juste fine thx a lot man !
and does the debug fire the debug message?
"Ouverture de la catégorie Outils"
What? I have no idea what that means. You mean you put the code in the file for the other script? It doesn't work like that
i copy paste the flip class that was on the movement script in antoher script (named flip) with only the flip class on it and it worked just fine
Did you actually have 2 monobehaviour classes in the same script file?
yea that was the dumb thing
ah, yes, that's a no-no, only one Monobehaviour class per script but you can have other POCO's there as well
this is a Unity specific thing not C# in general
no the message dosn't show up
Yeah, something must be off with the listeners or something else, unfortunately I am not sure what else I could do to help for now
yea yea i guess not in c# liek all the langages u can put multiples fonctions in it
thank you for your help
indeed -- this is because Unity references the script asset when you attach a component. it doesn't actually care about the C# class name
i even desactivated the raycast of the image there was on the button but nothing change
That's also why you can freely rename your class without breaking existing components -- as long as you don't rename the script file outside of unity
no, it's because when the Unity devs developed this system they didn't have a fucking clue what they were doing
you can interpret it that way, if you'd like
too many bad design decisions to take it any other way
there's nothing special about script assets; they're just like any other kind of asset
have you tried to check if the button listeners are assigned correctly?
you reference the asset, and the asset is identified by its GUID
as in if nothing is null, sometimes when using Find and other hierarchy stuff I make the mistake of getting nulls
but that'd throw Null Pointer Exception anyway
yep, the whole asset database concept is a pigs ear reminiscent of the windows registry
when you enter debug mode, you can change which script asset a component references. you don't reference a C# class, just like you don't reference the literal data in a PNG or the literal audio data in a wave file
i don't have any null exception error and i did verify this multiple times and it was good
Guys, please help me find the error in the code (this code is needed to control the player’s movement using a controller)
you have not provided any information.
what error. add some debugs
Did you check the link I provided? https://unity.huh.how/debugging
Ok so you still didnt convert the angle to the correct -180...180 range
i swapped it
You didnt use the code example of DeltaAngle I gave you.
Im not saying to use -180 and 180 in your if-statement. It should be -90 and 90
Hello, I was wondering If I call a Method inside a method like this:
// some code here
if (true) {
DoThis();
}
// other code here
}```
Would the "other code here" run if there was actual code after `DoThis()` is done?
The angle you use in the if statement should be the one you get from DeltaAngle @long jacinth
of course
code runs top to bottom, in order.
Aight, thanks
Unity gives this: NullReferenceException: Object reference not set to an instance of an object
there's more to it than that
you are ignoring the filename and line number of the error
so i swap the -90 with the Angle variable
No, swap the eulerAngles.z with that
BTW I have no idea how this https://cdn.discordapp.com/attachments/497874004401586176/1201205614928478380/image.png?ex=65c8f8e7&is=65b683e7&hm=fbc8ebb9576711aef9400878fbea6476da34fb9abfadb4c742d4a4fb69a4be6c& could even compile. Seeing as it is accessing variables that don't exist. Is your code editor configured @ashen coral ?
Judging by the colors it is not configured
https://paste.ofcode.org/34EQzyZPNQJsSfNxQiwkBun
Exception: Cannot add more triangles than the size of the triangles array.
MeshData.AddTriangle (System.Int32 a, System.Int32 b, System.Int32 c) (at Assets/Scripts/MapGeneration/MeshGenerator.cs:69)
MeshGenerator.GenerateTerrainMesh (System.Single[,] heightMap) (at Assets/Scripts/MapGeneration/MeshGenerator.cs:28)
MapGenerator.GenerateMap () (at Assets/Scripts/MapGeneration/MapGenerator.cs:57)
MapGeneratorEditor.OnInspectorGUI () (at Assets/Scripts/Editor/MapGeneratorEditor.cs:23)
UnityEditor.UIElements.InspectorElement+<>c__DisplayClass72_0.<CreateInspectorElementUsingIMGUI>b__0 () (at <97436df440ca462884c5332c1d8ebbe7>:0)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)
Saw a land mass generation video with indepth explanation and all but now I am getting this. when it comes to adding triangles to the mesh
Exactly this
Yep seems pretty clear where things are going wrong:
public void AddTriangle(int a, int b, int c)
{
if (triangleIndex >= triangles.Length)
{
throw new Exception("Cannot add more triangles than the size of the triangles array.");
}```
I added an exception to break it once it reaches the lmax length of the triangle
yes and you have reached the limit
hey im trying to make a ball shoot system like in mini soccer star but whitout the aiming arrow can someone help me make the script?
also its gonna be a mobile game so mobile input
Oh it writes exceptions like errors.!!! I fucking forgot
note that you're adding TWO triangles for every x/y coordinate.
Not only that but every coordinate uses up THREE spaces in the triangle array.
But when you allocated the triangle array you only gave this much space:
triangles = new int[(meshWidth - 1) * (meshHeight - 1)];
Thought my code was wrong
I'm pretty sure that array is at least 6x too small
I think your triangle array size is ~~ 2x~~ 6x? too small
i think it should be new int[meshWidh*meshHeight*6]
since you need 3 spots per triangle and you're doing two triangles for every x/y
Won't it be something like new int[(meshWidh-1)*(meshHeight-1)*6] then. So that it doesn't take count of the externalmost point
in the if statement i swapped out the eulerangles.z
only one of them should be -1
since you're only doing one check of if (x < width - 1)
so new int[(meshWidth - 1) * meshHeight * 6]
Operator '<' cannot be applied to operands of type 'method group' and 'int'
Quaternion.Angle is a static method on the Quaternion class
i started with entities so i created a new project downloaded entities package after this i create a sub scene and a cube but if i press play i dont see the cube at all in the game window do i need to change a setting in the camera or something?
therefore, you're getting this error because you're trying to use the < operator with a method on the left side
I meant replace the whole variable
what is rotation.Angle? That's not a thing friend.
I presume you wanted to just use your Angle variable.
(which shouldn't be capitalized, since it's a local variable)
if(Angle < -90 || Angle > 90)
Notice || instead of &&
Try to understand what you are doing
If you would use &&, it would have to be both <= -90 and >= 90 at the same time
That's not possible now is it
gunText.GetComponent<SpriteRenderer>().flipY = !(Angle < -90 || Angle > 90);
Fixed it changed this
if (x < width - 1 && y < height - 1)
{
meshData.AddTriangle(vertexIndex, vertexIndex + width + 1, vertexIndex + width);
meshData.AddTriangle(vertexIndex + width + 1, vertexIndex, vertexIndex + 1);
}
and this
triangles = new int[meshWidth * meshHeight * 6];
tnks
paetroblue and the gang. thnks
ohh i got it
I realized the mistake. Thank you
thank you guys for helping the gun rotation works perfectly now
i was stupid and didnt realize what i did wrong
Heres a bonus for you to make sense of the angles:
thanks so much
Hello i am trying to make a script for OpenXR Unity game. How do i make it so if a specific game object is picked up then a different specific game object dissapeared. Also if the object is let go off the object that disappeared comes back.
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
Get the Renderer components for both objects and then you can enable/disable them as you please
however how do i check if an item is being grabbed
how can i prevent all methods to be called at the same time inside the RandomlyChooseAttack function? Line 104
that is up to how you code it, collitions, triggers, other, take your pick
did you not read the bot message
i used gdl paste
no you didn't you posted the original code back here
ill be honest. i am pretty bad at programming in c#. idk how that works
time to start learning
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
to start with they are not all called at the same time but..
Update -> EnemyLogic -> RandomlyChooseAttack
So once this has been done you need a bool or something to stop it until the next time you want to do it
hi, im having trouble with a boolean not turning true when i want to ``` public bool ZombieStop = false;
public float speed = 10f;
public float HealthPoints = 5f;
private bool PlantCollide = false;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if(ZombieStop == true){
speed = 0f;
}
else{
speed = 10f;
}
transform.Translate(Vector3.forward * Time.deltaTime * speed);
if(HealthPoints <= 0){
Destroy(gameObject);
}
if(HealthPoints <= 0){
Destroy(gameObject);
}
}
void OnCollisionStay(Collision other){
Debug.Log(other.gameObject.layer);
if(other.gameObject.layer == 7){
HealthPoints = HealthPoints - 1;
Debug.Log("Zombie HealthPoints: " + HealthPoints);
}
if(other.gameObject.layer == 6){
ZombieStop = true;
speed = 0f;
Debug.Log("Zombie should stop");
}
}
void OnCollisionExit(Collision other){
ZombieStop = false;
}
}
i'll create a bool called inRange and turn that bool to true in line 81 instead of calling the RandomlyChooseAttack(); method. Then i'll call RandomlyChooseAttack(); method in an if statement like if(inRange). Something like that? And where should i enter that if statement?
Coming back to this, is there a particular framework you'd recommend? If I'm just building a single, locally-hosted webpage would it be worth just skipping the framework?
Edit: and is there a framework that could provide a visual means of creating the UI, instead of having to hardcore everything?
why canti see the cube in the game window?
the camera isn't pointing at it
soemthing like that, put it in update. also this
if (cooling)
{
CoolDown();
anim.SetBool("DownSlash", false);
anim.SetBool("SideSlash", false);
anim.SetBool("UpSlash", false);
}
doesnt make sense. CoolDown() should be called outsilde of the if
the camera is on point
Anyone know why the UI is doing this? it fixes itself after resizing the editor?
why is it "entities test scene"? Is this ECS/DOTS?
i wanna work with entities for the first time
#1062393052863414313 is the place to ask about it.
it needs to call the CoolDown(); method when the cooling flag is true. It's the cooldown system which prevent the enemy from spamming the attack
@languid spire also it sets the attack animation bools to false otherwise animations get stuck
Hey guys, do kinematic objects interact or overlap one and other?
and static
or do only dynamic objects (rigidbody) collide with each other?
problem is it can still do it whilst cooling is true
so you're turning off the animation immediately
kinematic objects are unstoppable forces/immovable objects
they don't react to any other objects in the scene or forces at all
but they are overlaped by each other?
they're overlapped if you place them in overlapping positions
not really sure how to answer that
they go wherever you tell them to go
okay, what about static?
yes on the last frame. I use an animation event to call the TriggerCooldown method
Static Rigidbody2Ds are placed in the scene and should never move
no, look at this
if (cooling)
{
CoolDown();
anim.SetBool("DownSlash", false);
anim.SetBool("SideSlash", false);
anim.SetBool("UpSlash", false);
}
even if cooling is still true the bools are set to false
to group a bunch of colliders under one physics object
okay, thanks!
yes, animation bools should turn false when cooling bool is true. Bool is turned to false when cooldown method is called. It is intended to work that way
are you asking about when trigger and collision messages occur?
https://unity.huh.how/physics-messages/trigger-matrix-2d
https://unity.huh.how/physics-messages/collision-matrix-2d
these pages show when the events fire
ok, gotcha so this is the problem
else if (attackDistance >= distance && cooling == false)
{
RandomlyChooseAttack();
}
cooling does not get set to true until the anim if finished so RandomlyChooseAttack gets called multiple times
hmm makes sense. Lemme check that
you need to control that wilh another bool set to true in RandomlyChooseAttack and set to false in CoolDown when the timer expires
still dont undestand why this code is not working. i have this script on my button prefab and want the sound to play every time the button is selected
am i not getting something here?
probably missing an interface for it
also why not just use Event Trigger component
i tried it with event trigger, but couldnt get it to work with mouse and controller input. do you perhaps mean the "Select(BaseEventData)"?
yeah you need to implement the ISelectHandler interface
also ISelectHandler will work exactly the same as EventTrigger btw
f.y.i. this tells you it isn't being used
to be fair it would still show that with the interface too
yeah, now everything works
i tryed to create a solution to weapons clipping thru wall and other objects, by rendering then on another camera, but that shows them thru wall as well, any idea how to fix this?
that is a code related channel
this is a code related channel
so ask a code related question 🙂
indeed wrong channel, also you have to switch layers between pickedup and not picked up
oh sorry then,where is rightchanel then?
well #💻┃unity-talk but looks like you need code to solve your issue, unless you make 2 separate objects
eg weapon is in Default layer and then on pickup you do weaponObj.gameObject.layer = LayerMask.NameToLayer("WeaponRenderer");
thx
need to set it back to none is there a code
afaik 0 should work
hi, can anyone tell me what is the difference between purple and pink filed in unity object explorer?
i hve to use that hff.... but the code doesnt see it, i can use other fields but not that one
!ide
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code
• JetBrains Rider
• Other/None
thanks
@grizzled pagoda do the visual studio one
so you can see the errors
in visual studio while typing
Not familiar with the window, but that might be because it's private?
as you can see i can select "fpvfieldofview"
Can you show the code for hffkblekiic (which is a mouthful by the way. Is there a reason these variables are keyboard mashes?)
what does this error mean?
type is not a supported string value
UnityEditor.RetainedMode:UpdateSchedulers ()
Check the stack trace and see if any of it is in code you write. If not it's probably a unity editor error and you can probably fix it with a restart
what is this, it doesn't look like a Unity project
Oh, modding. Can't talk about that here
really? ah sorry
You'll have to find the official discussion channel of the game, wherever it is
And yeah the garbled variable names is probably because of an obfuscator on the source code
Can entities have colliders on them or would that decrease performance
restarted and gone, ty
alright, thanks for help <33
what
Are while loops actually used by anyone? I mean i always use either if statements or for loops
yes
is there an example where you must use a while loop instead of for or if?
while loops are extremely common, yes
All the time
I've been programming for 2 years and i only tried to use it once, my game crashed, now i never use them and im okay
You can use for and while for all loops interchangeably, it's just awkward sometimes
Okay so while loop doesnt have special usage that a for loop cant do
if(drag)
{
//enable elsewhere
lineSystem.SetActive(true);
currentMousePosition = Input.mousePosition; // start updating currentPosition
float dragDistance = Vector3.Distance(initialMousePosition,currentMousePosition);
if(dragDistance > dragThreshold)
{
initialMousePosition = currentMousePosition; // reset new position for next drag check
}
if(Input.GetMouseButtonUp(0))
{
lineSystem.SetActive(false);
drag = false;
initialMousePosition = currentMousePosition;
}
}``` heres an example of one of my if loops
i have exit conditions like drag = false..
now if i was a better coder id use a while loop instead
this seems fine to me
how is that a loop?
happens every frame doesnt it?
ya
then the if is irrelevant, the Update is the loop
yes but the if breaks out of the loop.
if is not a looping statement
you said one of my if loops
okay steve
Anyway, just proving my point that while loops are not neccessary
ok, try that in a Coroutine
i could make it a coroutine 🤔
go on then
What is a coroutine?
Technically no loops are ever necessary because goto exists
i dissagree
while loops are just cleaner than for loops in some circumstances @cunning locust . For example:
Queue<int> queue = new() { 1, 3, 4, 5, 6 };
while (queue.Count > 0) {
int next = queue.Dequeue();
print(next);
}```
A for loop would be a but less elegant here...
```cs
for ( ; queue.Count > 0; ) {
int next = queue.Dequeue();
print(next);
}```
a for loop is extremely neccessary sometimes
But you could just use goto statements.
foreach, yes, for no
They're tools to have in your toolbox, and discounting one because you can massage another into the same use case isn't relevant
You should still learn how to use them
List<int> list = new() { 1, 2, 3, 4, 5 };
IEnumerator<int> enumerator = list.GetEnumerator();
while (enumerator.MoveNext()) {
int current = enumerator.Current;
print(current);
}```
^ Here's how to write `foreach` as a `while` loop
Does visual studio have a snippet shortcut?
Like when I press a shortcut key, it instantly pastes a for loop
or a switch
They appear in the completion list as you type
for, then Tab to complete
For enums, it does
don't worry about using shortcuts, learn how to write code yourself
Else, it cannot decide for you
Yeah i know all of these, i just can't bother to type them out all of the time
does system.random still work?
apparently you don't
public Update()
{
if (Input.GetMouseButtonDown(0))
{
// Set drag to true when the mouse button is pressed
drag = true;
// Start the coroutine
StartCoroutine(DragCoroutine());
}
if(Input.GetMouseButtonUp(0))
{
drag = false;
}
}
IEnumerator DragCoroutine()
{
// Enable the line system when starting the drag
if (!lineSystem.activeSelf)
{
lineSystem.SetActive(true);
}
while (drag)
{
currentMousePosition = Input.mousePosition;
float dragDistance = Vector3.Distance(initialMousePosition, currentMousePosition);
if (dragDistance > dragThreshold)
{
// Update LineRenderer during drag
UpdateLineRenderer();
// Reset new position for the next drag check
initialMousePosition = currentMousePosition;
}
yield return null;
}
// Disable the line system when releasing the mouse button
lineSystem.SetActive(false);
initialMousePosition = currentMousePosition;
}```
coroutine 🤔
what happened to system.random?
Where did I give you this impression?
now you have a while
Still exists, and will always exist
what would happen to it
in just about everything you have said
but i dont want a coroutine.. so ill just use my if() conditionals until it isnt feasible
im tryna use it and it isnt working
then you are using it wrong
I just got curious if a while loop is even needed, and it turns out it's not. So i was correct
its debateable as noticeable
if you dont need to use a while loop, dont use one.
but they aren't unneeded in no form
Hello, I'm making a 2d game and in a level I want to see nothing that everything looks black, all black and when the character puts a torch you can see around the torch, you can see what is the map, what I mean is that everything looks black and the light of the torch let you see the map, but I've been trying things and I can not do it, anyone knows how it could be done?
you can make fortnite? 👀
while is the most flexible type of loop. All the other loops are built on top of it
this sounds accurate ^
You can also write English sentences without the letter "e" but there's not good reason to do so.
what you are saying makes absolutely 0 sense
you can make fortnite without any for loop aswell
All im saying, if while loop wen't extinct, it wouldnt limit me in any way
you can make anything without using any looping construct other than label: goto label. Should you? NO
for you != useless
You will look back at yourself saying this in 5 years and laugh
Wrong, because most loops in C# compile to while loops
I doubt it? Loops are necessary
Your code wouldn't compile at all lol
not really.. u can emulate loops with if conditionals and booleans
why do you need a for if you can make the same logic in while
thinking in your logic
for sounds unneeded to me
i mean techinally.. ye
As I said earlier, there are several well known languages which have no loop constructs at all
its one or the other.
A for loop automatically can set a limit to the loop
which while loop can't
i mean it can, but
while loop can put a bool inside the brackets
of course it can
- i dont use while loops b/c im not good enough to use em yet *
i get tired of locking up my project
I think a for loop is more advanced than a while loop
Yes so when you have an unknown number of iterations that's why you would use while loops
why is it more advanced
you can emulate a loop with goto. You can't emulate a loop with if
it looks more confusing XD
it looks more confusing to you = its more advanced?
this is just c#, goto doesn't exist in other languages as far as i know
ya, i meant more *with the use of it being nested in a Unity loop (like update)
I mean is it not? Lets be fr here
i dont code outside of unity unfortunately
Yea I feel the same about multiplication, why is it so confusing. We should just use addition, remove multiplication since it is clearly bloat
well yeah but then there's still al oop, it's just inside the Unity engine and not in your code.
no its one of the basic things you learn
goto exists in ALL languages, loops don't
facts! lol idk i just jumped in
okay you just proved its kinda ponitless talking to you now 😄
goto is the basis of all loops. Loops are built on jmp style assembly instructions which are just goto
Goto exists in literally every language and is one of the most fundamental control flow commands which all other kinds of loops and conditionals eventually compile to
I would strongly dissagree as i have years of experiance in gamemaker
idiot
he's trolling
🤣 i cant
at this point xd
This is clearly a kid
I was hoping to have a nice discusion over a topic, yalls reaction is not it.
I'm just debating.
can't have a nice discusion if you are closed to answers
and can't take facts as a.. facts lol
Likely more of a #archived-lighting question
Well it was a calm friendly debate on my end.
I would strongly disagree, i have years of experience in psychology
hey guys, I just started out with unity and I was following this udemy course I got, I'm trying to make one of these hyper casual games just to learn the basics, here's a tiny bit of the player animation code. It works fine between idle and running, but I wanted to also make the player walk based on the "intensity" of the joystick, based on how far off it is, if just a tiny bit, he'd walk. I did alter the code for that but the value I was checking wasn't perfectly consistent so most of the time he'd jigger between run and walk when just pulling the joystick to a half point, if I do an if for lets say magnite > 0.5, usually walking is 0 to 0.5 and running is 0.5 to 1, but there would be odd values in between, running could have a random .4 and walking could have a random .6
any advice on what value I should be checking (I'm starting to think the vector magnitude isnt the correct one xd) or how I can get the speed to do this?
except in a debate both sides need to know what they are talking about, you very clearly do not
Look at the #854851968446365696 on how to ask. No one can help by just this alone
Ah okay this wasnt exactly what i was talking about, but now i get your point. I only wanted to say that gamemaker doesnt have a built in function goto for us users to use.
gamemaker is not a computer language, it is a system
I'm guessing you're getting that move vector from input somewhere, which means it might have smoothing on it
Yes therefor i withdraw my previous statements regarding the goto
little missunderstanding on my part
Game maker uses a scripting language and is not a compilable programming language. Internally, the code game maker compiles your GML to does have goto
three fundamentals of loops
jmp
jnz
jz
every piece of looping code you ever write will boil down to one of these asm goto instructions
That's why gamemaker shouldnt be a starting point in programming games, this type of information is extremely helpful now that i've moved to unity
Neved heard of goto before yesterday 🤣
then your education has been sorely lacking
It's not like you would hear about in doing unity solo anyways, you only hear about it because these people told you
You dont really use goto directly yourself in c#
I mean when you learn programming, someone tells you the information that you want to learn
that just confuses me now.
Thought it's commonly used by unity developers
You dont explicitly type goto in your code
ive only ever seen Goto: logic in memes (relating to Unity)
Goto isn't commonly used at all in Unity
one of the reasons that C# has so many different loop constructs is so that you dont need to use gotos yourself.
In fact if you follow strict OOP JSP principles goto should never be used by an application programmer
If i recall correctly, when i was talking to someone here about switch statements, they said that goto should be used for some sort of flow yadda yadda
the break statement is technically a goto
No, people are bringing it up because it'd be absurd to write all of your loops in gotos, just like it's absurd to try to write all of your loops in only for
complicated switch statements if its goto'ing around and about but yea, breaks, returns, etc
but it does not specify the "where"
it just breaks out of the switch
You can actually goto case n in switch statements
thats why u structure ur logic in a coherent way
the where is implicit. end of scope
u shoudn't need to tell it specifically where to go
Yea that's what i ment
While i cannot imagine a case where this would be usefull for me, it sounds like a neat feature which might be usefull
i need to write more switch statements.. my logic never gets that robust, hopefully someday ill transcend
people dont realize. case is the same as label. that is why it terminats with a :
the more tools in ur toolchest is the important part
even if u dont use it.. knowing something is available to u puts u ahead of the ones that dont
absolutely, you dont need to know the exact signature of all API's you just need to know they exist
imagine before the internet was what it is now.. u'd have to have a bookshelf at ur ready 😄
now u can just "beep: boop:" what ur hunting
look at my bookshelfs
I have hundreds of coding and sdk manuals
when people coded before internet their books were already read 100 times before
any that u would swear by?
in which field do you specialize?
today, no, much better info on the net if you know how to search
im always on the lookout for an extra ebook i can store
All of them
What a wild difference in times, during my time in university I seriously never bought a single textbook.
So like.. networking, front end, back end, discord bots
cyber hacking
yep and much much more
pretty sure he can do it all
cyber security
50 years is a long time to learn this shit
Finance and Banking
selling ur soul
it's also more fun than game dev
That must be country specific.. in my country the money is alright in banking, but making a successful game >>>
Capitalism! Hoorah!
I'm international, I'll work for anyone who pays me enough
..and he's bilingual 👀
multilingual if you please
i knew it!
is Steve Smith Steve Jobs by any chance
my mate Jobs is dead, I'm not
if you say so
whatever you say Jobs..
Does anyone have a hard time on YouTube tutorials
very very rarely
never
if i do, the solution is in the comments
the trick to youtube tutorials is to follow it exactly pay attention to what they click (they might not narrate every click they make)
dont be afraid to pause, and rewatch
usually they wont post a video that doesnt work..
no, the trick with YT tutorials is NOT TO WATCH YT TUTORIALS because most of them are crap
You can't just generalize like that
bet
imo youtube tutorials are best at exposing you to ideas, mechanics, and etc
Well itll work for the 10 seconds of gameplay shown, then you realize its impossible to develop this further
its up to you to take those and research and fill in the blanks
99% of YT turorials are made by people to make money or self promote, nothing else. They generally know nothing
if u dont.. ur just copying what they make.
So what? Should i just read the whole c# manual to learn something?
eventually yes, but thats an extreme..
no ones asking u to read the entire manual to figure out what a transform is
You dont get dropped off in mexico and learn the entire mexican language on the first encounter with a local..
What about the 10+ hour full course tutorials?
The youtubers that actually know what they're talking about, dont really make step by step guides that you'll be able to learn from. They will briefly mention an entire concept, because they're just telling you how they implemented a feature. If you dont understand the existing tutorials you're looking at who show you the code line by line, you 100% will not understand the few good tutorials that exist
same with learning a computer language..
Tarodev!
never tried any of those.. u mean the payed ones?
like Udemy courses?
Not necessarily, but sure. For example rn im watching a free one on youtube, 7 hours long full course
Take Brackey, heralded as the king of Unity YT tutorials by many, his code is so full of errors it's untrue and what he 'teaches' is rubbish
you'll learn alot of concepts from it.. but they all wont just click
you'll still have to do some follow-up on ur own
To be fair, 4 hours in i just got over the loops, which are basically the same in any language
My bad, 2 hours in.
basics aren't all that exciting
where can i get help for scripting errors?
here
I'm sure there's a debugger in unity
oh lol
I feel like the best way to learn stuff is to try using it in a project yk
absolutely correct.. you learn the most by doing
like a lot of stuff just doesn't make sense if you don't do it yourself
i never watch anything without a project opened up lol
yeah but I mean
you don't learn stuff by blindly copying it
you learn it by applying it yourself
I could dissagree with this
thats the step where you get those click moments..
When you are in school all you do is copy from the board.
"eureka moments" is a better term
i have like 2 scripts, one script checks if the player is touched and then uses the method of another script to show a game over ui
everytime i reference the method, i get this error: Object reference not set to an instance of an object
gameManager is not assigned
You didn't assign this variable
it needs to be assigned in the inspector - or elsewhere
oh damm
u just told Unity that you have a GameManager class u want to be named gameManager.. but u never assigned it so unity doesn't know which one
that means that gameManager is not assigned
Yeah refferencing stuff was confusing to me at first for sure
go to the player object
and drag the game manager object into the slot provided under your player script component
the scripts are in the assets
Sure, you can memorise stuff by copying, but to use it effectively in your own projects requires some amount of practice
do i have to tie it with a script?
like a prefab asset?
i mean game Object
yes, but if you have a script component on your player the public properties of te script will be exposed
yea u drag the gameobject containing the "GameManager" script
so i just create a gameObject for the sole purpose of storing the script?
it has to be in the scene to run properly since its a monobehaviour
ok
so ya, just make an empty gameobject name it something relateable, drop the gamemanager on it
and use that to get ur reference
my KillBlock script is in a prefab tho
Does c# have variables with different scopes? Can i make an enum or a macro which could be accessed in any script for example?
I thought public just means i can edit it via the unity editor
if u need that script from somewhere outside the prefab ull have to instantiate it first and then use a GetComponent<> or something similar to grab the reference from it once its in the scene
the components tab
it means that and what i said..
and the game Manager is inside the ui
a private field can be shown in the inspector.. if u use
[SerializedField] private float myFloat;
Interesting, maybe i shouldnt overuse public variables then.
and that wont be accessable outside the class u wrote it in
BUT will be visible in teh inspector
that's usefull to know, thank you!
absolutely not.. u should get into the rhythm now of only using public variables that u want to use externally..
if not and u still want to assign it via the inspctor use [SerializedField] private
On a different topic, im learning about coroutines and i dont see the difference between them and functions..
StartCoroutine(ExecuteSomething());
IEnumerator ExecuteSomething()
{
yield return new WaitForSeconds(2f);
print("Executed.");
}
well for starters you can't Wait in a regular function
so that code would never work in a regular function
I see, alright, is there more to it?
since my game manager and kill block scripts are both in parts, i can get the Game manager script from finding its path?
and how would i find this path?
i only use them for Delays.. but theres alot more to them
it's kinda weird that you can't wait outside the coroutine.
https://docs.unity3d.com/ScriptReference/Object.FindObjectsOfType.html
you can use this to find specific components/scripts
Hmm so what about structs and arrays?
can I make a custom Wait() function by passing in a function as a parameter of a coroutine?
IEnumerator ExecuteSomething( int func, int time)
{
yield return new WaitForSeconds(time);
func();
}
u can use a coroutine just like a function in the sense of passing in variables yea
yea u can do that, not sure about the func() part.. but i know u can pass in ints and stuff
yes
but func would need to be a delegate type
for example Action
ye but the script is inside GameOverScreen, is there no way of just Canvas.GameOverScreen.getcomponnent<GameManager>?
Yeah im particuraly interested in passing a function as an argument
if an animaiton has "loop" ticket off and has finished playing/is at last frame, would this method still return true?
ya u can do that.. if u know exactly what object its on.. and its GetComponent btw
punctuation matters
how do i reference the object path?
u still need a reference to that tho.. u cant just type out the name's
delegate type?
same as u did earlier.. u pass it into a variable.. but if ur gonna do that why wouldnt u just pass in the GameManager directly
IEnumerator WaitThenExecute(float delay, Action a) {
yield return new WaitForSeconds(delay);
a();
}
// Use it like this:
StartCoroutine(WaitThenExecute(2.5f, () => Debug.Log("Done waiting")));```
like that?
yes delegates are C#'s version of function pointers. A delegate type is.. a type of delegate
if the gameManager is attached to that exact objecct (the same one the script is on)
System.Action aka Action is a delegate type that returns void and takes no parameters
the kill block is actually in the prefab
do i need to do gameObject.Parent?
it that a thing?
.parent is a thing yes
Makes sense
I thought i could just pass an array as an argument
to do the same
but i realised I can't even get arrays to work in c# 💀
Array arr = [ 1, 2 ,3]
struct struc {1 , 2 }
Well yea that's not the syntax,
it. It's all there on the docs
that aint even close to c#
you could actually look up the syntax 😉
I don't see how an array would do the same as a delegate though
struct one should work..
not even close
Are you a Python user by chance?
The collection initialiser may make confuse things if you looked it up
The array initialisation is honestly almost correct in modern c#
im used to gamemaker language
it's almost correct except that the type is wrong
i did this
public struct struc
{
int i = 1;
}
Apparently gamemaker is like javascript and c? I was assuming C from how you tried to declare the struct
guys, how do I get the rb.velocity.magnitude in 3D? I was used to get this value on 2D but it is not working on 3D
but i cant drag the gameObject to the script
would it be possible to include time.deltatime into this? or would it still run equally no matter the performance?
yeah
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
@grizzled pagoda
It uses Time already, there's no need for delta time
it runs equally because it takes time into account
👍
Mathf.Sin(Time.time)
Show what you tried/more context. Magnitude exists on the Vector3 so this should be fine
Trust me that code was not how i WANTED to declare the struct 💀
I just tried
"return Mathf.Abs(rb.velocity.magnitude);"
but is returning zero
Then the value is 0
the obj is moving
You don't need to abs a magnitude, it's always positive.
How are you moving it
https://gdl.space/simatudizu.cpp hi could anyone help me with wave spawning? the wave starts out at 2, the wavecount however is set to 0 at the start though
I'm moving the transform
So you're nver changing velocity
the rigidbody does not count this way?
oh, that's the problem
Also, please don't cross-post
i solved it, i had to change something from my kill block spawner to attach the game Manager to the public var in the killblock script
sounds like ur getting it
could anyone look at this
Hey I have this error when trying to build my game, no issues when running in edit mode
What does it mean it has a different serialization layout?
Yeah, when I run the built game
what is Card
My script
well, as the pre-prorocesor directive saying
anything under Auxiliary will work only in the editor
Yeah, I just added it, was having this error without this if as well
yea cuz it's something related to the editor
Yeah, it contains only editor runtime methods
some kind of asset, i dint know what it is
yea so obviously

you cannot use this in build xd
But I don't want to
I can even delete this Auxiliary class completely and try bulding my game again
then do it
Usually this means you did something like:
#if UNITY_EDITOR
public int SomeField;
#endif```
what is Auxiliary?
Contains a few helpful methods during development but it's not needed in the final build, even when I commented it out the build still didn't work
What is IAmGood?
Where are things like displayName and username coming from?
public interface IAmGood
{
public bool IsGood { get; }
}
```An interface, nothing special
Why I can't send a file here? You can open it in full view or scroll on Discord
I can't download files on this computer
it's a work computer
Discord truncates it
There's no need to download it, you have this icon to view it
It doesn't show all
totally can see the entire file...
and forget mobile, who just sees "download attachment" and thats all
Really? I don't see that
Anyway I want to see the Card script
Aight, hold on
ah didnt even realize that was a thing, that looked like decoration to me lol
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
Possibly due to OnValidate being inside a preprocessor?
It's commented out
Try restarting the editor maybe? I'm not immediately seeing any issue
Not everyone can. It doesn't work on mobile, and if the file is too large, it cuts off . . .
Alright, got it
Still the same, restarted editor and rebuilt it and the same issue
Maybe should I get rid of [SerializeField] attributes? Will that solve the issue?
You're using Visual Studio, right? or VSCode?
Yeah
Horrendous code style btw
@tender breach
#💻┃code-beginner message
#💻┃code-beginner message
Please press Ctrl+A, Ctrl+K, Ctrl+D in that order then post the code again
You're not going to post code here if you're going to continue to refuse to format.
Your post is deleted until you do so.
I'm trying to create an interaction with my player and NPC capsule but no output in the console to show I touched the capsule.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerInteract : MonoBehaviour
{
private void Update() {
if (Input.GetKeyDown(KeyCode.E)) {
float interactRange = 5f;
Collider[] colliderArray = Physics.OverlapSphere(transform.position, interactRange);
foreach (Collider collider in colliderArray) {
Debug.Log(collider);
}
}
}
}
so Debug.log is not printing anything ?
have you confirmed that this code is even running?
Right, debug is not printing and the code is placed onto my player
Either the code isn't running at all or there are no colliders within 5 units of the player.
can you screenshot the object you placed this script on
full scene view no crop pls
Or the code is running but you're not pressing E
is your keyboard even plugged in?
Nvm, I got the code working. Second time it's happen where i had to restart Unity
Maybe it reverted to different save and it fixed it. idk.
{
_isGrounded = Physics.Raycast(groundCheck.position, Vector3.down, 0.05f, _groundLayerMask);
Vector2 moveDir = _moveAction.ReadValue<Vector2>();
Vector3 vel = _rigidBody.velocity;
vel.x = moveDir.x;
vel.z = moveDir.y;
Vector3 a = transform.right * vel.x;
Vector3 b = transform.forward * vel.z;
Vector3 c = new Vector3(0f, 1/100000000, 0f);
_rigidBody.velocity = (a + b + c) * speed;
//_rigidBody.velocity = vel;
private void OnJump(InputAction.CallbackContext context)
{
if(_isGrounded)
_rigidBody.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
}
Hey guys, could someone help me real quick? I'm trying to make a fps character controller but I can't manage to get the jump and movement to work together.
If I use the velocity that is commented out the player can jump but his movement doesnt follow the camera's direction, and if I use the line on top, the player moves fine but doesnt jump
👀 lol low blow
idk maybe OP forgot and was typing through discord phone 😆
weird way to write 0 lol
yeah im going crazy atp, I think it has something to do with the Y coordinate being 0 but idk I've been stuck for 8 hours already
1/100000000 is 0 btw; you are using integer division
Actually it wasn't restart. My E key got stuck. I realised this after changing the key in the code to different letter. I need to clean my keyboard XD
you also never seem to keep the y velocity, and just discard vel.y
Thank you for help!
I feel the pain, my keyboard usb insert is broken if i wobble cable it stops working my unity character starts indefinitely walking
I'm just trying different things to see if a miracle occurs, this is what happens when I use one line or the another
velocity overrides AddForce
if you wanna jump with velocity you have to well, assign y velocity
Well AddForce modifies the velocity
it does but if you force velocity directly it barely does anything, only 1 frame cause of impulse prob
hence the tiny hop in vid
i see
do you have any suggestion on how could I approach it? I'm trying another thing rn imma see if it works
are you set on building your own controller?
there are also premade ones like KCC or the unity regular CC
i was just trying to build it my self because I didnt find any that workds properly on the asset store
in what sense ?
I downloaded a few from there and there was editor errors
so I just tried to make one myself
the unity one is good to start with and easy to extend, if you want a solid one premade with features use the Kinematic CC.
guaranteed those have no errors lol
just clear it
And it comes back each time I play
im going to try it then
whats the unity one¿
you tried restart unity ?
or reset layout
oh i see thx, I saw that one but i thought it was for mobile games
seems the window took a poo
I'm going to try the KCC
its compatible with mobile
https://gdl.space/simatudizu.cpp could anyone look at this real quick? It automatically spawns 2 zombies even though it should only spawn one at the start
you call SpawnZombie every frame for a quarter of a second
and only increment the counter after a delay
what's up with the reloading domain thing taking 15 mins to load
also if you want a specific Zombie from the prefab itself, have the Zombie be its own script and spawn sprefab as Zombie.
Put like an enum that you change on instantiation to determine what zombie it will be, or maybe use scriptable objects (cleaner but more advanced)
seems to be , I dont have it 😮
restart ur unity
when domain reloading gets super slow good to restart the machine (even) and it'll speed back up
also if it is or getting progressevily worse might be worth deleting and rebuilding library
^ this too.. but usually a good restart will help ya out..
library getting full of nonsense
yeah lots of cache xD
I could be wrong but feels like , even when the assets are no longer there or packages the cache still present from b4
Playmode without Domain Reload is amazing
its how the engine Should be by default imo
ya, but u have to remember to manually trigger it
but static ruins it ig
right?
lol okay, i was confused there a minute 😄
soo much clutter now
ohh snap
u sir are correct
every other table like UI has disable/enabling columns, Wtf is up with this bs
🤔 is unity vc really this shit? 3 people for free?
gotta remake that money back somehow for buying out Plastic
also this cloud stuff now
not sure thats just for version control, or if we can store our projects in the cloud now
that'd be a SSD saver for real
also when you make a new project you have to like select an account which is annoying when you have 3 for example
why no permanent option
they have monkeys designing this hub fr
you would still want the project on your pc. Its the same as uploading a project to git then deleting it from your pc
basically, just use git. its always better
ya, the only problem i have with git is understanding the LFS
you just enable it, anything else is normal from there
i think thats the abbreviation, but ive had one project break my repo, b/c it had lots of audio files
not sure how or what i did
but i would get some weird error it would get stuck on 99%
are you using a GUI or commandline
Fork
to do the LFS setup i think u have to use the terminal
i had to look it up everytime
you dont even need to understand it, you can get away with just sharing the files through other means. Unless you have assets that are really up there in the GB
iirc its the best way yea through CLI
i removed all the audio and made a new repo
the old one wont allow me to change anything on it
audio files individually shouldnt be that large
it gets hung up on 99%, if i get around to it ill try to read what it was
how big are these audio files individually
🤔
thats what i was thinking too
b/c the way i understand it its big single files
is what cant be over 100mb
they're just basic wav files for gunfire and stuff
not any over 5mb i bet
OR it possibly could be a PSD thats hidden in there
they are uncompressed
but i dont think any of those are over 100mb either
hmm it usually tell you which file failed
is there a scriptableobject equivalent of getcomponent?
like can i get an array of all SOs of type level for example
what exactly are you expecting that to do? SOs are not attached to any other objects
im storing my level data in scriptable objects and i just wanna grab all the SOs and put them in a list
just drag them into a serialized list in the inspector
otherwise you could put them into a Resources folder and use Resources.Load or addressables or something
trying to look at tutorials for randomly generated 3D terrain but I noticed every tutorial I look at creates a new mesh instead of using Unitys' built in terrain features. Is there an explanation for this? I'm worried about creating my own mesh because of the work that would entail going forward (creating UVs, randomly placed vegetation, etc) that are simple to use with Unitys' built in terrain features.
thats weird, no logs?
im pretty sure its still broken b/c i have zipped files of this repo now on my HD
thats all i would get.. it would hang up on 99% and that same fatal error
have you tried GitHub Desktop , for a GUI its pretty decent
no tree/timeline view though 😦
i used to use Github Desktop but fork is really good
its only this repo thats broken
and i thought it was all the audio.. fun fact i finally got it updated by pushing every folder individually
I bet there is a log somewhere with more info
yea, this was dated last year.. i'll try to push it again later for shits and giggles
not sure ive ever seen it done using unity's terrain
You can with heightmaps and all that
the one I currently use uses terrain, but it only generates small hills and I wanted to do more lol
but I bet generating your own mesh is ofc always more flexible and you can cut it in chunks for performance
that urs?
doesnt unity allow u to use heightmaps with their terrain component?
might be a way to do it
they do
it once was.. ive deleted it since
b/c i really dont understand how it works
i kinda just copied it 😄
oh haha still nice to use in stuff other then open world
i bet for static map gameplay would be nice
aren't those just meshes? so like mesh collider no?
prob kill perfomance tho
unless its static prob gets as one big mesh
idk how that works with runtime gen tho
What
you should probably not be using it for mutable data
levels is a scriptable gameobject
Unless you know what you are doing
But i doubt it
Since you ask such thing
Don't use SO for saving system
That is not a way to go
im just using it cus it makes it easier for me to set level data on the fly
jesus store your path in a variable at least
Don't ever use SO for save&load system
if you change one you change all instances
think of it like a static class/vars
i mean, if ur using JSON u could just make a class/struct
How to properly make this script on editor only monobehaviour? https://gdl.space/vedufademi.cs
Like Dictionary<Level, LevelSavedStatistics>
Then you can map each statistics to each level
yeah i think that makes more sense, thank you!
Even better if you make the dictionary serializable
yeah i be doing that with json stuff i think
i have an idea on what to do now
thanks
Place it in an editor folder . . .
just encapsulate the editor namespace/methods
no need to encapsulate the whole class
that blocks you from adding itto any gameobject
with the ifeditor
editor folder and monobehaviour are quite not friendly with each other
can just compile it out too be using one of those directives
if its on gameobject unity serialized it and it expects it to be there
but you put #if editor on the whole class
hmm turnin it into an empty class if!Editor?
Then just use the if editor directive . . .
that looks ugly, but ig better
the scene camera isnt the same thing s the game camera is it?
Im using a render feature for outlines and they're displayed in the gameview but not the sceneview,
its not a big issue or problem, im just being curious
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
[ExecuteInEditMode]
public class DisconnectPrefab : MonoBehaviour
{
public string RenameTo;
#if UNITY_EDITOR
void Update()
{
gameObject.name = RenameTo;
if (PrefabUtility.GetPrefabType(gameObject) == PrefabType.PrefabInstance)
PrefabUtility.DisconnectPrefabInstance(this.gameObject);
DestroyImmediate(this);
}
#endif
}```
or just the whole update method
hmm, even if i dont need the whole file?
then dont put it on a gameobject
unity expects it there
that's why serialization error, dont match
did it, it feels itchy that there's no better way for it though 🥹
if i have a dictionary and try and add to the same key twice, does it override they value for the key?
Intellisense worked yesterday in vscode, but today it's not. Also, when I type [ctrl + shift +p] >omnisharp no commands for omnisharp pops up and no omnisharp logs are present. My dotnet version is 6.0.412. I installed the latest mac mono version, tried regenerating unity project files, setting omnisharp.useModernNet to false, and uninstalled and reinstalled c# and unity extensions.
Any ideas? My C# log:
Using dotnet configured on PATH
Dotnet path: /usr/local/share/dotnet/dotnet
Activating C# + C# Dev Kit + C# IntelliCode...
waiting for named pipe information from server...
[stdout] {"pipeName":"/var/folders/m6/kv19br757x316_pn4twdxn7h0000gn/T/451100eb.sock"}
received named pipe information from server
attempting to connect client to server...
client has connected to server
[Info - 3:35:33 PM] [Program] Language server initialized
it will error
what is purpose of this script exactly does it need to be on gameobject?
No, they are different . . .
it breaks prefab instance for prefabs as you spawn it on scene
helpful for buttons
ill just use a custom gizmo on things that use the Outline renderer 👍
that'll be sufficient
not sure what you mean by "breaks"
sounds like it can just be an Editor script or Editor window script
Does anyone know why I keep getting this error? "Assets/Resources/Scripts/Utility/AudioManager.cs(45,11): error CS1061: 'Sound' does not contain a definition for 'source' and no accessible extension method 'source' accepting a first argument of type 'Sound' could be found (are you missing a using directive or an assembly reference?)"
when you place it from project folder, it automatically is black, instead of blue (prefab connected)
Sound doesn't have a source
my good btw
ik that's what it means, but im confused, because I specified a source variable for Sound
how do you assign source?
if its hidden in the inspector how have you assigned it to a valid audiosource?
I assigned source in the other script, in the foreach loop
why would this not change the animation curve value?
just for extra info, here is the debug, you can clearly see there is a weight value
It depends how you add. Calling the Add method results in an argument exception. If accessing the key to assign the value, this will override the previous value or assign the value if the key doesn't exist: dictionary[key] = value . . .
alr i just removed HideInSpector
the errors got removed
i have no clue why
yea i have no idea why either
using UnityEngine;
public class AudioManager : MonoBehaviour
{
public static AudioManager Instance { get; private set; }
private AudioSource audioSource;
private void Awake()
{
if(Instance != null && Instance != this)
{
Destroy(this);
}
else
{
Instance = this;
audioSource = GetComponent<AudioSource>();
DontDestroyOnLoad(gameObject);
}
}
// Play a single audio clip
public void PlayClip(AudioClip clip,float volume = 1f)
{
audioSource.volume = volume;
audioSource.PlayOneShot(clip);
}
}```
thought it would jsut hide it in the inspector, i wanted it public so other scripts could access it easily but I didn't want it to be accessed from the inspector
heres my audiomanager.. i just pass in a clip and a volume and play it. ive never seen a class called Sound like u have, interesting to me lol
i use NaughtyAttributes and the ReadOnly attribute
it helps sometimes esp when debugging
I like using a ReadOnly attribute as well. It's good to have . . .
Some people create a Sound class to assign settings to a specific sound, or a Sound array with configured sounds to use . . .
An SO is even better . . .
ya, but did u see his setup? i dont see why the error
#💻┃code-beginner message
#💻┃code-beginner message
The problem I’m having is that the spawning and wave count isn’t updating accordingly
does the error come back if you add the attribute back? could just be that unity didnt recompile when you tested it
You should learn events btw
How would those help btw
im not very familiar with the HideInInspector attrib but i dont understand why it would say sound doesnt have a source when it appears it does
and then work when its removed
yea it does
But regardless when you remove the item cal method on spawned that sets the spawneras references . When you destroy an enemy you cal method on spawner/counter to remove entry from list