#💻┃code-beginner
1 messages · Page 677 of 1
ye
you are not using the Image from UnityEngine.UI
which is what you want
delete these
using JetBrains.Rider.Unity.Editor;
using Microsoft.Unity.VisualStudio.Editor;```
then put using UnityEngine.UI
OH
😭
Spent all that time for what
Well now I gotta get images from the Project folder thing
then set them to be the source texture
put a field for it
no need to search the project folder
set it in the inspector / drag n drop
but then i gotta do that for each item
hotbar system
like these
great now itemPreviewImage.SourceTexture = itemImage;
Source texture has a red line
where are you getting SourceTexture from
the image from earlier
u know the one that i couldnt disable
i can disable it now but thats all
https://docs.unity3d.com/Packages/com.unity.ugui@1.0/api/UnityEngine.UI.Image.html
where do you see such a property
sounds made up
Hey, guys. I want to rotate a gameobject depending on its velocity (in my case pointer delta), but it's really jaggy. Is there something I do wrong?
!code btdubs
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 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.
😭 Ima see if it worked
I mean thats the property for it, It would work in theory.
i hope
do u think its gonna work
Sprite itemImage = (Sprite)Resources.Load("Assets/UI/Hotbar/itemPreviews/" + item.name + ".png");
I hope so
no because the Load method has wrong path
UnityException: Load is not allowed to be called from a MonoBehaviour constructor (or instance field initializer), call it in Awake or Start instead. Called from MonoBehaviour 'InventoryHandler'.
See "Script Serialization" page in the Unity Manual for further details.
UnityEngine.ResourcesAPIInternal.Load (System.String path, System.Type systemTypeInstance) (at <0022d4fb3cd44d45a62e51c39f257e7c>:0)
UnityEngine.ResourcesAPI.Load (System.String path, System.Type systemTypeInstance) (at <0022d4fb3cd44d45a62e51c39f257e7c>:0)
UnityEngine.Resources.Load (System.String path, System.Type systemTypeInstance) (at <0022d4fb3cd44d45a62e51c39f257e7c>:0)
UnityEngine.Resources.Load (System.String path) (at <0022d4fb3cd44d45a62e51c39f257e7c>:0)
InventoryHandler..ctor () (at Assets/Scripts/ItemSystem/HotbarHandler.cs:12)
😭
also just make fields..
you cannot call method in the field initializer.. you can only put a property at most
im so lost
but again you should not do it this way at all
well if you guess your way through it ofc
did you read the docs how Resources.Load works ?
its in update not fixed update i think
nope 😄
how exactly do you plan on making something work if you don't even know how it works
it is when you read the docs on how it works.
😭
i dont know if this is the best way to do something but
im making a rpg game for fun and i got different npc with different tasks that they give u so u can get a key ( they all have different scripts )
in each task i thought the best way to make the final gate to open was to comapre if the player had all the bool active
my plan is to make some text on the screen saying something around "you got "amount" of keys" ( aka the bool that i have ) how could i do it?
store the keys in a list then check if the list has the amount of keys you need
a bool per key sounds like a mess
how would you approach it?
the way I suggested lol
how would i do if a player completes a task? addes a key to the list?
that actually sounds better
unless you need specific keys then I would make the Key itself an object and use an index/enum to distinguish it
nah its just 3 keys
randomly
so if its just needs to be 3 keys and you dont care which one i which, and you just need the amount collected, then use a list ye
should i make a keyhandler or smth script? just to check the keys and stuff?
You could if you want, thats up to you
thank you for the help
if you insist on using bools but this is also a terrible way of doing it
[SerializeField] private bool[] myBoolArray
for (int i = 0; i < myBoolArray.length; i++)
{
if (myBoolArray[i])
{
Debug.Log("+1 key")
}
}
probably will do the list
it does sound better
and less complicated
but thank you!
array is valid too but not sure what the point of that loop
so you can extend the array as much as u want
wdym extend to array
arrays don't extend they are fixed in size, hence the .Length instead of .Count
yea but you can extend it in unity
yeah but you're bound by the inspector to do that, and all is doing is myArray = new bool[newSize]
you still need to loop through all of them anyway to check if they are all true
🤷 personal preference ig
kinda lol
Hey, any input onto this? Thanks 
theres a setting in rigid body to enable gravity + theres no code that rotates the GameObject
Theres a character controller on the player, does that have one?
whered u get the code for this?
Currently in tutorial hell, so tutorials on YouTube 😅 never worked on 3d unity before, I’m used to 2d
unity has some tutorials to !learn from + u should start with 2d
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
Gotcha! Thank you so much. Will spend some time on there 
Also, code monkey has this great course for unity 3d on youtube. 10 hours for free!
still kinda tutorial hell
well, if you're looking to get out of tutorial hell, I think it's best to have this sort of "end"
since it is a pretty comprehensive guide, you shouldn't have to look for any more tutorials, and rely on the documentation from there forward
rely on the documentation isn't a negative..
oh I mean, you will rely on the docs
rather than tutorials
was about say...thats how you get out of tutorial hell when you can interpret the documentation and nothing else
the unity documentation is as important as energy drinks for me
I forgot a comma my bad 😭
Is there a way to write my if statement this way instead of the inverted version of it but without returning anything as here my return statement at the end of my method, it should be a List<Tile but in this if statement I just want to get outside of that if statement to not execute neighbours.Add(tiles....);
So return doesn't work, continue doesn't work, so I'm kinda loosing hope on using a safe guard statement in this case and have to go with the inverted if statement 😬
if break, continue, or return isn't working for what you need, you can also try goto as a last resort
goto: back to classic
Is it what would be practiced in "pro" environement ? Or will "proes" go with the inverted if ?
pro env / good practice
goto is generally avoided by pros, but sometimes the cleanest flow is to jump over everything else and go to the end
And sometimes encasing everything in a bunch of IF cases to do that is uglier than just using a single goto
alright, could you gie an example of how a goto works because I never used one please
what im reading is use it if: whenever it's the cleanest and most maintainable way to write something, which is uncommon
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/statements/jump-statements
Goto is near the bottom
im slow
Thanks 👍
I generally will only use a goto when the destination code is near the end of the method, and I'm using it to jump past something in the fastest and cleanest way
I would never use it to jump backwards, that way lies madness
i see it mentioned alot about "error handling"
like this gem i found 😅
... cast it into the volcano before it is too late
could you not just return neighbours right there? i dont really see what the problem here is, but goto is 100% not your solution here
you really just shouldnt be using it
ive never seen it in the wild
I've used it exactly once in my current project. The circumstances where its more readable do exist, its just pretty rare
Nope because I have multiple if statement where I need to do that trick, so that's why I went for the classical inverted if approach
then swap around your logic. why not just check if the value is 0 before any of this?
^ very true..
Or && the != 0 into the initial IF statement
that condition doesn't apply to all tiles, only the corner ones
But yeah, I think starting off with != 0 is better
then yea include it in the first if statement where you want it
and make a method so you arent writing the exact same logic 10 times
also, I think a lot of those IFs should be ELSE IFs
I'm not sure to understand 🤔
i guess first focus on the part Contrivance said here #💻┃code-beginner message
you can just add the logic to the outer if statement
making a method for this would just avoid rewriting the same code over and over, but its not required if thats the entire logic
^ i was also going to mention that too but wasnt sure if it was appropriate
all those if statements make me think a switch might work well too
Done
also youve most definitely been told about the code command before
code command ?
Switch needs compile time constants, which might not work here. I used to run into that issue all the time when I wanted to make a switch running off of vector2int coordinates
#archived-code-general message
it wouldve been easy to just show you how to write it if we could copy the code to edit
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 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.
A tool for sharing your source code with the world!
How you wrote the code in the screenshot was fine. I was just saying if you sent the code like this initially, its easier to show you what we mean since we can copy and edit it
Btw you can check if the value is 0 before checking its in the grid. It's a micro optimization but that means it wont check the grid everytime if it doesn't have to
My bad, I'm used to send screenshots because usually these questions get solved really quickly and don't need rewriting the code 😄
I think I can't because the != 0 is only for the corners, as I don't want when I click on a tile and it's a 0 it propagates to 0s that are on corner neighbours
I meant swap the order of the if statement so you check tile.Value and then check IsInGrid in the same line
Right now it'll check if its in the grid everytime, then check if the value is 0 if it was in the grid.
If you check if the value is 0 first, it has a chance to exit that if statement early without checking if its in the grid
Oh I see
I have no clue why but that site also keeps deleting all the code as I try to scroll on mobile lol. Hopefully it was clear though
Like this ? 🙂
Yea
Also, is it possible for multiple IF statements to be true? If not, then you should be using ELSE IF for the extras
Its a micro optimization but it could matter in the future if one condition is an expensive operation
yes
Argh my code doesn't work, it should reveal those corners as they're non zeros but it doesn't 😬
Yellow = Where I pressed
Red = What it revealed
It should be like this (with the corners)
Actually, a cleaner way to do this is to encase it in two FOR loops, one for x and one for y, and then do the IsInGrid check on the x and y coordinates you get from the loops
Let me try that
x and y going from -1 to 1, and adding that to the coordinate you clicked on to get all possible 9 positions
and a check for when both are 0, in case you don't want to do anything when its the exact tile you clicked on
I want when I click on a tile with "0" to make it propagate to adjacent tiles but not on diagonales that are 0 and the edges of those 0 that are != 0 but not -1 and the diagonal should work too (I hope it makes sense 😄 )
nested for loops can achieve that, it removes the need to specify every possible coordinate, and you can put the logic inside for whether to place a tile or not
wait, what should be the condition for i and j inside those loops ?
like i < ?
ur grid dimensions right?
true
i = -1; i =< 1; i++
same for j
Since you're adding these to the x and y of the coordinate to get the adjacent ones
Oh
its why I'd call them x and y and not i and j, makes it more clear
ah ya, i was thinkin of the actual grid generation
btw, what u making? minesweeper?
yes
This is the code of generation
I think I will go to sleep guys, I'm tired 😄 I hope you're here tomorrow 😛
i tried that once. i got the grid and selection stuff coded out
but i couldn't do the math for filling in the numbers
filling the numbers is easy, you loop through each tile and you count how many mines are neighbour of that tile and you set the number of that tile to that value 🙂
Good night 👋
Nothing wrong with this but sometimes can be nice to move this logic into it’s own function since it’s kind of it’s owned isolated job. Eg
SpawnNewTile(Tile tilePrefab, Vector2Int index)
Also just another 2 cents that you can take or leave but imo that code is slightly more readable if you do the tile coords and color setting on the tile reference directly thats right there and not via the matrix index reference. (The fact the reference is right there and your not referencing that makes my brain assume the matrix must be pointing to something different)
Final random suggestion that’s more for longterm is having the matrix assignment + coords assignment as a seperate function, so in the future if you ever wanna modify a tile’s position you can use the same central function
any way to only get the rotation values of an animation without a humanoid?
also what's the best way to change walking animation up slopes
checking the angle of the normal below your feet ig, have a blendtree and param that ends up changing between 2 types of walking
Hello everyonem i'm beginner and i have put some light on my scene and it's look like that, why i have random illumination and it's stop instant idk why ?
Not a coding question. #archived-lighting
Juste Check Lightning I have maybe already said that yesterday
Great, then wait for an answer there
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 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.
Can the async scene load create memory leaks like default events? If you don't -= after += I mean.
So compare this:
var asyncLoad = SceneManager.LoadSceneAsync(deserialisedModel.CurrentSceneName);
asyncLoad.completed += _ =>
{
_gameStateServices.ForEach(service => service.ReadStateFromModel(deserialisedModel));
asyncLoad.completed -= handler;
};;
to the clunky unsubscription:
var asyncLoad = SceneManager.LoadSceneAsync(deserialisedModel.CurrentSceneName);
Action<AsyncOperation> handler = null;
handler = _ =>
{
_gameStateServices.ForEach(service => service.ReadStateFromModel(deserialisedModel));
asyncLoad.completed -= handler;
};
asyncLoad.completed += handler;
The delegate will be GCed once the async operation is gced
You don't need to unsubscribe unless you're keeping a long running reference to the operation around.
Wdym by "vertically across my entire screen"?
nvm, it's because my canvas scale was too small, dumb or outdated tutorial maybe
thx though
How do I get my healthbars to show up like in League of Legends? They're so stable, don't jitter or move as camera is moving and perfectly follow the units.
I tried it like this healthbar.transform.position = _cam.WorldToScreenPoint(worldPos);
But it keeps moving as I move my camera, it dances left/right up/down a bit.
for healthbars like that they'd probably be world-space canvases
anyways the issue you're seeing is probably due to stuff being out of order - likely this positioning happening before the camera is positioned
I tried world-space first but that was even worse, since the camera position constantly changes the angle
within each frame, the world stuff has to move first, then the camera (if it moves independantly), then stuff that relies on the camera view (like parallax or UI)
but with a world-space canvas you can just sidestep the entire "position is reliant on camera position"
it's better in screen space, but it dances a bit as the camera moves
you'd have to apply billboarding i suppose?
This is what I have now:
hmm not sure what that is
lol it has sound from the lol stream I'm watching 😅
basically rotating it to point towards the camera at all times
(there might be a better more built-in solution for this, i'm not a ui guy 😅)
yeah I tried that, it was much worse than this
according to Chat GPT LoL uses screen-space for healthbars
yeah that's just.. not something you can determine?
don't trust chatgpt for anything lmao
it's gonna tell you everything with confidence whether it's right or not
quick google gives the same result though
well i suppose it technically isn't wrong, this one is definitely in screen space lol
is it from an interview from devs
if not it's probably a guess
you could achieve identical results with world space and screen space UI
in fact these terms might not even apply since league uses its own engine
can't find a single tutorial on this stuff that actually works
are you trying to fix the original issue or do billboarding or what exactly?
for persistent data through scenes, for things like the player's party data and unlocks for example, would a persistent scene or don't destroy on load be more ideal and easier to work with as the game grows?
I'm trying to do billboarding now
transform.LookAt(_camTransform.position); is the result in the video
also tried transform.LookAt(_camTransform.position + transform.position); with both + and -, neither work properly
I'm trying to add healthbars that stay perfectly above their unit, regardless of camera position & angle
Similar to how league of legends does it
dontdestroyonload is a persistent scene so whatever you prefer tbh
you probably want your ui stuff on a screenspace canvas that sets its position to the converted world space
rather than the ui being in worldspace directly
@sour fulcrum this is what I had before
@topaz mortar i did answer about why that was likely happening, if you missed that?
#💻┃code-beginner message
alright let me start over again 😅
with perspective view this would point towards the center of the screen, whereas you'd want it to point perpendicular to the screen plane
actually a lot better, still not perfect
This is what I have now: (Quantum, so different update function)
{
Vector3 offset = new Vector3(0, 3f, 0);
Vector3 worldPos = transform.position + offset;
Vector3 screenPos = _cam.WorldToScreenPoint(worldPos);
healthbar.transform.position = screenPos;
}```
well is the camera positioning also in OnLateUpdateView
no, the camera follows my player object, which has no late update in quantum
it's cinemachine
imma be honest i'm not noticing weird positioning
it jumps a little, as I press any direction, for example up, it shoots up a short distance, then goes back down a little
it's hard to notice but something is off
I may be wrong, but it's probably better to loop through all the health bars and update their positions in a single update, instead of having each individual one update for itself, for performance reasons, but again I might be incorrect
wouldn't really matter, method overhead is tiny (and might mot even be a factor given the override thing)
I don't know what that means 🤯
I think going with world space would prevent the zoom issue too, so might be better
do you just mean I should do transform.LookAt(_camTransform.position - transform.position);
no you'd have to project the position onto the plane of the screen and then look at that
is the zoom issue that it stays consistent or that it doesn't?
you could use Vector3.ProjectOnPlane i think but i don't really know how to use that method
i guess the other thing would be WorldToScreenSpace then ScreenToWorldSpace lol
is copying projects a good practice to learn how to make a video game?
nope, it's terrible
well, depends on how you do it
Yeah its a one of many way to learn the basic but you need to do a lot of those or make your own game and learn as you make the game that way you will learn fast also enjoying the journey
I fed this line into chat gpt and it came up with this:
forward.y = 0;
forward.Normalize();
healthbarCanvas.transform.forward = forward;```
this almost works, except when you go above the unit, it becomes a line
and if I remoe the y freeze, it doesn't update position based on the camera anymore, it kinda just statically floats there not looking like it's above the unit
Copying by rewriting and setting up by hand could absolutely be useful for learning. Copy pasting entire chunks less so
nah even rewriting isn't good
Tbh i’m not interested in hearing it from someone actively using chatgpt, respectfully
the best way to learn programming is to watch a tutorial on a piece of code, close or hide the tutorial and try to write it by yourself, never just re-write code you can see, you will learn nothing
It's way way harder for a beginner
like how would I know what draw gizoms is? or how would I know what object pooling is
Googling 😄
because you just saw how to do it in the tutorial and are now doing it again by yourself
if you forget, re-watch the tutorial (or google), close the tutorial & google again and try to write it yourself
Though you don’t need object pooling when starting out
I promise you your brain will remember nearly nothing after a few hours if you just re-write code (or worse copy/paste it) while looking at it
He is saying that I should write the code myself and hide the code from the tutorial, how can I google something that I don't know anything about, you know?
well for my first project I made a figthing game
and I needed that
object pooling is an optimization, you never "need" it
Oh I see now
If you mean it like that then yeah it's smart I guess
public class PlayerMovement : MonoBehaviour
{
public float speed = 5f;
private Rigidbody2D rb;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
float horizontalInput = Input.GetAxis("Horizontal") * Time.deltaTime;
float verticalInput = Input.GetAxis("Vertical") * Time.deltaTime;
Vector2 movement = new Vector2(horizontalInput, verticalInput);
rb.linearVelocity = movement * speed;
}
}
whats wrong?
do that in your original message lol
show your rb setup
How do I remove it? Gravity scale 0?
Yes
public class PlayerMovement : MonoBehaviour
{
public float speed = 5f;
private Rigidbody2D rb;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
float horizontalInput = Input.GetAxis("Horizontal") * Time.deltaTime;
float verticalInput = Input.GetAxis("Vertical") * Time.deltaTime;
Vector2 movement = new Vector2(horizontalInput, verticalInput);
rb.linearVelocity = movement * speed;
}
}``` now is there something wrong with the code? i cant even move 😭
you only set gravity scale, right
try debugging, make sure movement is what you expect
public class PlayerMovement : MonoBehaviour
{
public float speed = 5f;
private Rigidbody2D rb;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
float horizontalInput = Input.GetAxis("Horizontal");
float verticalInput = Input.GetAxis("Vertical");
Vector2 movement = new Vector2(horizontalInput, verticalInput * Time.deltaTime);
rb.linearVelocity = movement * speed;
}
}``` ok now i can move left & right but still not up and down
yeah the verticalInput velocity isnt getting added
im printing it now
only horizontal is
why do you have Time.deltaTime there
so it doesnt matter your frame rate
okie thanks it works now
Time.deltaTime is a conversion factor between "per second" and "per frame"
your speed is units per second, so if you did the movement manually every frame, you'd need the deltaTime to convert that to units per frame
but velocity is also units per second, so you don't need the conversion in this case
i see
I just started Unity for today and for some reason the cam is so zoomed in while it wasn't yesterday and didn't touch anything since yesterday 🤔 How to solve that please ?
change the ortho size on your main camera to not be soo small, also not a code question
ortho size ? You mean FOV ?
ortho size if ortho, fov otherwise yes
I presumed 2d from how it looks + 2d light
If stuff that should draw is just not, your camera may be at Z 0 and your content may be there too. Can be solved by moving the camera back a tad on Z
Thanks 👍 Also my code doesn't work anymore for some reason 🤔 ☝️
elaborate on how it "doesn't work"
nevermind it's because I commented that part to try what was suggested to me
start by getting your !IDE configured then share the code properly
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
• :question: Other/None
share code correctly !code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 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.
ha
PlayerMovement.cs:
using UnityEngine;
public class PlayerMovement : MonoBehaviour{
public float speed = 5;
public Rigidbody2D rb;
private InputManager inputs;
Vector2 moveDir;
bool isMoving;
void Awake() {
rb = GetComponent<Rigidbody2D>();
inputs = GetComponent<InputManager>();
}
void Update(){
moveDir = inputs.moveInput.normalized;
isMoving = moveDir != Vector2.zero;
Rotate();
}
void FixedUpdate(){
rb?.MovePosition(rb.position + moveDir * speed * Time.fixedDeltaTime);
}
void Rotate(){
if (isMoving){
float angle = Mathf.Atan2(moveDir.y, moveDir.x) * Mathf.Rad2Deg - 90f;
transform.rotation = Quaternion.Euler(0, 0, angle);
}
}
}
InputManager.cs
using UnityEngine;
using UnityEngine.InputSystem;
public class InputManager : MonoBehaviour{
public Vector2 moveInput;
public void OnMove(InputValue input) => moveInput = input.Get<Vector2>();
}
start with what boxfriend said
The joystick, I can't move it
If you see the video, you'll see that the move input variable in the input manager script isn't updating
That's the issue ig
oh it's probably not in the code then
(could confirm that by adding keyboard bindings and see if those work)
uhmmm it is in the code...
if those work fine, then either the joystick isn't hooked up properly, or it doesn't work in the editor for some reason
that would be an #🖱️┃input-system or #📱┃mobile question though
the issue is probably not in the code
i did ask in mobile, they sent me here
a code issue was a good guess, but it's apparently not the issue
i'll ask in input then
(make sure the virtual joystick is hooked up correctly)
uhhhh ig it is... wait i'm sending screenshots
(send it in #🖱️┃input-system)
okkk
Also, why do you have a null conditional operator on your rigidbody move position call? Last I recall, null conditional operators did not work with Unity Objects 
they "work" but not as == null as one might expect
Right, they don't use the custom equality operator
so what should i change??
remove the ? (?. -> .) and just let it fail-fast if the component is missing
Remove the question mark from your rb?.Move...
If the member has a proper reference, you'll not get the Unity missing reference exception
Getting rid of errors is not getting rid of problems. If rb is null, it should throw an error. Null checking it gets rid of the error but just buries the problem that's still there
Still not working
Not working relative to...?
The joystick isn't working
it wasn't supposed to fix that
Ohhh
it was just a separate issue
like this ?
for (var x = -1; x < 1; x++) {
for (var y = -1; y < 1; y++) {
if (IsInGrid(tile.Coords.x + x, tile.Coords.y + y) && tiles[tile.Coords.x + x, tile.Coords.y + y].Value != 0) {
neighbours.Add(tiles[tile.Coords.x + x, tile.Coords.y + y]);
}
}
}
gotta be <= 1
both for x and y ?
yes
if it was < 1 you'd just get -1, 0
makes sense
Doesn't work 😬
- Green : When I pressed that tile it only revealed that tile and not the adjacent "0"s
- Yellow : It revealed that tile + 3 in the red rectangle
I'm kinda confused on this behaviour 🤔
I think it's because of the != 0 part
yup 👍
does -1 symbolize the bombs?
yes
i may give it another shot as well. got ur "Easy" message.. ya i was overthinking the number thing
what do you mean ? 😄
Oh 😄 Yeah try it 😄
i was using the bombs to fill in the numbers..
i just need to use the squares to look for the bombs
huh ? How ?
I don't understand what you mean by that 😄
instead of having each square count around itself for bombs..
i was using the bomb spaces to fill in the numbers around it
but then if i got to a second bomb in the vicinity of another bomb.. id have to re-do numbers that wer already done.
that wouldn't be an issue
a 1 might become a 2.. and then it might even become a 3 later on on the next bomb.. sooo yea i was doing it bass-ackwards
it would actually be more performant
ya, i probably could have finished it.. but i wrote it so bad that it became abig problem
well, if the amount of bombs is <= 50%
for each tile:
if tile is bomb:
for each neighbor(tile)
if neighbor is not bomb:
neighbor.count++
```vs```py
for each tile:
if tile is not bomb:
for each neighbor(tile)
if neighbor is bomb:
tile.count++
I still don't understand it 😄 Do you mean like you generate the value of the grid from top left to bottom right and if your random generator generates a bomb for your current tile, you're kinda stuck for the previous tile that you already set a number for it and the next tiles would have the same issue later ?
this distinction is what spawn is talking about
oh it's from the perspective of the tile or the perspective of the neighbour, I see 👍
ur using a space.. and then look around that space to find the amount of bombs to fill it in right?
i was doing..
ya ya.
i could have just skipped the bombs.. b/c they dont need a number
but i was filling in the spaces adjacent
yea
stupid lol
(atleast for my ass)... a nested loop is about all i can contend with
or to keep straight in my head.. grids are my kryptonite
- I Genereate all the bombs in grid first
- Get all the bombs tiles and fill the value of their neighbours
- All the other tiles don't need to be filled as their default value is 0
let me see if i cant find my old code.. im sure it will give someone a laugh
i mean if you do it when you generate the bombs you don't need the n^2 step
not really a laugh but a way to learn 🙂
oh no.. it was one of my first 2D projects.. its def laugh worthy..
it was a learning lesson back then
now its just disappointing lmao
hey i have minesweeper too lol
nice 😄
heh why not both (i did both)
i could do snake real quick..
did u do urs the actual grid ways?
i mean tbf i kinda did them for fun, not with the intent of learning
where u add a grid in front and remove a grid in back?
they're terrible and that's ok lol
for movement
uhhhhh kinda?
ya thats the way i wanted to do mine
and i kinda felt gate-kept
seems like something hard to do
snake movement
i mean.. tbh i feel i still made the right choice ^ i wouldnt know how to do this even today
since we're in beginner code anyone know the psuedo on how to do something like that ^
where the movement of the snake fills in the square ahead of it and removes the square at the end?
deque (via linkedlist in c# for example - or List but that doesn't scale well, in theoretical terms)
does the snake have a V12 engine ? 🤣
actually i guess a queue would suffice, you don't need a deque
so you can just use the built-in Queue
yeah the scaling is definitely terrible lmao
that's what happens when you make something for fun tho lol
(btw @rocky canyon if you want to ask about stuff here feel free to open a thread and tag me. it's definitely not very good code lmao)
Snake Movement Grid
https://hastebin.com/share/udamoyijih.csharp
the text isnt activating, it just stays deactivated no matter what
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
if anybody like to help just dm me i am stuck hehe
Then it seems you are not overlapping with anything on that layer. Does your overlap detect anything at all
oh shoot
the box has to have a box collider 2d....
Well it needs to have some sort of collider to be detected, yes
ohh i was making a mp game for mobile trying to dodge the mp coding things so i ended up somewhere with chatgpt"s script i spent one day figuring out this and wasted i cant just drop out from this project even tho its my second project if i give up i dont know ill lose motive or something
uh still doesnt work
So is your overlap detecting any objects at all? Does it detect anything on that layer? Try using logs
i recommend to get help not from chatgpt, only for minor things maybe. i find to learn better with help from real people
alright gimme few mins
where to get real people ? for free :)
ask you questions here lmao
If you want people to answer your questions it's usually a good idea to actually ask one
ok thanks
hey everyone i have a quastion so i was making a mp game for mobile trying to dodge the mp coding things so i ended up somewhere with chatgpt"s script i spent one day figuring out this and wasted i cant just drop out from this project even tho its my second project if i give up i dont know ill lose motive or something if somebody likes to help me (for free) just dm me :)
This still isn't a question
And people aren't going to commit to solving your problem in a DM when you won't even say what it is
seems like the only thing its detecting is the player
so its having some issue with the layer detecting
probably im doing something wrong with checking a layer.
although layer number 3 is Box
and the box object has the layer Box
so im not sure currently
ill re-check my scripts
Hey, I’m using Photon PUN 2 (free) for a mobile multiplayer game.
Each player prefab has a camera and a Canvas with joystick, sprint button, and stamina UI — all inside the prefab.
The player prefab is spawned using PhotonNetwork.Instantiate().
❌ Problem:
When Player 2 joins, Player 1 freezes — can’t move or look — and logs:
👻 Not my player, disabling input.
It looks like input scripts are disabling themselves due to this check:
if (!pv.IsMine) { ... }
Also: Players aren’t synced. Player 1 sees Player 2's head move, but the controls are hijacked.
✅ What I want:
Each player to have their own camera + UI + input working properly without affecting each other.
Any idea what might be wrong or how to structure this better? (this is not made from chat gpt)
U guys are killing me😂
Overlap only detects the closest thing. You should probably pass it a layer mask if you only want to detect one kind of thing
oh really now?
yeah i looked at that but i didnt see the text i guess
There's an OverlapCircleAll that gets back an array of hits
You could do that and loop through them, but if you want to look for a specific layer anyway, you should just use a layer mask
right so it only detects one object; the closest one? ok, would CircleCast be any different?
yeah i will
Circle cast is basically firing a tennis ball in a specific direction. Overlap seems like what you want, you just want to set it up to only be looking for specific layers
alright ill try it out and see
{
if (((1 << hit.gameObject.layer) & interactLayer) != 0)
{
pickUpText.SetActive(true);
}
else
{
pickUpText.SetActive(false);
}
}
else
{
pickUpText.SetActive(false);
}``` seems to work
finallyyy, spent an hour on the if statement 
nice one, bitwise operations are a beginner thing
It could also be simplified to pickUpText.SetActive(hit != null && (1 << hit.gameObject.layer) & interactLayer) != 0;
(use the bool comparison result directly instead of using an if)
(and if you don't want to be a barbarian you'd have 1 or 2 named bool variables to express what the condition means to check 😛 )
yea its easier to debug if it goes into a bool and then is used. For simpler expressions its probably not needed if variables have good names
Is there a good guide on how to implement dragging in Unity? I've just started trying to make an infinite runner type game but unfortunately, Unity is too complex to allow raw coding and too raw to simply bind an action to drag
as in
on a phone screen you drag right to move your character a lane right
unfortunately i dont know how to tell the scripts to utilize already given or existing variables
like touchscreen status
save the mouse position when the button is pressed down. Once the player releases the mouse again calculate the direction from p1 to p2
If it would be so nice, but I wish to actually have the game sitting on my phone
meaning i need direct touchscreen compatibility
checking the last and current input pos gives you a "velocity" which can be used to detect a drag.
its possible, i saw "touch" as an option, but i cant for the life of me figure out if it has "drag" as a preset or if i have to somehow read touch position in a script
the big question is: how do i check input position?
im unfamiliar with unitys specific coding
i know c
^ If you are using the NEW input system you can get mouse position as touch or mouse pos:
https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/Touch.html
You can also enable Enhanced touch to get things that work like the old input system touch stuff (do not try first)
The new input system way would be to have mouse pos and touch pos go to a vec 2
alright ill check it out
sorry if i sound stupid, i code a lot but ive never used unity or ue5 or anything of the sort
a little bit of guided godot but thats about it
i want to get into making games but unfortunately ue5 is even less beginner friendly so i ended here
using the old input system you can grab Input.mousePosition each frame and get the difference (current - last):
https://docs.unity3d.com/6000.1/Documentation/ScriptReference/Input-mousePosition.html
If you're talking about a Subway surfers type game sounds like you are looking for "swipe" detection, not dragging?
Or possibly both
is "dragging" object specific? or what sets it apart?
It does imply you would move something
ive been told to use the new input system and android exporting does not properly support using both systems, so says the popup at least
Its telling you the option cannot be "Both" so you have to set it to "old" or "new" only.
yeah thats what i did
but it means that if the new system is better, i unfortunately cant use the old system just for some singular items
has anyone just got a good GENERAL youtube guide series for unity? There's a lot going on that doesn't add up in my head
There is plenty of content for unity online
Check out the docs and quick start guide for input system: https://docs.unity3d.com/Packages/com.unity.inputsystem@1.14/manual/QuickStartGuide.html
I've done touch swipe detection before so I can give some pointers
Just a quick question because this is gonna come up later: Is it possible to run scenes within scenes?
I'd use at least two scenes (Main Menu/Game), maybe more for different submodes within the run like flying or so, and it would require smooth transitioning with scenes
like showing a peek of the area within one tab of the main menu
You can open multiple at once if you load others "additively"
Let me rephrase it more clearly, that was very confusing, sorry
You know Subway surfers, yes?
The game has its tabs on the bottom and top, and then in the middle it has the animation of the guy spraying
then when you tap in the screen in that scene, it fluently goes into the run
That i need to do
Or rather, want
I think that is not worth thinking about at this stage for you.
You need to tackle the basics of unity first
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
The thing is, I've learnt from much coding that usually, I need to think about this stuff first
Else I end with a mess thats, for example, all in one scene, and it's a hell to seperate it
Well what you said is possible for sure but I think you should make sure you understand some more fundamental things with unity first
But you are right, i should learn the basics first, i was just hoping that once i get some basics down, it would flow more easily
which it might
this would just be making the main menu not cover the entire screen in one tab and covering the screen in the others
unless i misunderstand what scenes are used for id use a scene for the main menu
actually scenes in general are very confusing
do people just put the entire thing in one scene
again this is something that you can worry about later
is that socially acceptable
there's many ways to do this, just keep that in the back of your mind when thinking about how it'll flow together
don't worry about the specifics just yet
get something working before you get something good
your first game won't be great, and that's ok - you get experience to make the next ones better
that was why i was making an infinite runner
it can be expanded upon
and if something good actually comes of it theres plenty of directions one could be used
considering i have 0 actual models its just gonna be cube runner anyways
being an infinite runner doesn't really affect "it can be expanded upon"
anything can be expanded upon in terms of ideas if you're creative enough
i rephrase: its easy to expand upon
and a generally really simple game principle
some things can be expanded upon in terms of implementing content depending on how you've designed the underlying systems
how the game plays doesn't really affect that
...i really should just start by making a game that uses mouse and keyboard first shouldnt i
You could make the runner game using just wasd controls for now
you could just reduce the scope of the project you have
And add touch support later
yeah that
ill probably start over anyways
stuff always turns to a mess sooner or later
alright then lets start with the basics
So, now a basic question
how to i change the x position of a cube within a script
have you gone through like, unity essentials, junior programmer
a link would be appreciated
although i might have it somewhere in my page salad
aight you should probably go through those !learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
unfortunately that link still doesnt work
(you can skip parts in unity essentials that you aren't using right now if you want)
thank localization probably
wdym by doesn't work?
by that i mean it redirects to a site saying "oops you broke the internet"
i assume this is because it autoredirects me to the de website which doesnt exist
ignore this
it's on de.unity.com or smth?
funnily enough that page loads in english for me
yeah i assumed as much
the "click here to go to livehelp" works for me, does that also redirect?
it seems that localization doesn't actually go through /de//ja/other slugs for me
perhaps you have a stale cache?
full refresh doesnt help either
neither does vpning anywhere
so browser change it is
full refresh on learn.unity.com/de?
you'd need a full refresh on learn.unity.com without the /de
i took notes on all the basic things i needed to know, but now my next question is how would i know where they go in a script?
can go to /en with the same result, even in german
yeah the localization doesn't actually go through those slugs
i also went on incognito which i believe to have set to use an empty cache
would anyone happen ti have a good tutorial that teaches you how to utilize the things you wrote and learn in what way to write them?
browser change doesnt help either
this is something you have to practice, not something someone can teach you
make sure you understand all those, not just know them
break stuff down into smaller problems, etc
im pretty sure this is just c# coding
you gotta familiarise yourself with the basics of that
or c
or c++
or really any other programming language
well is there a good way to start at least? like how i would use transform and vector3 in the same statement (presuming i would use them in the same statement)
@muted sapphire what about like https://learn.unity.com/pathways
Free tutorials, courses, and guided pathways for mastering real-time 3D development skills to make video games, VR, AR, and more.
theyre all just dialects to one another anyways when dealing with stuff like this
works perfectly fine
that's a very ambiguous and unanswerable question
depends on how you want to use them togehter
...damn, i didn't think it'd work
what do you want to achieve
im pretty sure the homepage is just broken on my end somehow
NO MATTER who needs homepages
i know the terms, i just don't know HOW to write them in the script.
example, if i wanted to make pong, i have the tutorial but i have no clue how he knows how to place where things go.
which is why its like i said
learn c#
or any coding language
its very simple
you don't know where stuff should go, this isn't like a jigsaw where everything has 1 specific place it goes
you design and decide where they should go
so it's.. less like a puzzle and more like a lego?
if we could fuse we might be the best coder
that's a very good analogy. i will be stealing that
LOL
what do you mean by that?
You know the unity terms
oh you mean how i know the terms
I know how to code
but i havent a damn clue how to make my code tell Unity to do something
yeah, i know a good portion of them and their uses now, i have a bunch of notes on the ones i know at least
i sent them to one person, he said they were good, few chop ups here and there
Language you can learn from youtube to the respective language
Logic comes naturally when you begin to understand the syntax and what you actually do
Library is what I'm missing in this case, because I can't tell my code to, for example, move a player, but i can perfectly calculate where it's supposed to be
so you have the wood and hammer, you have the blueprint, but you don't have the screws?
I'm missing the specific screws that would put what I've made to the rest of the machination
you're missing the proprietary screwdriver lol
even knowing the terms you still have to functionally put them together
yeah that sounds about right for coding
i've begun correcting myself on semicolons, capitalization, and spelling, those seem important
yep those are the worst mistakes
i kept making them when i made that flappy bird tutorial
together with plus and minus errors
hm you didn't have autocomplete?
suppose i can see if i can't make pong on my own today rather than follow a tutorial
i had autocomplete, i still messed up a lot
but that usually only happens when you do a programmer and just scatter random - signs around your code when stuff doesnt work
real
i was writing kinematic stuff a few days ago and i just could not get it to work and i checked my math so many times
i had forgotten Time.deltaTime in applying acceleration lmao
idk about judging, proofreading maybe
that works
just need someone with more experience to look at them and see how well i might've done
ofcourse i wrote them IN cs.
you probably don't need that Unity.VisualScripting
i feel like that'll confuse your future self
In school we're doing Coach7 (no idea if that software is common) but thats basically all about that math and it usually ends up looking like a bomb defusal too
if you're writing in c#, you'll generally never touch VisualScripting
VisualScripting is somehow harder than normal scripting
well i have little idea what it is, i just grabbed it from a scipt file in unity and started writing notes
visualscripting is unity's block code thing
lets not worry about that top part, it's the notes i wanted proofread, as a beginner with no experinces
your IDE might've added it if you tried to use something from the visual scripting namespace, like a class. this happens often
your IDE also might have a code cleanup function to remove unused using statements
i think it might be that, i remember having to update my IDE manually and i think i left something unclicked
RigidBody2D //a physics body Transform // the position of the edited object gameobject //a type that can appear in the inspector? quaternion.identity //no rotation vector2-3
you're mixing types and values here - capitalization is important, Transform refers to the class, transform refers to the instance of Transform on the current gameObject

honestly i'd recommend not having this in a .cs file, that way you have more freedom in how you structure your notes
you have if..else, a very fundamental concept, quite far down, separated from for which is in the same category of control flow
i'll only defend myself by saying this is my current understanding of how the terms work
otherwise this is pretty sweet
markdown files ftw
if it works on your end
alright i checked out the new input system
but it seems oddly complicated
also this doesn't work
GetComponent(doorlocked = false);
what happens to "getKeyDown" but no we do "horizontalAxis"
yeah i know, thought i put a note saying that it wouldn't work
i was just using it as a "this how it would look theorhetically, because i don't know how it actually looks"
That's not even the new input manager
What kind of sorcery is that
i intend to come back to this file when i learn more so this is helpful
there's one at the bottom for a separate line of code?
just not for this one
so would you be able to explain this with an example at all?
and yeah, definitely this - would help in structuring your notes a lot
could have separate sections, inline code/codeblocks, lists, checklists
i wouldn't use an example for those
also intended to get to that when i knew more about what i was doing
:((
or something
(do you actually have a question? i can't tell lol)
I was trying to ask whether i had to use the fancy input system package and all the settings that come with it
well, if you want to use the new input system, yeah?
or whether i could just make my code check if a key is pressed using it
you can do that with either system
the old input manager is almost as complicated
welp, time to remake the entirety of the ps2 game 'shadow of the colossus' with my current knowledge.
the real world is messy 😭
you won't believe how well my code will fit in
it won't, they're different kinds of messy
orzo and spaghetti don't look that cohesive.. i don't think
not really, there isnt much to the old input system. the new input system definitely has a steeper learning curve because it comes with way more features and can be customized quite nicely
alright now, how would i get if "up" is the current state
the tutorials are for the old input manager
there are tutorials for the new one as well. "new" being a couple years old already
#🖱️┃input-system has pins with resources
oh yeah i use unity6 btw
it doesn't have a state, it just has a value for the Move action
up just means y will be positive when the binding is triggered
okay, but how do i get that in code
(that kind of question would be more suited for #🖱️┃input-system fyi)
there's like, 6 separate ways to do so
new input system is really flexible, hence the "steep learning curve" comment
for now, i just wanna make a cube move whereever i tell it to with my wasd
i mean, if it's in a composite like that then you'd want to use the entire Vector2, no?
Guys why does it complain when I subscribe to my event and the method is a Coroutine please ? I think I'm missing a StartCoroutine() somewhere but I'm not sure where (it says : Expected a method with 'void OnGameOver()' signature)
did i use a word there that's unfamiliar
yeah invoking the event would just call the method instead of passing the enumerator to StartCoroutine
you'll need an intermediate method to handle the unsubscribing
but Vector2 specifically
a Vector2 is a vector with 2 dimensions, x and y
https://docs.unity3d.com/ScriptReference/Vector2.html
same thing for Vector3 but with z added
that's as far as unity goes in the core lib
And how would I get the entire "Move" Vector3 (or two, if that is that) from the Input system?
it would be the theoretical input.Move from before (it'd just be a Vector2 here, only 2 dims)
i'm typing it out give me a sec lol
so "input.Move" describes a 2 dimensional array
or returns it
makes no real difference but it would force me to use ()
well shoot me i dont even have the input system imported
And what should I return at the end ? Here I'm returning null but it's more like as default choice.
Also do I have to save the coroutine in a variable to clear it later or as I'm reloading the scene, it will handle the clearing for me ?
options, in no particular order (because i don't have the brainpower to sort them right now)
InputActionReferenceas a serialized field, poll thatInputActionReferenceas a serialized field, subscribe to thatPlayerInputcomponent with messagesPlayerInputcomponent withUnityEventsPlayerInputcomponent with C# Events (not sure what that entails)- Generated class, poll that
- Generated class, subscribe to that
you should probably find a tutorial and then just go with whatever that tutorial uses
unfortunately the coding beginner guide on the main page uses input manager
how do i import it in the first place?
it's not a 2 dimensional array, rather it's a 2 dimensional quantity (you could view it as a 2 element array but it's technically a struct)
one dimensional, two element array, im tired sorry
there are separate inputsystem tutorials, but if you're not very familiar with gestures vaguely at everything you might want to just stick to the tutorial for now
the tutorial is unfortunately being very weird around this corner
anyways more realistically input.Move would be an "input action" that you can get stuff from, like GetValue<Vector2>()
ah there, i found some semi decent guide on input system
let me copy paste half the code segment and then figure out what it does
- you don't need to return anything at the end. it'll exit automatically when it reaches the end of the method (since it's an enumerator, you can't actually
return;, youyield break;to stop the enumerator.yield return null;gives a value, which amounts to waiting a frame for a coroutine.) - coroutines exit and handle themselves
yield break, my IDE says Redundant control flow jump statement
yes because it's at the end. it'll exit itself
you know how you don't need to return void methods?
IT MOVES
yeah
yeah there's an implicit (aka automatic) return at the end
oh ok, thanks 👍
same thing here except with yield break
an enumerator is something that gives a sequence of values
when you write a coroutine, you're building that enumerator by specifying the sequence of values
yield adds a step to the sequence
yield return x; adds the value x to the sequence
yield break; specifies the end of the sequence
Hey everyone!
Is there any possible way to add unity messages(info on Unitys Methods) on Visual Studio Code?
That looks advanced 😛 I use it right now only for coroutine to wait some amount of time before doing something else 😄
Like in viusal studio
think of the coroutine yield returns as yielding delays
not what they're referring to
are you sure ? 🤔
I mean just to hover on the methods and see documentation
Yeah I think that's what I sent above 🤔
real quick - is it specifically unity messages, or just stuff in general?
i don't get documentation boxes on hover, only when writing methods
yes, they aren't asking about writing docs, they're asking about seeing them
Oh ok, my bad 😄
I would suggest to switch to Rider, it was the best decision I made 😄
Yeah that works beacuse of the comments /summary, I want just when i hover on to see them like in vs code
no just unity mesagess
that's intellisense, not docs
yeah and in visual studio u get this
This is how it looks like in Rider fyi 🙂
yeah but you don't get any in vscode, right? not just unity messages
vscode seems to have these kinds of settings, but there's nothing for c#, so i don't think this is something you can get with the microsoft extensions. maybe there's a thirdparty extension to do that
any what sorry i dont get u
u mean dis?
Why the message is different from Visual studio? I just want the excact same messaes that are shown in visual studio in visual studio code
I have this issue and don't understand how to solve it as the scene is already in the build profile 🤔
you're trying to load the scene from itself, or...?
gotta give some more context here
I'm trying to reload the same scene I'm in
ah, ok, so they are supported
vscode's, uh, decompilation? just doesn't have very many comments
and messages probably just aren't documented
Try logging the scene name before you load it
See what it prints right before the error
have you tried debugging the thing you're trying to load? i can guarantee it's not what you want lol
@naive pawn solved, thanks 👍
I thought GetActiveScene() returned the name but I had to use name property
static variables aren't reset when loading a scene again ?
it returns a Scene
alright im calling it a day for today, the input system is getting to my head
they really arent letting me just get what keys are currently being pressed are they
I'd gladly manual the entire movement thing but I can't get it to just give a boolean true for as long as a key is pressed
you wouldn't use a bool though, regardless of movement system
you'd just make a vector out of the 2 axes (for the old one) or take the vector that's the same thing but done for you (for the new one)
What about this please ? ☝️
And also do events get properly cleared when loading the same scene like I do right now ?
When you unload a scene all the objects in that scene get destroyed.
When you load a scene non-additively, all other scenes get unloaded
Static variables have nothing to do with scenes at all
so they're completely unrelated
then why my variable gameOver doesn't come back to its default value (false) when reloading my scene ? 🤔
Why would it?
Didn't you just say it was a static variable?
yes it is, that's why I asked the question because I don't know the behviour of static variables 😄
I'll point back here
It's a bit like asking "How come the hat on my head didn't change when I got in a new car?"
Oh Ok I understood now
ik its not code related but i cant find the player input script and im on unity 6, i need some help
Where is your "Player Input" script ? Because your C# folder looks empty
i added that for later, but there should be a script component called "Player Input"
why "should" ? If you didn't create it it won't be there. Are you following a tutorial ?
Yes im following a tut
Are you referring to this ?
YES THATS IT!
Did you install the "Input System" package ?
Go in the top menu > Window > Package Manager > Search for "Input System" > Install it > try to find the script again
click on the little icon for "Unity Registry"
and search it there
got it, but do i say yes?
Yes
ok
thanks for the help
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 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.
After reloading the scene, the game doesn't behave properly and when I click on the first tile it reveals the whole board and it's empty (it has no value). https://paste.mod.gg/nqfwtjojodix/0
A tool for sharing your source code with the world!
Before
After
It looks like your Game manager is a singleton but isn't a DDOL, so when you reload the scene it destroys itself
i wanna update a text based on a variable. is the easiest way to do it in the "update" place in the script? i wouldn't think it's good to call it every single frame since the variable isn't gonna change every single frame
invoke an event where you set the variable and change the text object only when that event is invoked
that would require sending that event every time the variable is changed, correct?
yes
ok, thanks 👍
this is easiest done by using a property and changing the variable's value and invoking the event inside the property's setter then just assign to the property everywhere else you are changing the variable instead of assigning to the variable directly
can you register async Task into button event?
theres a function that must be async Task
in login manager
public async Task GoogleLogin()
{
Debug.Log("Google");
}```
in another UI
```cs
private void Awake()
{ GoogleLogin.onClick.AddListener(LoginManager.Instance.GoogleLogin);
}```
i guess i just turn it into void then
No, like, literally a boolean "isPressed"
If I could just get an output telling me if a key is pressed or not my life would be much easier
Haven't read the convo but I assume you have learnt of the two input systems available?
would there be any particular reason that, when a bounce physics matieral is applied to a rigidbody2D and box collider, upon making contact with a wall, it's speed seems to multiply excessively?
If so, it's a matter of picking which one to use and then using it. Not much else to it
Preferably the new system
to the point that it actually breaks out of the walls i've trapped it in
I have, but was told the new one is better
It is
I mean, in comparison the new one is set up much better and allows for cross input much better
But I'm currently at a point where I'd rather manual the motion outputs in my code than actually fight with the motion system
You can use the old one, especially if you purely use just a keyboard
ironically, I want to eventually switch to touchscreen
Then I'd do it correctly and use the new one from the very start
TBH even if you dont need cross input the new system is better
Just shoots yourself in the foot once you do need it somewhere
depressing, the new one is kinda weird when using simple movement
its an infinite runner, its literally got three possible states plus height
The idea is the same, I don't see how simple movement makes a difference
But maybe you can share your code and it can be reviewed
Because it feels overly complicated
No like I have no idea what I'm doing with the new movement system
But so far I've gotten Vector2s out of jt
isn't it literally a getkey(KeyCode.W)
Which is way unnecessary for a movement system with three states plus height
Didn't work for me but I'll try again
then multiplying the movement by whatever public int/float you use
then multiplying by Deltatime so it doesn't turn into fallout 76
(context, in fallout 76, movement was directly tied to framerate, which meant if you looked down on at the floor to unload everything, you moved faster.)
yeah unfortunately some games do that (looking at you risk of rain 2 update)
it could also be that the movement script isn't connected to your Rigidbody or whatever you decide to use
Yes, but this is the old system
This won't work for touch screen
It just seems overly complicated to run a whole input system for something that can be "0, 1 and -1"
I'd dive in and learn the new input system considering it's good knowledge and you will always use it in your games. Even if it gets a bit more complicated
well, as far as i know, it's more complex to make actually running it easier, say if you wanted to use a controller or something like that you could easier attune it, right?
unless i'm big stupid, that's just the idea i got from others who were talking about it
that and to simplify complex interactions with the code
i'm still trying to figure out why my ball is increasing in speed, or if there is a way to put a cap on it
Oh i might be able to help with that, that seems like a coding issue
What exactly is the problem?
you willing to send the code?
{
bool isRight = UnityEngine.Random.value >= 0.5;
float xVelocity = -1f;
if (isRight == true)
{
xVelocity = 1f;
}
float yVelocity = UnityEngine.Random.Range(-1, 1);
rb.velocity = new Vector2(xVelocity = Flyspeed, yVelocity = Flyspeed);
}
just something i followed from a small tutorial
kind of using it as a test to see how much i actually understand
doesn't seem to fly in any random direction either, which sucks, but that's less important
okay so let me go through this snippet
first you randomize if it goes left or right
or how far it goes right
Randomized left or right
randomize left or right?
I won't comment on the quality of this code
yeah thats unitys own feature cant really work on that
LOL, guess the tutorial i followed wasn't very good (go figure)
wait what the hell
why is a >= chained with a = in a single statement
and why does it work
These are basic comparisons
>= means "larger or equal to"
which is probably the area that it can travel to
ohhh its implied
right?
Sorry, I'm not used to C#, I was expecting a () around the comparison to recieve a boolean
with isRight being a general direction it can travel in? i assume?
at least that's what I would'vs done
i wish some of these tutorials described what they were doing
I should read a short booklet on C# someday so I know its exclusive terminology
like -1f and 1f (which i assume is just to make it be a float value)
actually, do i even need isRight?
since it's all seemingly handled by rb.velocity
unless that's me being dumb again
you do
it's used in the calculation of xvelocity
which is used in the calculation of rb.velocity
doesn't seem to be very random
as it swings straight out or slightly down (which i assume is the .5 at work)
actually hold on
Sounds like you are used to if-statements, these always have them
you set it to "Flyspeed"
you might wanna xVelocity*=Flyspeed
or if that isn't a thing in C# xVelocity=xVelocity*Flyspeed
it's the speed at which the ping pong ball flys
flies
set to.. currently 3
but i have a range on it that lets me change it
unless it is that range that is causing it go faster
the line i sent sets xVelocity to itself times Flyspeed
which i think should be correct
I love how the x value is randomized by this unnecessarily complicated snippet but then y value just gets a one liner
other way around?
but yeah i thought that was weird
also it's still increasing in speed
wish there was a way to lock the speed at which it's velocity increases
because it's going absolutely nuts
think about what locking the speed entails
logically
probably keeping at a singular consistent number right?
do you want to lock the velocity, or how much it increases by
well, that's the problem i ended up with when trying to find it, by locking it, it'll never increase to it's maximum
so i guess i want to limit, not lock
in order to help with that I'd need to know how you handle walls
and there we leave my expertise again
pfff
suppose the answer would be i want to stop it from increasing past my flyspeed slider
thinking about it, i can probably do a reverse flyspeed if/else, just need to figure out how to write it, but it may be easier to find a set of words to actually lock at a certain speed.
so i have this problem where when i auto complete code it doesnt add the right amount of space