#π»βcode-beginner
1 messages Β· Page 172 of 1
Both of those are going to require some self-motivated learning
the player is not moving
So does everyone
Probably because your code is lit up with errors
ik i want to know what are those errors
Are you getting errors in Unity or just in the IDE
just ide
Then you probably need to regenerate project files. It's on the page where you set your IDE in Unity on that guide you were following a while ago for configuring it
!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.
ya i dont have that i didnt even wanna take this class casue this nor cyber was the ide of it i wanna to learn
So if you have just admitted you don't want to learn and are doing this to pass a class you didn't want to take in the first place, why should I help you
I've given you plenty of ways to find the answer but you are just refusing to learn the basics to the point you can even understand my answers
I'm not writing the code for you. Come back when you've done the bare-bones basics and can understand the answers you're given
wow ight i wasnt expting you to write me the code just explain in witch the basic context i have to use it and ya i might not want to take the class but i was still willing to learn it and when did i ever refused your help i refused the videos because they were for syntax not what i needed
I did explain the basic context. You call SetColor on a material. You had no variable meshRenderer, I asked you what you wanted to get the material of
ya you literally just said the exact same thing the site said and i said i didnt under stand the site and what they were saying and that i needed you to dumb it down or give me an example of it being used because i wasnt sure how to apply set color to my context and my use
You call SetColor on a material.
You can get a material from a renderer.
This is the answer. But you literally do not know the language so you don't know the answer. I cannot help you if you do not know the first thing about C# syntax. I'm not going to write it for you and I'm not going to give you a personal tutoring session on how code works when there's plenty of resources out there for you to read on your own. Go learn how to write C# code and then come back when you understand how to type literally anything into a script and have it compile
i do understand these are scripts i made and also i never asked you t do it for me nor do i want u to i wanted an example cause i would rather have a visual example i can base off of and i dont need you to tutor me because if i would have asked you to while i might not know the language im currently trying to learn it and one the new things was the set color and i didnt understand how to use it because i had no pervious work with material colors
there are plenty of visual examples of how to create a variable, assign a reference to it, and call a method on it in each of those scripts
None of your issues have to do with how to work with colors
your issues are "not knowing how to call a function" and "not knowing what a variable is"
which have absolutely nothing to do with materials or colors
You are wandering around Seoul, getting angry that everyone is giving you directions in Korean
You do not speak the language to understand the help you're being given
You cannot have a variable that is the same name as the class
damn lemme check
ya but i didnt now how to use it with the set color
the error means exactly what it says. you cannot have a variable, method or property called Reload inside a class or struct called Reload
If you know how to use it with other things, then do that
then change the function to SetColor
Chill, ain't this channel for beginners?
exactly
had a method named same as class
there is absolutely nothing special about the SetColor method that would make it work any differently than calling any other method on another object. do yourself a favor and stop wasting your time and learn how c# works
ty gang
There's a difference between "I am a beginner" and "Write my code for me because I refuse to learn"
This has been going on for nearly an hour after I answered the question
yes, but a basic understanding of how to actually write code is still expected.
why da game doesnt understand Time.time?
I get that but even while I ask some question it feels hostile. Just chill for a bit
you have a variable called Time
Because float does not have a property named time
dis what i got
get your !IDE configured π
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
OMFG THIS CHAT IS NOOB PEOPLE WHO ARE TRYING TO LEARN I WAS TRYING TO AND WHEN I SAID I DIDNT UNDERSTAND THE FIRST TIME YOU EXPLAIN IT WHY WOULD YOU TRY 5 MORE TIMES THE EXACT SAME WAY
once it is configured and the error is underlined you'll probably see your mistake
whats an IDE
your code editor
i use VS
congrats. get it configured
stop wasting your time and go learn the basics of C#
How does me learning coding help me change my basic color? I just want to change the color so it different from the red, purple, green.
stop wasting your time and go learn the basics of C#
#π»βcode-beginner message
Here is me, an hour ago, telling you to click on the link that would answer your question.
Have you done it yet
How is arguing about how you don't want to learn C# going to help you program something in C#
https://gdl.space/uwibupitoj.cs
https://gdl.space/osejavojav.cpp
looking to make my bullets shoot in the direction my cursor is on screen, instead there just shooting towards the actually cursor on the canvas in game, pls halp
no because that is to learn methods no what i needed was help with how to use the set color like what would a basic line look like with it in there and the only reason why im arguing is because if this is the code BEGINNER that means im some what new to codding and i need help not redirect link to videos explaining something i already know
You are not going to avoid learning how to call a method or set a variable. There is no shortcut. There is no getting around it. Do the tutorials in the pins
does this belong in a different code channel?
You have not even gotten to the part where you need to know how to change a color
no. have some patience, and maybe provide more details about what is actually happening
mb
I'm done with this. Come back when you know how to write code that compiles. I will not be responding after this
OMFG im avoiding cause thats not what i need help with i understand the basics i dont understand in what context should the set color should be used is all you had to do is send me a single line using it so i can see what it needs to look like
the context for which you would use the SetColor method on a material is when you would want to set a material's color
basically im wanting the bullets to shoot from the tip of my gun in the direction the mouse is pointing, instead they are just shooting up towards where the canvas is, all help is appreciated π
why are you calling Destroy in Update?
btw i was just missing this
log what was hit by the raycast and its position. and the position of shootPoint
no the fuck you weren't
idk i dont get any errors now
and your IDE is still unconfigured
until you realize your code probably doesn't do whatever you were expecting it to
andsaw what was missing
ig ill try it and see
you can search the hierarchy with t:PlayerCharSelection
also not really a code question
debugging doesnt really tell me why its going up to the canvas, just be telling me where the ray hit, no matter what i try it still shoots up towards canvas, ty for the help tho
getting that information absolutely will tell you that though
to destroy bullets
how exactly?
it just tells me location ray hit π¦
obviously knowing what was hit and where it is as well as the starting location will provide you with the context for why the direction is the way it is
yes. exactly.
dumbass thats why im here is to learn what i need this is the BEGINNER chat and what both you two have sent me links for is not what need i have repeatedly said that i need help with set color not methods or variables i understand what they are and that you guys need to send me an example because the ones that were provided on the unity site for set code didnt make sense and that i needed them in a different context not that i need what it done ik it sets the color of a material and if you didnt want to help send me to a channel on discord that can and will instead of being stuck up and think that people in a BEGINNER should know every thing and try blaming them that they dont know stuff
stop wasting your time and go learn the basics of C#
im thinking its the way the canvas is, maybe needs to be world space and set in front of the player? i get what your saying tho π
bro just leave
why would the canvas have anything to do with it unless your raycast is actually hitting something on the canvas
This is the beginner chat help me with the basics
stop wasting your time and go learn the basics of C#
ye this piece of code did not work
hey guys, im using a premade package called kinematic charachter controller to set up my player controller and im facing some issues.
as you can see the Y rotation of the player is not acting like how it should.
any ideas where the issue is? im guessing it has something to do with the ProjectOnPlane things in the code snippet down below but i cant figure it out.
code snippet related to setting the player rotation:
//Calculate camera direction and rotation on the character plane
Vector3 cameraPlanarDirection = Vector3.ProjectOnPlane(targetCamRot * Vector3.forward, Motor.CharacterUp).normalized;
if (cameraPlanarDirection.sqrMagnitude == 0f)
{
cameraPlanarDirection = Vector3.ProjectOnPlane(targetCamRot * Vector3.up, Motor.CharacterUp).normalized;
}
Quaternion cameraPlanarRotation = Quaternion.LookRotation(cameraPlanarDirection, Motor.CharacterUp);
if (cameraPlanarDirection.sqrMagnitude == 0f)
{
cameraPlanarDirection = Vector3.ProjectOnPlane(targetCamRot * Vector3.up, Motor.CharacterUp).normalized;
}
all the code i found related to setting CharachterUp seen in the previos code snipper:
public Vector3 CharacterUp { get { return _characterUp; } }
private Vector3 _characterUp;
...
_characterUp = _transientRotation * _cachedWorldUp;
because the cursor is a sprite of a reticle thats on the canvas, should i be doing it another way?
You keep saying that like this isnβt the basics chat
stop wasting your time and go learn the basics of C#
this is where i set the targetCamRot used in the first code snippet
// NOTE : Do NOT Use time.Deltatime, beacuse the mouse input that is coming from the new input system is already a delta. more info :
https://unity.huh.how/programming/input/built-in-input/mouse-delta-time
// Rotate the camera based on mouse input
float mouseX = lookInput.x * sensitivity;
float mouseY = lookInput.y * sensitivity;
//we use the lookInput values to rotate the camera horizontally and vertically using the transform.Rotate() and Quaternion.Euler() functions
//respectively.
rotation.x -= mouseY;
rotation.x = Mathf.Clamp(rotation.x, -90f, 90f);
rotation.y += mouseX;
camHolder.transform.localRotation = Quaternion.Euler(rotation.x, 0f, 0f);
Character.targetCamRot = rotation.y;
that shouldn't matter if your canvas is in screenspace because you are getting a world space ray from it using Camera.main.ScreenPointToRay.
seriously just print the information i suggested you print, show what it prints and maybe we can figure this out.
your refusal to do any debugging at this point is putting me off of attempting to help you
and stop making assumptions about the issue. you need to verify what is happening. hence the instructions to print useful information like what is being hit, where it is, and where the bullet originates from
is your IDE configured yet
i did the debugging, what i was saying was that it was only showing where the ray hit, you would need that info to help me?
my dude, i cannot see your screen. i have no information about what is actually happening except for what you tell me. how can i help you debug your issue if you refuse to provide the information that we are literally attempting to debug
im asking if you want that info π
what part of "show it" leaves that up to interpretation?
im having a rly weird bug in vs
you wake up on the wrong side of bed today? ive sat here and seen how youve treated everyone poorly yet held my tounge cause you have been "trying" to be helpfull, you need to learn manners before attempting to help people, all im seeing is you being rude and treating other poorly
where only some stuff just is refusing to autocomplete
make sure it is configured !vscode π
!vscode
You set the context. Wouldn't you use it when you need to set the color of the material? I just looked at the docs for Material.SetColor. It explains that and gives an example of its use . . .
my vscode was working fine last time i used it
its just started doing this randomly
no.. not yet but i dont understand why i need to change or configure anything, literally worked without issue in my other unity project
but ill read through the site now
having configured tools is a requirement of receiving help here
wait do i need unity 2021
An onslaught of people unwilling to do basic debugging or follow instructions tends to have that effect on people
it will also underline your errors for you and provide syntax highlighting, and auto complete
cos my game is on 2020
Ya but i didnt understand what it was saying becasue it wasnt in the context i need
ah yeah, the new c# plugin requires 2021 to work properly. you might be able to find some guides for using an older version with the million other extensions you need to get it working π€·ββοΈ
yes it does that in my other unity project
doesnt mean be rude, this is a help channel, not a "I KnOw HOw tO CoDE BeTtER" channel
but not with the scripts from this one
or just switch to visual studio which is much better and less likely to break
is there a way to move the game to 2021
oh
So when someone is helping you and asks for the result of your logs, you should probably, y'know, share them so they can help you
if it were properly configured it would work for every project. it's not a per-project thing
Have you tried explaining what context you need to change a material's color? No one will know what that is, as I'm not sure I understand what you mean . . .
bump.
then why do it multiple times, like Destroy the same object every frame?
My point
would it be worth having every action logged?
can you be more specific about what you mean
like every time a button is pressed, a scene is loaded, specific collisions occur
that's really up to you π€·ββοΈ
if you think that would be useful information to have then do it. if you feel it would just clutter the console/log files then don't
You can if you want. That's the observer pattern for any/every action you want to track . . .
if i were to add audio for a button press to multiple buttons, would i add that audio to every button individually?
nah, just call the Play method on the AudioSource from each of the buttons. let them all reference the same source
I would use inputsystem, and also make a separate singleton to make button sounds. Unless you want to tie the sound to a specific action happening.
which is probably what you want
like to play Jump SFX only when you jump, and not just whenever you press jump
so i need to create a new object and add an audio source in there for it to be referenced
i mean you will need an audiosource either way
That depends on how you set up the interaction. A MonoBehaviour script would need an audio clip added to each instance attached to a GameObject. If using an SO, it would contain the audio clip, and you would drag the SO into a variable slot on a MonoBehaviour . . .
what do you mean by SO?
Short for ScriptableObject . . .
π
As you see from all of our responses, there are multiple ways to create this functionality . . .
which way would you say is the simplest
Depends entirely on the use case. Something simple may be like having a monobehaviour that lets you plug in the audioclip, then all the buttons just pass that clip to an audio source and play. but then if you want to add functionality where you can play different sounds from a list of clips, a SO wouldve been better from the start.
Simple may make it tedious to add functionality later
ok
It depends on your use case and current experience . . .
I'm trying to instantiate a sprite, and the sprite is being parented to another sprite with scale 1, 1, 1. That sprite is parented to a canvas set to Screen Space Camera. The new sprite, the one generated by instantiating, is generated at scale 240, 240, 240.
Is it a sprite or an image
because SpriteRenderers shouldn't be children of a canvas
Okay, just making sure
TextureType, rather
Can you show the inspector of the prefab you're spawning?
and I haven't touched the Pixels Per Unit, the scale itself in editor reads 240
first image is spawned item, second is raw prefab
First off, you should probably spawn the object directly as a child of the object you want it to be a child of, rather than spawning it at the top level, then setting the parent, that could cause some scale problems
Try using the 2nd argument for SetParent. Is the canvas scaled at all?
the canvas is screenspace camera, I can't control the scale
I can try that, just a moment
what if i want to use the other handlers? how do i add on more?
that fixed my scale problem, thank you
sprite.enabled = true;
speed = 3;
Vector3 newtemp = myTransform.position + Vector3.down * speed * Time.fixedDeltaTime;
myRigidbody.MovePosition(newtemp);``` can any one tell me why this is moving so fast. I mean its like the speed of a bullet
even if i change speed to 1 its same speed
followup question though, I need to reparent the image if I move it from one inventory grid to another. if I set the parent from grid 1 to grid 2, will it balloon to 240 again?
Yes. It's classes you can't do that with. Interfaces are fine
It should be fine, as long as they're in the same canvas
Or another canvas of the same size
Hey I've been having a problem that I just haven't been able to figure out. If I exlpain the proble, would I be able to get help in this channel
What happens if you just comment out the MovePosition entirely
yh same speed
So the code you've shared is 100% irrelevant
hmmm yes...
I'm trying to align my player game object with the surface it's standing on so that it's always rotated towards the normal of the surface (makes the player look perpendicular to surface). My character can move well on slopes (increase and decrease top speed on slopes as well as keep momentum) but it doesn't rotate yet. I've been trying lots of different ways to do this but I haven't been able to achieve this (problems that arise are: the camera jitters and changes angle (not settings) of my cinemachine, no changes in rotation, wonky rotation, and immediate jitter rotation followed by instantaneous reset of normal rotation (at least that's what I think happens, it's a bit too fast for me to tell confidently) ).
The code I currently have is this:
private void SurfaceAllignment()
{
RaycastHit hit;
if (Physics.Raycast(transform.position, Vector3.down, out hit, playerHeight * 0.5f + 0.2f, whatIsGround))
{
// Calculate the target rotation based on the ground normal
Quaternion targetRotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
// Gradually rotate the player towards the target rotation using Slerp
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, rotationSpeed * Time.deltaTime);
}
}
I've tried different things like RotateTowards and such, but the problems persist.
I'm starting to think that it may have to do with me using cinemachine. I think it may be messing with the rotation. It may not, but I can't really think of anything else. Does anyone know if there's something I'm missing?
are you using a CharacterController?
no, rigidbody
I put that method in a seperate script and placed it in the player capsule (child object of player. GFX holder), the problem still remains :/ I did notice one thing tho. I disabled said script and manually rotated the object during play time. This gave the same effect as when the script was enabled. So now I'm thinking it's most likely the camera script. These are the only scripts after all
if the issue is camera jittering, then you might be updating the camera on the wrong time step
I'm not really messing with the camera itself tbh, The freelook cinemachine has a script but the script just switches the orientation of the player (player has another child called orientation which dictates whats forward. It's for movement)
whats the event for when a button is selected? like iPointerselect or whatever
Right, but my code itself is the issue
So it use to be 2D its now 3D thr rigidbody has gravity. can that speed it up?
If the issue that your object is moving down very fast, then gravity could certainly be a factor
if i was to turn gravity off would movetowards still work in a 3d envirmoment?
They have nothing to do with each other
Gravity is not a requirement to set an object's position
heres the cinemachine script in case you wanna see it. But like I said, I don't think it actually does anything to the jittering of the player rotation. Player has rigidbody, where my movement script is located, along with 2 child objects. One is the GFX holder, which is just a fancy way of saying the capsule (later I'll replace it with an actual 3d model), and the other is the orientation. which is rotated through this script to determine the forward (movement direction based on camera forward).
!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.
I tried sending it as code, but the message is too long so I had to send it as a text file
gee, that's a shame. too bad there are no instructions for sending large code blocks
does anyone know how to make falling speed gaining velocity further down while falling?
private void customGravity()
{
if (rb != null)
{
rb.velocity += Vector3.down * gravityStrength * Time.deltaTime;
}
}
do i have to put in in square or something
if you have a dynamic rigidbody, why are you calculating gravity manually? why not just let it do it automatically for you
becasue forcemode.accelerate doesnt work for some reason
I'm using them, I just haven't used those b4 so it's taking me a sec.
...what?
i stole source physics and i thing the friction calculation is also effecting y value
and i dont want to change anything because it might not work π
whats the name of the event system for controller click? ipointerclickhandler doesnt work
@slender nymph https://gdl.space/iluhucocok.cs
you are literally replying to a link that contains all of the event system interfaces. just look?
i have looked, but i cant see anything thats relevant hence my asking
well you have access to exactly the same link i would be looking at so π€·ββοΈ
found it, it was submit
boxfriend, have you looked at the link
Does this argument that is passed inout var networkedClientdeclare a variable right there and then?
what is this syntax called?
it's an out parameter so, yes, it is declaring a variable for the life of the scope of the if statement
hi, I can't figure this out, can someone help me?
I have a boolean private static bool x;
which then I use for a method call (from another class) CreateAxisOverlay.CreateX(x);
that method for now just sets the boolean value to true: c# public static void CreateX(bool x) { xAxisInitialized = true; }
but then if I try to use the boolean in the "original class" it returns false, it only returns true inside the called method, how can I get the method to change the value of the one boolean I passed as parameter?
with the "original class" I mean the one in which I called the method
btw I'm not sure if you say invoke or call for a method
if(roomController.rooms>0)
{
foreach(Transform roomConnLoc in roomConncections)
{
int roomRand = Random.Range(1,4);
switch(roomRand)
{
case 1:
Instantiate(room1, roomConnLoc.position, Quaternion.identity);
roomConncections.Remove(roomConnLoc);
roomController.rooms -=1;
break;
case 2:
Instantiate(room2, roomConnLoc.position, Quaternion.identity);
roomConncections.Remove(roomConnLoc);
roomController.rooms -=1;
break;
case 3:
Instantiate(room3, roomConnLoc.position, Quaternion.identity);
roomConncections.Remove(roomConnLoc);
roomController.rooms -=1;
break;
default:
Instantiate(room1, roomConnLoc.position, Quaternion.identity);
roomConncections.Remove(roomConnLoc);
roomController.rooms -=1;
break;
}
}
}``` can someone help? the foreach seems to not work, only one transform is being removed from the list
A static variable belongs to the class itself. There is only one x in the entire program.
Are you getting any errors in your console
So that pretty much explains it
one for every thing that spawns
You cannot modify a list you are looping over
yup yup, but could I modify the value then without hardcoding something like OriginalClass.x = true?
aha, thanks
ill find a workaround then
I'm pretty new to using static variables, methods and all that so I'm not fully sure how it works yet :[
That's how you access a static member
yup, but is there any way to change it's value by passing it as a parameter to a method (located in another class), or is that not the way to go about it? :[
I cannot get touchPhase.ended or .canceled to trigger, any idea what I am doing wrong?
began works fine
bool is a value type. You don't "pass" it. When you set a variable to it, it just copies the state of that variable at that moment
where does this code live?
it is attached to the main camera, where the logic for the mouse controls for the same systems also lives
I mean where in the script?
show the rest of the code
sprite.enabled = true;
Vector3 newtemp = myTransform.position + Vector3.down * speed * Time.fixedDeltaTime;
newtemp.x = 0;
newtemp.z = 0;
myRigidbody.MovePosition(newtemp);``` how do i make that go in the y direction only but i dont want to x and z to be rest. thinking like dropping a bomb from the sky the x and z will be the position it dropped but and only move towards at y
ooo so its like it makes a copy of the value in the method itself?, so I guess the only choice is to access the bool directly right?
Are you basically trying to do this right now?
public class Caller
{
public static bool x;
public void Call()
{
Creator.CreateX(x);
}
}
public class Creator
{
public static void CreateX(bool x)
{
// Set "passed" static x bool from Caller to true
}
}
actually nvm how would i work around that? i cant add them to a temp list and remove them after, i need them removed instantly
yup yup
So... gravity?
yes but gravity makes it move to fast and want to control the speed
Then you would just add force down. Gravity is basically just calling AddForce(Vector3.down * 9.81f)
Disable gravity and then do this manually with a smaller number
So does add force ignore x and z?
Add force adds force
in whatever direction you give it
thanks ``` var sprite = GetComponent<SpriteRenderer>();
sprite.enabled = true;
Vector3 newtemp = myTransform.position + Vector3.down * speed * Time.fixedDeltaTime;
myRigidbody.AddForce(newtemp * speed);``` no shoots up in the air. do i also have to turn on the gravity on the rigid body?
Why are you using a position as a direction
i thought i would not and add force would push in directio
sorry, realized I cropped it incorrectly as your request
this is currently the entire script contents
Either pass it as a ref or out or return the value and assign it in the calling class
When you make a call to a method, the passed variables get copied. In case of value types, well - you copy only the value. It's not the same variable but a local copy of it. In case of reference types (classes) you also make a local copy, but the way classes work is that they hold a reference to the actual data instead of holding it directly - so it's fine to pass classes and modify their fields since they point to (reference) the original data, but for value types you gotta do it differently.
var sprite = GetComponent<SpriteRenderer>();
sprite.enabled = true;
myRigidbody.AddForce(Vector3.down * speed); like so?
Are you sure the code is running? And it's not just exiting the function immediately if selectedItemGrid is null
if so still moving left and right on the way down
Then something else is moving it left or right
positive. I get "touch began" logs at the beginning of every touch. selectedItemGrid is only null if the pointer is outside the grid area.
Either pass it as a ref or out or
Okay, so the issue is that it's not getting the "ended"
that's probably because you only check for the touch phase ending if the touch count is above 0. If you release it, then the touch count is 0, and it never reaches that code. You should probably put your "touch ended" outside that condition
why not print touch.phase to see what's going on
Debug.Log($"Touch phase is {touch.phase}");```
if I do that, I get a null error because I'm trying to read the 0 index of GetTouch when the array contains nothing
You wouldn't need to get the specific touch, you know that there's none. If you had a touch last frame, and you don't have any this time, then you've released the touch
the last frames of a touch event are always either Stationary or Moving, no Ended
Unity remote app
oh that's why
Samsung Galaxy S10
try in the editor itself
Unity Remote is crappy
especially when it comes to touch handling
ah
or try a dev build
Simulator editor is still not running an ended event
can you reccomend how to do this, checking the last frame? I can't read touch.ended on a null
would it be something like this?
would switching it for a for loop work?
You'd use a boolean, set it to true when the touch begins. If that bool is true, but there are no touches, then it's been released. You don't need to check for touch.ended. You can infer the touch ended by there having been a "begin", and there currently being no touch input
editor is running more jankily, always reads stationary even when moving
Do you have Collapse turned on in your console?
so like this?
no
if(roomController.rooms>0)
Β Β Β Β Β Β Β {
Β Β Β Β Β Β Β Β Β Β Β for(int i =0; i<roomConnections.length;i++)
Β Β Β Β Β Β Β Β Β Β Β {
Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β int roomRand = Random.Range(1,4);
Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β switch(roomRand)
Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β {
Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β case 1:
Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Instantiate(room1, i.position, Quaternion.identity);
Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β roomConncections.Remove(i);
Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β roomController.rooms -=1;
Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β break;
Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β case 2:
Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Instantiate(room2, i.position, Quaternion.identity);
Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β roomConncections.Remove(i);
Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β roomController.rooms -=1;
Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β break;
Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β case 3:
Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Instantiate(room3, i.position, Quaternion.identity);
Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β roomConncections.Remove(i);
Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β roomController.rooms -=1;
Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β break;
Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β default:
Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Instantiate(room1, i.position, Quaternion.identity);
Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β roomConncections.Remove(i);
Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β roomController.rooms -=1;
Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β break;
Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β }
Β Β Β Β Β Β Β Β Β Β Β }
Β Β Β Β Β Β Β }``` something like this? (wrote it on my phone so something will deff not work as it is but you get the idea)
what are you trying to do exactly
why remove them inside the loop
just do the loop and roomConncetions.Clear(); at the end
Also no need to triplicate your code like this
Thanks it was the parent that was moving. Thanks for your help
I currently have it written like this, but it will only capture the first touch ended event and no subsequent ones
wait i am big dumb, i dont need to remove them at all. for some reason i thought that if i didnt remove them the foreach will be stuck in a loop. why
Are you just trying to iterate over them in a random order?
doesn't matter the order, basically if theres a connection for a mew room then add a room to that
put the rooms in an array
get rid of the switch
in the future id rather use a percentage based system rather than the switch
with the rooms in an array then you can just do this:
int roomRand = Random.Range(0,rooms.Length);
Instantiate(rooms[i], roomConnLoc.position, Quaternion.identity);
roomConncections.Remove(roomConnLoc);
roomController.rooms -=1;```
no need for switch at all
As for a percentage based system just look up weighted selection algorithm - commonly used for loot tables but you can use it here for the rooms too
alr ty
Hey guys, I'm trying to detect if there is a collision with any object on a certain layer, but even though I *visually *see the raycast colliding (with the correct object, with the correct layerMask), it's still not detecting any collision. Here's my code any ideas?
for each element in array
if(rand_num < element.probablity)
select and break
rand_num = rand_num - element.probability``` something like this right?
something like that yes
alr
but it's more like rand(0, sum_of_all_probabilities)
better thought of as "weights" really
let's say you have items with weights 3, 8, and 5.
so you do rand(0, 16) (16 is the sum of all the weights)
Let's say the random number picked is 7.
Then in the loop you do:
first item - weight is 3
7 < 3 ? no
so 7 = 7 - 3 = 4
second item - weight is 8
4 < 8 ? yes
so you pick the second item```
Any way to do something similar to on trigger enter when none of my colliders(trigger, and the object that will pass through it) have a rigidbody?
My players physics are custom and handled via a script so it dosnt have a rigidbody, but i still need triggers.
Physics.OverlapXXX
If you have moving objects with colliders though,m they should really have a rigidbody
Oh! Didn't know thats a thing. Ill check it out
Like i said, custom physics. Im using the kinematic charachter controller package which handles evreything like pushing objects you collide with around, gravity, air drag and etc
Also its just unneded overhead
And performance cost
but now you're adding even more performance cost by doing your own physics queries
pretty sure KCC uses a Kinematic Rigidbody anyway
I dont think so, i cant see a rb component on my gameobject, even with debug mode enabled in my inspector
For some reason, I can't seem to get a very simple text display to work. I have a text UI element named TextBox and a script named DisplayText which is attached to a game object. My understanding is that I need to drag TextBox from the hierarchy to the component on the game object but I'm not able to.
is it a prefab you're dragging to from hierarchy ?
Nope, just a game object wit hthe DisplayText script attached.
or maybe the types don't match at all.
{
public Text TextBox;
public string textToDisplay = "My Text";
void Start()
{
TextBox.text = textToDisplay;
}
}```
and you have TextMeshPro component as your UI?
TextBox is a from the UI/Text - Text Mesh Pro option in the dropdown
yes types dont match
I've looked at a couple of guides and really don't see why this isn't working.
Touch Ended will only run reliably on the first instance of the game running, and I cannot figure out why
because its the wrong type
Meaning that the 'Text - TMP' is different than just 'Text'?
TextMeshProUGUI vs Text
yes
use TMP_Text or TextMeshProUGUI
There we go. π Thanks much.
Is it normal that I don't have a standard Text option in the UI dropdown? I only have the TMP version.
Yes
I'm sure Unity will get around to properly integrating TMP and fix all the weird third-party plugin naming and feel of it all any decade now
I think it's a rite of passage basically everyone has to go through to realise Text is not actually text (well, it is, but not the one you thought it was)
a good youtube playlist to learn basic of physiscs for unity?
Whatβs wrong with the docs?
I have a question regarding the Scriptable Object.
here is my plan: I have buttons in my clicker game that are different upgrades. for instance I have a +1 (reward) per tap. if the player presses this the cost should go up on the upgrade and how many you have owned. this is basically the same mechanic for every button, but with slightly faster upgrades like 1+ (reward) per second, or +10 (reward) per second. could I make this in a scriptable object, or should I just use normal code to make this happen? I am reusing them, but I am unsure if this is even worth going for. if it is, can someone also provide me some tips? because I do know how to do it without scriptable objects, but just not with the scriptable objects. thanks for all the help I can get!
Hey, I am trying to make the player allow to move a little in the air but does not exceed the maximum speed limit that he can move at. My problem here is that when the character is moving faster then that speed, the speed would stay the same and will not allow the player to move in the air. Here is my code:
if (Math.Abs(rb.velocityX) <= maxRunningSpeed){
rb.AddForce(new Vector2(direction * speed_mid_air, rb.velocity.y));
}
else if(Math.Abs(rb.velocityX) > maxRunningSpeed){
rb.velocity = new Vector2(direction * Math.Max(maxRunningSpeed,initialHorizontalSpeed), rb.velocity.y);
}```
I am pretty sure that it is because of my if statement, but I just can't seem to have an simple idea to fix this. Can someone help?
Use https://docs.unity3d.com/ScriptReference/Vector2.ClampMagnitude.html and don't do if/else
hmm, it doesn't have an example of how to use it
Do you need one?
am i missing something or is this a bad example from chatgpt? im just tryina figure out what mathf.min does, and if it returns the lower value between 2 variables.. wouldnt it just.. well.. return the lower value there, even if its under the preferred min height?
The thing is, I am kind of confused to what the distance is
if you've a small limited pool of these buttons then I'd just write those values onto a script, but if this list of upgrades can expand tens to hundreds, then you can consider scriptable objects since they are pretty quick to set up
it goes into billions eventually, but I dont really know how to use scriptable objects, if we are talking changing info.
and I dont know if scriptable objects will influence my current saving system
Where do you see "distance"?
and I mean the vallues not the upgrades, they will be at like 20 -25 hopefully
ChatGPT is wrong as usual, it sucks shit
Stop using LLMs to learn unless you want to be lied to by a dumb autocomplete robot
oh sorry I was looking at another link to know what the length is...
here ```Vector2 ClampMagnitude(Vector2 vector, float maxLength);```` the maxLength
That would be the maximum speed you wish to allow. I guess maybe if you want it only for the x axis you should be using Mathf.Clamp on the X axis only
if it's billions then I assume you're generating them, so perhaps SOs aren't what you're looking for
But Max won't work for leftwards velocity.
okay, thank you
you can do it in combination of SOs like perhaps option profiles for generating them
what does that mean?
damn
whats an LLM tho
maybe use them for the start values of the upgrades and then later they get replaces with what the user inputs and what it gets later from the save files
liar liar machine
large language model
for big things yes, for small fixes it is a meh, like a meh it will probably work
Except that it continually is shown here that it doesn't work
"probably" isn't something I want when I'm learning
also depents the prompt, you have to be very clear
it's just bad with unity
hello everyone, how are you?
I am new to Unity and I am still learning a lot of things... let me know if this is not the right channel to ask for help.
I have an Animator Controller with one animation for my UI(initial menu), I created a New state in animator controller to become the default state and a trigger for the transition between "empty default state" and "Closing" state, it is firing after I click a button and works fine!
But when I try to LoadScene again(come back to the main menu scene), and click the same button, it looks like both states are "Stuck" and nothing happens...
Anyone know what I could do to fix this?
It's also against our #πβcode-of-conduct
We ask that you do not:
- β’ Use unverified AI-generated responses in questions or answers.
oh dang
here, I amde the changes, but it it doesn't look like it's working
Vector2.ClampMagnitude(new Vector2(maxRunningSpeed,17),maxRunningSpeed);
if (Math.Abs(rb.velocityX) <= maxRunningSpeed){
rb.AddForce(new Vector2(direction * speed_mid_air, rb.velocity.y));
}
}```
like you can actually get some legit code using it with glsl, but once you add any unity macros and method calls, it spews out a bunch of shader garbage with hlsl
What it's good for is generating a whole bunch of vaguely legitimate looking text
async void Update()
{
await Awaitable.MainThreadAsync();
await Awaitable.BackgroundThreadAsync();
}
```Hey, what is the difference between these two methods? Is that something I can use to ensure other async methods have completed before I move on?
They're for switching between the main and background thread.
Move on where/what?
You can't ensure that other async methods are complete with this.
async Awaitable TimerStart(float startPoint)
{
while(true)
{
// doing some other stuff here
try
{
await Awaitable.WaitForSecondsAsync(1, destroyCancellationToken);
}
catch(OperationCanceledException e)
{
Debug.Log("Coroutine canceled successfully: " + e.Message);
}
catch(Exception e)
{
Debug.LogError(e.Message);
}
}
}
```Alright. Well, I have this method that I call once and it keeps looping forever during game play, and when I want to stop the game it'd be good to ensure this method completed first before I entirely exit the game
Aight, so I'd try catch entire TimerStart() ?
I'm not having this conversation again
Aight, thanks
Just return from it in the cancellation catch..?π€·ββοΈ
hello everyone, how are you?
I am new to Unity and I am still learning a lot of things... let me know if this is not the right channel to ask for help.
I have an Animator Controller with one animation for my UI(initial menu), I created a New state in animator controller to become the default state and a trigger for the transition between "empty default state" and "Closing" state, it is firing after I click a button and works fine!
But when I try to LoadScene again(come back to the main menu scene), and click the same button, it looks like both states are "Stuck" and nothing happens...
Anyone know what I could do to fix this?
Or break out of the loop and it will end naturally.
Lmao, really just return; ? I didn't think about it, yeah, but I need first to move try-catch out to the calling method and there I can return;, thanks a lot! 
What states are stuck? And are the parameters changing?
Well, it's just a method. And you end methods by returning from them.
That's right
idk, maybe async/await stuff blinded me and I forgot I can just return; in the catch statement
Im tryina make an object that moves towards the player (player = blue) (movement path = yellow) have a new movement path (red) (so a sort of "reflect" vibe) when hitting the player, im trying to do it with moving the object, rather than with a rigidbody n stuff, and this is my method
tho like as soon as it bounces the Y pos goes wild, talking about -200 as soon as it hits the player, anyone got any tips?
can someone explain this line to me step-by-step
it's kinda glazed over in the course
that's a for loop.
the example on the page I just linked is nearly identical to your code.
we cant see what any of these values are. you should do some debugging to find out why this is reaching negative values very quickly. Print out the values or use the debugger to see what they are line by line
A simpler way would just be using rigidbody though, or an animation
subtracting the square of deltaTime makes no sense
this kind of looks like a kinematic equation of motion
but those use elapsed time
i was assuming the goal was some upside down quadratic equation raised slightly
which would follow -x^2 + some X
hm but that'd be + a constant actually so yea idk what the goal is here. Likely just magic numbers
oki i think i get it now
so
"for (int i = 0; i < 3; i++)"
translates to
"i is worth 0, if it's worth less than 3, increase i's value by 1"
so for arrays it goes through the list one-by-one using that
right?
not exactly: it's not just that it checks if i < 3 and increments i if that's true
if i < 3, the loop body runs
after the loop body is done, it increments i
then it checks again if i < 3
once i < 3 it stops working?
you mean once i < 3 is false?
oki thank you Fen this helps a lot
This is quite true, though.
It increments the index value, i, until it's not smaller than the array's length
if the array has 5 elements, i will be 0, then 1, then 2, then 3, then 4
it will then be incremented to 5
this will cause the condition to fail, so the loop stops running
it's an incorrect implementation of this equation of motion:
r = rβ + vβ * t + 1/2 * a * tΒ²
This formula is only necessary if you want to compute exactly where an object will be at a specific point in time.
you generally just do iterative methods in a game (i.e. you use the current velocity and position to calculate a new velocity and position every frame)
when I am back to the scene, this is the current state of the animator
when I tap the button, it simply does not run the closing animation
But it already worked previously(before I leave the Scene for the first time)
Does the Close parameter trigger when you tab the button?
yes
But it looks consumed? Did it transition to Closing and back?
it does not, nothing happens, only in the animator tab it is changed to "Closing" State
So it does change to the Closing state?
yes, but the animation does not happen
Even when the issue occurs
What does the animation clip do?
oh, I think I figured it out....
I just ResetTrigger in Start function and it looks like it is working
Not sure if it should be like that(maintain state of the animator even when I leave the Scene)
Assuming the object with the animator is destroyed, it shouldn't maintain any state.
it should be destroyed... but the button that fires the trigger is a prefab, do you think it can be the problem?
but, thanks anyway!!
Unless you're modifying the prefab and not it's instance, there shouldn't be a problem.
I feel like this should be easy and yet I can't seem to figure it out... how do get an objects script component? When I make an object into a prefab, it removes the script that it should be pulling info from and sharing info with
Can you not just use get component on a script or am I missing something?
You can use GetComponent to get a MonoBehaviour, yes.
I assume that it removes references to scene objects. Since prefabs are not tied to any specific scene, they can't maintain a reference to objects inside a scene.
Indeed
That's why I need to find the object on creation, I'd need to reference the other object to get its specific script right?
aye. i have Question GUI and i want it check answer and show score at Text. what Type of code i can use?
Yes. There are multiple ways to get a reference to an object in the scene. There are different Find methods and you can also pass all the required dependencies from wherever you instantiate the object too. The latter is the preferable method.
Code that checks the answer and sets text.
i often have a SetData method on my scripts that i call immediently after instantiate so i can pass in all the stuff it needs
much more prefable to finding the references through other means
i dont need code to receive answer right.just check from button and increase point
Then do it. Call a method from the button, check something in it, and do some logic depending on the result.π€·ββοΈ
Yeah, bingo. I usually call that "Init" or "Setup" or "Attach"
I almost never set fields on things I instantiate now

really managing depedencies is like the thing unity is worst at. since you dont got usable constructors in 90% of things
hello thank you for those who helped me from my problem yesterday
unityβs weakness is the devsβ fetish for sealed classes
I am trying to normalize the point of contact between my meshes in my terrain generator and it isn't working well
There are 2 differnt ways I try doing it. one is commented out though but u should see it
I am having problem with the normalization for when I set it to globally. It still doesn't make a smooth transition in height data between 2 chunks
i don't see why normalizing each chunk would ensure that the transitions are smooth
it would just ensure that the lowest point in the chunk is height X and the highest point in the chunk is height Y
thats often a side effect of things not being all implemented in C# and having a bunch of externs and a pointer to a C++ object, so its not eactly safe to let it always be extended
waiter! waiter! more undefined behavior please!
Assumed if there is a forced consistency then everything inbetween would follow along hence the transition as well. If u look at the noise map u can see it just slide through. but once height data and everything is calculated there is inconsistence
don't normalize the random data
if chunk A's minimum value is -100 and chunk B's minimum value is -200, then a height of 0 in A and B will remap to different values
youβre right. like how ruletile has a bunch of injected code.
it's hard to tell you much more than that, since this is a lot of code and you haven't shown us an example of the problem in action
oh wait, but we can extend rule tile, weβre expected to extend rule tile, and it just works
who would have thought, if you donβt seal the class, and write it in a non dumbass way, shit just works
How do I show the problem in action
by showing us the generated data?
pictures?
i see zero instances of extern methods or native code invocations in RuleTile...
there are a few [RequiredByNativeCode] attriburtes in TileBase, which are mysterious
my computer is fried rn, so I literallt canβt look through code rn
but I remember it being in SetTile
as RuleTile derives from TileBase
and SetTile is injected. And an extremely important method, core to how tiles work
yeah, that's in Tilemap
and Tilemap is sealed
SetTile is not implemented in RuleTile
oh right
the parts you need to extend are kept in plain C#
Holes like this inbetween some areas instead of just sliding down
so that you don't suffer a case of computer explode
usually between 2 separate chunks
i would still like to extend basic shit
like CustomCollider2D. Itβs literally designed in a way that would be perfect to extend.
I'm unclear what "global" normalization is. Is it supposed to remap to between the lowest and highest noise values seen anywhere?
other reason for a lot of sealed things, is the more that is exposed the more unity needs to keep stable and un changing between versions as to not totally break other peoples code
Oh that was just incase I want to just generate the full map at once for smaller map or in chunks as player move for bigger maps. Local is to only normalize the map based on it's own map data (in the case of the smaller maps generated once), while global is to ask it to take consideration of other chunks ( in the case of big maps which would be broken down) so I could try getting rid of the holes between the chunks
I think what I've done for this is create a padding of a few pixels where it would lerp from the first to second chunk
You need to sample some extra positions outside the chunk bounds.
Sounds doable I believe. I'll look into that
This too
Tnks I should go play around with these
hopefuly not die while I'm at it
Are you following Sebastian Lague tutorial by chance?
Because they have it all covered
Yh but some of what he did no longer works as it used to. I understand his explanation of the theory behind it though
It just gets me confused some times. So I decided to go mess around a bit
Hmm... I don't think there were any breaking changes in regards to what he was doing π€
What doesn't work?
not breaking
even this part of his tutorial that explains this is good. I don't like the result much. So I wanted to learn other ways to do it
Asked Chatgpt and it gave a pretty good response. Still trying to problem solve some more. So basicaally creating problems where I shouldn't
Hi. I'm stuck on something and cannot find a solution. I have a simple attack animation for an FPS prototype. I have done what I've done 100s of times. Left click to play the animation but it seems like half a second delayed. I've checked the animation and it starts when it should. So I'm guessing it's code or a bug? Is it because I'm using a trigger and not boolean?
in Update
Would also like to add that fixed duration and all that stuff is also 0
Probably an issue in your animator State machine
I'm assuming it's a bug.
Watch the state machine with the animator selected while you perform the attack
What do you mean about it being delayed exactly
It's very unlinely that there's a bug in this like, decade+ old animation system
I have. It plays Idle. When I press my left mouse button, it goes to Attacking after half a second
I think I'll redo it all. Just wanted to try and figure it out. Won't take me long 
Out of interest, is the attack's animation speed 1?
Yusss
Well, It's working now. I screenshotted every setting do with with the animation. Using the same code too. Nothing is different 
If I use blendShapes, the meshColliders do not update to the new Shape right?
Cause without that I don't truly know how to do the collider that I want
Found via google:
var render = GetComponent<SkinnedMeshRenderer>();
render.SetBlendShapeWeight(0,100f);
Mesh bakeMesh = new Mesh();
skinnedMeshRenderer.BakeMesh(bakeMesh);
var collider = GetComponent<MeshCollider>();
collider.sharedMesh = bakeMesh;
So I have to bake the new mesh with every blendShape update?
Probably not with every update, just when you want the collider to be accurate. Hopefully that's not every frame during the transition
It is XD
I want to do the typical ring in the floor that expands over time and you have to jump over to avoid it
I had to do it with blendShape instead of just normal scale to mantain the ring thickness over the scaling
That seems incredibly demanding if I want to use a good chunk of them isn't it?
Might want to investigate a procedural way to do the ring so it maintains thickness
I have been searching for something like for a while, and found some answers but none that truly worked
Weird cause it seems like something that many people would want to do
Maybe I am terrible at searching answers XD
most beginner lessons or tutorials are pretty shit to begin with. but in this case it doesnt really matter what you do. You'll get the same result. Running switch statements on ints like this is pretty weird tbh, usually you would use an enum
Dunno, but I can say that whenever you do [], you're creating a new object. The preferred way to do is to put the response array outside the function as a static readonly ig, so you're not making a new array everytime that method is called.
well this array should be created outside the method but it really doesnt matter
Indexing isn't creating a new object.
The creation of the new object is the collection initializer: {...}
hello, i'm having trouble with MoveTowards; this is my code:
Vector2 C1target = new Vector2(-668, -2124);
void FixedUpdate()
{
Cashout1.transform.position = Vector2.MoveTowards(Cashout1.transform.position, C1target, 300 * Time.deltaTime);
}
so instead of moving to -668, -2124, it goes to -1448.5, -2563
Debug the involved values.
how would I go about doing that
Debug.Log or use the debugger 
er like, what am I debugging for
I can see them slowly drift across my screen
here's a little snippet of a debug log of the position
wait that's actually weird
Are you perhaps moving a UI element?
Just hooked up mine ;P
how do I know if T is null or "" or 0?
add some exception handling
gives you a clue there: it is a type parameter which is not known to be a reference type
like try catch? I'm not sure how to use it.
but for some reason (result == null) doesn't give compiler error.... hmmmmmm, what if it's a string
I would just set a constraint, but otherwise the first google post looks like it has the answer
https://stackoverflow.com/questions/65351/null-or-default-comparison-of-generic-argument-in-c-sharp
you need generic constraint
oh nice thanks!! yes looks like constraint is what I needed. I only need it for reference type.
Hi there I just wanted to add a c# script as a component but there is an error which says that the script canΒ΄t be added because the script class cannot be found. Does anybody have an idea?
file name and class name mismatch
Unfortunately not, I have already checked it.
compile errors
The error message tells what the problems can be. If there are no errors in the console, post a screenshot of the editor while the file is selected and visible in the inspector
Ok I donΒ΄t really know how, but I think I fixed it accidentally. Thank you anyway @gaunt ice and @keen dew
I am having a issue with a transition sometimes doing some flickering when more of one instance of the Enumerator is called
Like, to stop ALL instances of a couritne I have to just type StopCouritne("CouritineName"); rigth?
It only stops the 1st one with the specified name https://docs.unity3d.com/ScriptReference/MonoBehaviour.StopCoroutine.html
You should store references to your coroutines somewhere if you want to keep track on what's running
Like an list. you'll just have to parse it and call StopCoroutine on each of them to make them all stop
I have to create a variable for each Couritne?
Is not like I want to keep a track of each one
Just stop every single one
If that's the only coroutine one the object, you also can call StopAllCoroutines
I'm trying to implement a heart system into my game. Full hearts worked fine, but adding quarter hearts has lead to a bug where every time you are hit, your health gets set to 1.25/3 hearts.
public void subtractHealth(int healthSubtracted)
{
playerHealth -= healthSubtracted;
int index = 0; // Variable to keep track of the index
foreach (GameObject heart in hearts)
{
Image image = heart.GetComponent<Image>();
if (index >= playerHealth / 4)
{
image.sprite = heartSprites[0];
Debug.Log(heart + "set to empty.");
}
else if (index <= playerHealth / 4 && index %4!=0)
{
image.sprite = heartSprites[index%4];
Debug.Log(heart + "set to 1/" + index%4 + ".");
}
else
{
image.sprite = heartSprites[4];
Debug.Log(heart + "set to full.");
}
index++;
}
}
Let me know if additional information is needed.
But if you happen to have 2 coroutines that do different stuff at the same time and you only want to stop the 1st one, it won't suit your need
It migth have more couritnes in the future, I don't know yet
StartCoroutine return a reference to the coroutine, you should store it in a list of running coroutines, that way you can keep track of what's running
And stop exactly what you want, like all coroutine with a specific name whatsoever
Also the result of the operation index%4 is always 1.
If you are using quarter of hearth you should probaly multiply everything by 4; so 1 hearth container is 4 health, it is probably easier
I have it like that.
I am baffled that there is a method to stop ALL couritnes but no stop all the courites by name X
But ok
Thx
But in the 1st place, if this coroutine is supposed to run one at a time, you should check if there's one running before starting a new one
This is the courtine; it makes a fade out transition of an image in the UI; I have a boolean telling if a Couritine of this type is in execution
This happens if you try to call the couritine but the boolean says that it is still running; which should set all images to 0 alpha and stop the corutine in progress
It doesn't seem to be stopping the couritine properly though
that is not how you stop a coroutine
You don't have any insurance on which coroutine will be stopped here
save the return value from the start coroutine and pass that to the stop coroutine
Actually I think only one coroutine can be running at the same time here, now that I double checked it
How?
Coroutine cor = StartCoroutine(myMethod());
...
StopCoroutine(cor);
https://docs.unity3d.com/ScriptReference/MonoBehaviour.StartCoroutine.html
method declaration
Vertx has a page for everything lol
Furthermore, if ResetScreenOverlayEffect is called on each coroutine you start, you're boolean will be reset even if the actual running coroutine isn't finished. This makes possible the call of another coroutine that will alter your effect
If I start a new coroutine with the same name, it is replaced then?
nope
no
And stop only a random one with that name when I call it to stop?
The 1st one the method find yes
Unless you pass a ref instead of a name, then it will stop the exact coroutine you give
So if I want to stop all of them I could just do a while (couritneName != null) loop rigth?
In that case just call StopAllCouroutine since it will have the same effect
So when having a script which can make do certain things (for example make a new enemy), I can make a scriptable object instead of having it to hard code every single one of them right?
In your example, you can just drag a prefab in and spawn an enemy directly. You should show what you mean, because this is very unclear what you are referring to for hardcode.
No, not that way. I have a bunch of enemies which get in the game later (bullet hell). Can I just use a scriptable object where I can make it more easy to make an enemy with 1 set of settings instead of having to make something for each and every single one
I can't drag a prefab in the game when playing
you can't drag a scriptable object in the game while playing either. so use a prefab that you can instantiate. scriptableobjects are not objects that live in the scene, they are basically just data containers
Like dragging a prefab in the editor? Would become quite the hassle no?
I mean it would, but you can for testing
is that optimized when we talking about 100's of enemies?
use object pooling then
Alright, I'll look into it, thank you!
SO can be used for the settings of an enemy sure. But at the end of the day the enemy is gonna exist as a prefab. Then you can swap out the settings from information on the SO
i'm also curious what you think a scriptableobject is if you think it would have solved your issue at all in whatever you think an "optimized" way is
You can still have the gameobjects reference a ScriptableObject that has the shared settings for that enemy
Nono, I never thought it would of been "optimized", but I had it in my head and thought of a fancy detour xD
The Foreach loop doesn't get explained at all in the Unity Learn course, can someone take me through it step-by-step
why would foreach be explained in unity learn course
it's a basic C# you need to learn
Cause the course is about Loops it's the Beginner Scripting one
yeah foreach is C# basic
they explain 3 other loops
you can just google C# foreachloop
and then just don't explain the Foreach
and find out yourself lol
foreach is not looping but iterating brainfart, usually in c++ you use a forloop with an iterator, but technically foreach is both combined so technically it is a loop
which is why it probably wasnt explained there
unless you're thinking of for loop
I guess technically it is looping? Maybe I'm overthinking it
startLoop:
if (i < 5)
{
Console.WriteLine(i);
i++;
goto startLoop;
}```
Best loop
forloop is mostly used in iteration, but you can always give it parameters to act like a normal while loop
ah ok, it is defined as a loop. Never really thought of it that way though
I have problem because
public InputField CharacterName;
isnt showing in unity inspector.
I need to assign inputfield because i wrote script and getting error "it is read only".
what is the actual error
Property or indexer 'string.Length' cannot be assigned to -- it is read only
yeah you need to fix that. you cannot assign to the length of a string. perhaps you mean to compare it using == rather than assign with =
this is a compile error and you have to solve it first
jesus bro
foreach(string item in strings)
{
Debug.Log(item);
}
just to make sure, the foreach loop is basically saying
"for every string present in the 'strings' array, print to the console"
right?
i already looked it up i just want to be sure
yes
yayyy i get it
IEnumerator something=XXXX:
while(something.MoveNext()){
T value=something.Current;
}
https://learn.microsoft.com/en-us/dotnet/api/system.collections.ienumerator?view=net-8.0
is the official name "AnotherClass" ?
I'm confused as to how this works
shouldnt it just be Class
if its defining the type of variable
AnotherClass is the type name
that's an actual type name? not "NewClass" or "Class" or anything?
yeah I know you can name the class whatever you want
but AnotherClass is the actual type?
the name of the variable is myOtherClass
Please dont name a class 'Struct' lol
Correct
this is an object of type AnotherClass
<type name> <variable name>
Well I guess not an object yet until you use new
I believe it's on the stack till then
so "AnotherClass" really is an actual type name
that's weird lol
Only if you make it
is assuming it is
Its not a standard class in C# or Unity or anything
transform child or getchild will include inactive gameobjects right?
What does the documentation say?
{
1Door,
2DoorDiagnol,
2DoorAcross,
3Door,
4Door,
}
public enum CardinalDirection
{
Up,
Down,
Left,
Right,
}```
For some reason im getting an error for the values in the enum for RoomType.
Identifier expected
Ok so I switcehd the numbers to chars and the error went away.
I would like to use numbers if thats possible
identifiers cannot begin with a number, move it the the end
also maybe consider giving those better names
i see thanks
Any suggestions?
i don't know what their purpose is for so i cannot possibly provide a suggestion
just use cardinal points. N, S,W, E etc
the thing is that im rotating the doors if that makessense. Lets say theres an 1 openinig south. I will pull the tileset containing one door then rotating it south therefore its not a static direction. The variable represents the tileset prefabs that contain X door
gotcha, then you are probably ok with those names although it would be nice to spell Diagonal correctly
haha oops will do
so i follow a tutoral and he put rigid body on sb but i cant see the rb place on mine i have exactly the same code
show the relevant code
nice
!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.
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float moveSpeed;
public Rigidbody2D rb;
private Vector3 velocity=Vector3.zero;
void FixedUpdate()
{
float horizontalMovement = Input.getAxis("Horizontal") * moveSpeed * Time.deltaTime;
MovePlayer(horizontalMovement);
}
void MovePlayer(float _horizontalMovement)
{
Vector3 targetVelocity = new Vector2(_horizontalMovement, rb.velocity.y);
rb.velocity = Vector3.SmoothDamp(rb.velocity, targetVelocity, ref velocity, .05f);
}
}
read the message directly above yours. then get your !IDE configured and fix your spelling errors
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
i can't understand what do you mean
huh how do i use that
like i do a movement script
use what? the guide to configure your IDE? you read it
lmfao
cool
but on unity he put rigid body as a rb but i cant
because you have compile errors. get your ide configured then fix the spelling mistakes
they are referring to being able to assign a rigidbody in the inspector which they cannot do because their code is not compiling
ah
i dont speek very welle english i cant anderstand a word of what you sayind can you come in vc and i show
this is a step by step guide
on how to configure your IDE
just read it/translate to your language if needed
i know what your problem is. i already told you how to fix it. use a translator if you cannot understand what i am telling you
how to see were the error is aand what to do
this is not going well π
for the love of god, configure your fucking code editor and it will show you the error
- configure your IDE
- fix compile errors (you can see them in the console)
i did fix two error and config it but nothing apear as error it just dont show the litl thing were you choose the rb
at this point his broken english is breaking the community conduc of the servert:
Do not: β’ Use a language other than English.
it's not showing that because you have compile errors
Who broke eng?
no you didn't config your IDE
dont lie
i just dont anderstand the coding word i can very welle anderstand
isnt it the thing wer it tell error in unity (console
Lets put it like this @limber stone either you go and use https://deepl.com and translate your language to english and english to yours.
Or we stop helping you
Why are you so aggressive?
His english isnt that bad lmao
You don't need to help if you don't want to
My guy havent read much webnovels
"you" can stop helping him (you didin't start yet but :D), not "we"
bro are you a dumb ass i cant anderstand special word of the comunity if you cant stand aving a bad person in coding asking help go tf out and talk to the general
not agressive, just saying what should be said
very
what do yous till not understand
configure .. your.. ide
i guess you can tell what they mean
but they also dont understand us either
Yeah I read a lot of MTL things
yh i have problem envent in orthograph event in french but with voice i totaly anderstand and can talk
Lmao
this is why you should be using a translator
this
IDE is not special word of the community of this server wdym
An IDE (Integrated Development Environment)
ide=your colorful text editor
after configure it, it can be helpful and help you check your syntax and provide suggestions
Unity/Visual studio
i have bad writing and eror in what letter and werre to put them even in my native laguage
Considered u have code issues its visual studio
i dont think im the dumbass here, you want help and refusing to translate, which would help us properly understand you and you could understand better too.
Google exists btw
ty that what i was askin its that i dont know hte meaning of word wen they are not comon in normal talking for exemple with non coding person
googled it i didint get a response i could anderstand bcs my google is in french
then dont put your google in fricking french
Do you mean its in french like you speak french or u put it in french on accident?
He doesnt understand the results in french is what they said
you think im gonna change all that bcs somone cant asxplain in longer and more anderstandable word for beginer wont say it
i actualy speek french and use it
Coding is like 60% of looking things up
sorry but as an example, cuz you dont translate, this is written so bad that you basically wrote the opposite of what you mean
ik but im only 14 not very good english very different native laguage and beguiner
THEN USE A TRANSLATOR
Omg its a kid
its free
yh but it translate word that dont make sense in french

Wdym it makes no sense
it does, if he would use DeepL, its just google translate thats shit
Which i already said they should use
En programmation informatique, un environnement de dΓ©veloppement est un ensemble d'outils qui permet d'augmenter la productivitΓ© des programmeurs qui dΓ©veloppent des logiciels. Il comporte un Γ©diteur de texte destinΓ© Γ la programmation, des fonctions qui permettent, par pression sur un bouton, de dΓ©marrer le compilateur ou l'Γ©diteur de liens ain...
lol
It took me, googling IDE, pasing that meaning into google asking for wikia, changing wikia language to french

even Xaxup gave up helping you, the one that told me that im in the wrong, wanting you to use translater or we stop helping.
Lol
"method must have a return type"
yeah you need or void or what it returns
youre missing a void before values
void = returns nothing
your method has no return type.
there are beginner c# courses pinned in this channel, do them. you've been told this every day for several days now
also you dont need to "return;" a void anyways
poor box he is just sending people to c# courses XD
i'm gonna guess that random return was their attempt at fixing the issue
also you have two closing brackets at the end
function declaration:
[unsafe?] [access modifier] [static?] <return type> <the name>
and consider have an online c# course first
I think that second one is class bracket
So dont give him a hint to delete that too π
then its indented wrong
Proabaly he has barely any idea of coding
it's just [modifiers] [return type] [name]. unsafe, static, override, virtual, new, public, private, etc are all just types of modifiers
Hellow world is not a sign of experience
Thats like the best advice for like 60% of questions here

wdym i'm a professional 1337 programmer in 255 languages because i wrote hello world in all of them!
I'm legit in the middle of taking a course right now and I don't understand it, that's why I'm here bro
Please leave me alone
dont use it if you dont know what it does xD
Its UNITY channel
ah, static is access modifier (define whether it is instance method or class method), mb
it leads to memory leaks
Yeah I know
learn the basics of c# before learning the basics of unity
I also read that most of pointer stuff not really needed anymore with compileres
ok we will if youre refusing genuine advice
wait is he the guy who came with " move player left"?
yes
it's not an access modifier, access modifiers are public private and internal. it's just a modifier
dont forget protected
yeah i wasn't gonna list them all lmao
What for is protected used?
So far had no reason to use it considered my apps cared little for haking
protected is basically like private but allows inheriting classes to access it too
I get it
has literally nothing at all to do with security/hacking
I mean it sounds secure π
oh so a "private" public xd
i bet someone used it thinking that
that's more like internal
our prof just told us to use private or public and ignore the others, that most of the time they are the better thing to use
microsoft just call static as static modifier, yes, it is not access.....
for the most part you can completely ignore the other access modifiers. although you may want protected sometimes. in unity you're unlikely to need any of the other 3
Is unity mostly script driven? I remember being told its c++, but so far I only coded in C#
that question does not make a lot of sense
I mean the fact that U can make everything with scripts and they are written in C#.
C# isnt really scripts
not quite 100%
this is also not entirely true. you can write native plugins using c++ or even c
JavaScript?
C# is still code that gets compiled
not like a script that just gets read at runtime
only if you go back in time to use unity's bastardized javascript
Who wants to rewrite unity in java script?
noone cuz js is ass
Don't forget there is still Emscripten for .jslibs targeting WebGL
when one same language has like multiple different branches cause it sucks so bad
wait what
btw this is more of thing for #archived-game-design were kinda blocking the help channel with this
JS (UnityScript) got removed around v2017..? IIRC
If someone wants some coding help they are free to ask
box gonna send them to C# courses anyway xD
me 2
this channel should just autoreply to questions with a C# & basic unity tutorial
xd
only if they show a complete lack of understanding of how c#/coding n general works
Wasnt like most of people who came here like that?
indeed
nah, you're expected to know how to write a method
60% or more times a question in here its answered by a basic tutorial video
I mean everything is googlble
This chat is mostly for "why this no work"
with most dominant answer "you forgor" smth
With appearence of A"I" tools learning coding at least on begginer to medium levels became even easier.
and yet people still refuse to learn
For beginners, it just added an extra place to have something broken and not know why
i've blocked dozens of people at this point who just outright refuse to try learning the basics. many of them still come in here with super basic questions that even a shallow understanding of how to write code would fix even after a year or more
Which beginners struggle with .. beginning and learning π
I liked chatGPT, when it just got out it was really good.
Helped a lot explaining what something does
With time it got worse
It doesn't know good code
yeah the code done by gpt only got like worse, which is like weird, but i mean its a language model, not a coding model
I mean who does?
Experienced people who've been programming for years?
it was actually pretty decent while it was new
Reminds me of that video of valve coders complaining in the code about something
Exp Programmers
Negatives of AI tools that got over hyped
you learn how to code and understand what does what and how to archive what
thats how you learn, you never learn just using AI code
I learn well from examples so for me it proven really usefull
also the AI code has a high chance of beeing wrong or the wrong approach
Yeah it loves hallucinate
back
is your IDE configured yet
leme try i was eating
just i does work with visual studio code bcs the origina lvisual studio dont work with so i use this one
screenshot your entire code editor
can i send the image in this chanel
yes
not configured. π !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
it is a requirement to get it configured in order to receive help here
ok ty leme do it
thats what i wasnt anderstanding and a litl phrase like you did could of explain me of the start wat was ide ty
Keywords and phrases can be easily highlighted and googled.. you can do that yourself when you come across a word/phrase you don't know
is this the right way to do this?
the firing becomes false when I stop holding the mouse button
it wont select Visual Studio Code as External Script Editor.
i dont have the choise
you don't need that bool at all. just use Input.GetButton
restart your computer then try again
ok or can i just restar unity ?
you need to restart after installing the .net sdk anyway so restart the whole pc
ok
Can you crash an audio source? If I run my mouse really fast along buttons which are configured to playoneshot a sound on hover eventually they stop making sounds
you sure you're not hitting the max number of sounds playing at once or something?
still not leting me the choise of visual studio code
