#💻┃code-beginner
1 messages · Page 399 of 1
AH valid mb
Also not sure how you were able to make so many inline code lines so fast
i think it just never closed until they did threebackticks
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
found it lol
this problem is like the plague
I don't see the method addPoint being called anywhere
how do we kill it
this is just for having the score appearing in the leaderboard scene
lemme send my other code
why is everyone using the legacy Text
lemme send the code for actually adding the score
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
put a log and debug the collision
the collision does work, it even adds the score
show where you have the Text object in the scene too
i just dont know how to make it save the score and post it on the other scene
-
- Are you sure the method
OnTriggerEnter2Dis called?
- Are you sure the method
-
- Are you sure the
other's tag isbird?
- Are you sure the
-
- Are you sure you want your score to be displayed as
123Points?
- Are you sure you want your score to be displayed as
oh I misunderstood, thought you said you dont see the text
lemme add that space
use persitent object / data
Should the score be saved when leaving the game or just throughout the scenes?
In the first case, you don't even have to save it, as you already have a Singleton
the score should go away when leaving the game, but show when the scene goes to the leaderboard
i already got an online leaderboard thing
Written above for this case
wdym
if you already have an online leaderboard just save it there..
no thats not what I mean
i want the score to appear as text IN that scene
like before its saved
help, what is causing this
You already got a UI Text for this
so where is the score coming from to change the Text in scene to that value
the score is coming from the scene where the game actually is, and is then displayed on the leaderboard scene
so whats the problem ?
before it is ACTUALLY saved to the leaderboard
the problem is iti isnt displaying on the scene
okay wait lemme send a ss
Well, could you show your Text in the scene first?
yes
This seems pretty vague to me
Not the hierarchy, the scene
when the scene loads, the new text in the middle disappears
yes because you need to load the text
This is another scene
idk how I would do that
yea
You already have your score saved in your Singleton
so how did you link the second "Text" scoreText
This probably isn't the correct channel for that question, but what render pipeline are you using?
I am on urp, but that is someone else packages I downloaded
You create a method for displaying the text and call it on new scene loaded
is there a way to use GetKey / GetKeyDown when not having the window focussed? it doesn't seem to work for me. I have "run in background" selected
under the canvas, I have a SocreText object
what
There is SceneManager.sceneLoaded
public static event UnityAction<Scene, LoadSceneMode> sceneLoaded;
how's that answer How you linked the ScoreManager from scene 1 to Text in scene 2
idk if I even did do that
Impossible, I suppose.
What's your camera's "Background Type" set to (in the "Environment" drawer)
your ScoreManager wants to change scoreText.text
you def have null refs then unless you never call AddPoint there
then you need to pass the reference properly
D: that's not a satisfactory answer :C
I want a second opinion -3-
should I have delete other scripts I made that make the objects consistent
i think I should
like the text camera and canvas
i made 3 seperate scripts
i dont wanna bloat my project lol
you should only need 1 script if you're gonna use DDOL keep it simple for now
they are now gone
Well, it doesn't seem to be something you can control. You cannot really tell the window to be focused, because the Unity user is the one doing it. Note that these issues won't happen when playing your game outside of the Unity editor.
Second option: ignore.
put the canvas in the DDOL as child of ScoreManager
I tried it in a build but it still didn't work...
gotcha
that can be your Score canvas. LeaderBoards, Score etc.
Mm, as far as I know, it should
that's what I thought
okay I put it under the canvas
But the player cannot play the game without focusing it.
should I test it?
wait.
okay
you linked Score now from that canvas in the script
I'm not great with render pipeline stuff... but maybe the Skybox itself is scuffed. Try changing that to Solid Color and see if the issue disappears. If so, you might need to figure out what's up with the skybox, or maybe just find a new one
lmk when I should test, ur taking the lead here and im following
lemme see
no bad way to do things
should I delete this
don't blindly follow
other inputs like Microphone do work
like the scoreText
okay, i will be an active participant mb
this usually happens when skybox type is set to none
lol
see how you didn't pay attention thats why you dont blindly follow
just changed it, problem isnt with skybox. The problem only seems to be present in scene view
Also not sure how you tested it. Simply opened the game window? When doing so, your tab is not focused, so you first have to click somewhere within the game window
so it doesnt clear the last buffer
if you changed any editor settings that somehow got rid of skybox then revert it
I need it to work without being focussed on the game window though...
okay I did it
sorry, yestarday I worked on this for like 15 hours
like the whole game
btw this means the score text will be on the same spot in the different scenes
you can sure
thats just the checkbox right?
I dont think thats the problem, has to do with the render pipeline
well you would have to toggle that in code then
okay valid
which leads you back into detecting when scene changed occurred
okay
the alternative is have Other script inside Scene 2 detect when there is a ScoreManager in awake/Start
then just grab score data for Text component / Canvas in that scene
should I send my code that detects when lives = 0?
Don't want to tell you that it's definitely impossible, but some time ago I was not able to find any way to do it, so it doesn't seem like you're able to "force" the player to focus on your game.
It seems like you should use the Application.isFocused boolean in suitable parts of your code, and (or) wait until the button, which activates the game, is pressed.
irrelevant rn
okay I shall not
forcing it to be focused kinda breaks the purpose of the project as being in the background
Well, the most important thing is, do you actually have to have your player focused?
okay so whats next
I've outlined two options for you 🤷♂️
I don't want the window to ever be focussed, I just want inputs to be recognized when not focussed.
okay wait what do I do with this
i dont just
copy it in right?
that would make 0 sense
again, thats needed if you don't go with Option2
yea ik
Well, this shouldn't be a thing. Are there any apps you can think of, which do this?
which do u reccomend?
idk :I
trying to find stuff about it
both are valid. I personally would have the object in scene2 only do work when it detects the Scoremanager
okay I will do that
It's definitely possible to send input events to unfocused windows via OS calls... Like AutoHotKey and similar software does so. I have no idea how you incorporate that into a Unity game though. Worst case, I imagine you could create a second standalone executable which launches with the game to handle that functionality.
If the UI Text is only meant to live on scene2 but scoremanager needs to be in multiple scenes, no point on having it carry canvas with it here..
okayy
Just checked and Discord does that.
I hate using this channel so much but I don't understand what I'm missing here. This seems like it should work but it doesn't. Where have I gone wrong?
using System.Collections.Generic;
using UnityEngine;
public class InventoryCloseButton : MonoBehaviour
{
bool isOpen = false;
public void ButtonPressed()
{
GameObject.Find("Inventory").GetComponent<Canvas>().enabled = false;
isOpen = false;
}
void Start()
{
GameObject.Find("Inventory").GetComponent<Canvas>().enabled = false;
isOpen = false;
}
void Update()
{
if (Input.GetKeyDown("e") && isOpen == false)
{
GameObject.Find("Inventory").GetComponent<Canvas>().enabled = true;
isOpen = true;
}
if (Input.GetKeyDown("e") && isOpen == true)
{
GameObject.Find("Inventory").GetComponent<Canvas>().enabled = false;
isOpen = false;
}
}
}
What does "doesn't work" mean
What are you expecting to happen that isn't happening
or what is something that you're not expecting to happen but is
The canvas isn't displayed
do I make it not a child anymore?
It works without the bools and the second GetKeyDown though
But I want e to close the canvas on the second press
my dude just storre the canvas once in a field private Canvas what is going on with all the Find
so how do I edit the code to where it detects when it appears
nope
Is it really possible? When having 2 windows opened at the same time, and e.g. scrolling when focused on the 1st window, does it mean the 2nd window is also going to receive the input?
because the Objects in scene2 run Awake/Start when scene is initialized
assuming they're not gameobject disabled
If my craftying system is based on the number of objects you have on the crafting station (for example: If I place 3 sticks and 2 stones it will craft a hammer, the order in which this objects are placed does not matter just the number of them that are in the station at that moment). I am also using Receipt ScriptableObjects but what should those objects have, any ideas?
After I think about this, it should cause users even more troubles when wanting to do something on the focused window, and doing unneccessary things on the 2nd instead
what is "that" lol speaking vaguely
im sorry
https://github.com/elringus/unity-raw-input?tab=readme-ov-file
I think I found it
i meant make them unrelalted
So, read through the Update function in the order the code runs:
- Check if you pressed
ethis frame. For the sake of demonstration, let's assume yes. - Check if
isOpenis false. Let's assume it is. - Enable the canvas (you should cache this reference please for the love of god don't use a find in update)
- Set
isOpento true - Check if you pressed
ethis frame. As established in step 1, you have - Check if
isOpenis true. As established in 4, it is - Disable the canvas
- Set
isOpento false.
There is no possible outcome in which the canvas is enabled when this function ends
just unparent the canvas.. put script to change UI only in the script of UI objects in that scene
ScoreManager should only Keep track of score, or modify it
it should not deal with UI
okay unparented
I see, after reading the description, it seems like there is a huge point in receiving specific keys in the background.
#💻┃code-beginner message
also no need an update for everything you do
like leaderboard scene
okay
put the script that changes UI in the scene that has the UI doesnt matter which object you put it on..as long as the reference to the Text object is properly linked in the inspector
I assume you could do that, yeah... Like you can definitely capture input events regardless of which window is consuming them. And you could forward the events to another window if you have it's window handle, or possibly process ID?
This isn't a realm I've explored to a great degree, but I believe it's all plausible. Absolutely no clue how to accomplish within a Unity game though, or even how you make calls directly to system libraries 😁
@wooden socket don't forget about [this thing](#💻┃code-beginner message)
ScoreManager should not touch the UI
okay
And how can I check the object can be crafted using the receipt
not even needed anymore. The UI Script can be its own script that changes the UI element in scene2
could anyone explain how'd use raycast to check if the player is colliding with a floor or wall
it needs to be a script in scene2 so yes its a seperate script as I said already
ScoreManager scoreManager;
private void Awake()
{
scoreManager = ScoreManager.instance;
if (scoreManager)
{
myUiText.text = scoreManager.score;
}
}```
Yeah, it seems like it might be needed when e.g. updating the application's music with a long Ctrl + Shift + Alt + +
Raycast in the direction the player is moving. RaycastHit has a normal property to get the normal vector of the surface it hits.
https://docs.unity3d.com/ScriptReference/RaycastHit-normal.html
You can use the dot product of that normal with Vector3.up. If the value is close to 1, it's a floor. If it's close to 0, it's a wall. If it's close to -1, it's a ceiling. You can adjust the allowable difference in the dot product to change how sloped of a surface you want to count as what
How is this script going to receive the score?
Pretty dumb. Instance.
i don't know what raycast is
Then that should probably have been your first question.
https://docs.unity3d.com/ScriptReference/Physics.Raycast.html
thanks
my UItext should be renamed to what i called the text object? I called it displayText
ok that didnt work
yes 2+2 is 4 lol
a raycast is a check to see if theres an object at a location.
e.g. if you raycast in front of you, you check what object is in front of you.
doesnt exist in current context
how can I check if an object is craftable (using Receipt ScriptableObjects) only based in the quantity of each object inserted in the Crafting station?
can you show what you actually wrote instead of speaking in vagaries
whats a receipt gameobject
oh
Didn't work? Have you not succeeded in renaming the text object to "displayText"?
Also it seems like all the texts can be called "displayText"...
this error is meaningless..
THATS AN EMPTY NOT TEXT
show what you actually wrote
Found a solution! Instead of having both if statements I swapped the second if statement for an else if. Thanks for the breakdown!
What is displayText
my ears.
depending on the objects inserted according to this receipt, it will generate an object in the output
It doesn't exist.
you havent made a displayText
could you show us whats in this receipt
why didn't you make a field for it..
in fact cant you just add a bool to say if its craftable
Irrelevant
youll also need to do it in code
this isnt even related to the script..
ok
There's nothing in the script named displayText
scripts have 0 knowledge of whats in the scene hierarchy
you made a thing in the scene called displayText, but your code dont know what displayText is
naming the object displayText doesn't magically appear in code lol
that would be a nightmare
so i make a new field called what
All my Container objects 🥵
Name an object "this" and watch the world explode
you can name it whatever you want as long as it has the type TMPro.TextMeshProUGUI
name it whatever the hell you named the the non-existing field ?
dumb name but theres an explanation for it
their Text isn't TMP apparently
Names don't matter, call it whatever you want
A field needs two things:
- the type: what it holds
- the name: how you refer to it
The name does not matter, as long as C# allows you to use the name at all
what the sigma
ok then make it have the type UnityEngine.UI.TextMesh
So it's like a beam from the player in any direction for a given length?
just make sure the type is correct @wooden socket
yep
and if the beam hits something then you can retrieve it
why the hell did you put brackets
hmm so the origin of the beam would be the center of the player?
so lets say you want the player to interact with an object they're looking at. to get the object they're looking at, you do a raycast from the player's position in the direction they're looking at to get the collider
at this point you need basic c# courses pinned in this channel
idk how to make a field im sorry
it depends on what you want, but in your case you can make it from the center of the player
oh you should probably do c# tutorial before coming here to unity
immediantly after this I will do as much research as I can
it will save you a lot of brai ncells
you literally made them already thats why
this is in 3d context right?
tbf thats just copypasting stuff online
this works for both 2d and 3d context
"as much research" its not that diffcult.
"What is a field in c#" or some shit
instead of just guessing it
This complete C# tutorial for beginners will take you from the basics of C# programming to advanced concepts.
✏️ Course developed by @CoffeeNCode
Learn more from the course creator: https://www.udemy.com/course/csharp-complete-masterclass/?couponCode=FREECODECAMP
⭐️ Contents ⭐️
(0:00:00) Introduction
(0:01:56) Installing Visual Studio 2022
(...
boo
c# tutorial
okay got it
freecodecamp saved me a lot
then you see how simple it is to google something and know about it?
as a programmer you learn everything by googling
Oh i see how you could use it in 2d so how do I set the raycast origin?
reading the manual and googling sure
manual always comes first
for 3d, we normally do Physics.Raycast. but for 2d we use Physics2D.Raycast. bring up the doc page
at this point you're just guessing
im not
i find it interesting how the first programmers who had no internet could only consult manuals and maybe a few $200 books, now everything is so convenient
im genuinely trying to figure this out
string is a type. Text is also a type
thats what happens when you skip the basics
no one is saying to learn the whole language overnight, but the basics are needed
i just am worried to google stuff because I want to make a career in game design and i think it would look bad to google stuff so I want to remember it all
is that wrong/unprofessional?
string, int, float, double, bool are primitive types.
TextMeshProUGUI, MeshRenderer, Rigidbody are all classes. classes are made off primitive types
which makes a lot of the paid courses very sad coming from old timer where internet was literally not an option
so much good info out there for free, you just need critical thinking skills
there is no memorisation in programming
pinning this to my wall
imagine paying for $2000 bootcamp in 2024
yes we did and, no IDE's just a basic text editor
thank you
the world before the internet was almost a better place.. bitter - sweet the internet was
yes thats what computers are for
we have the luxury of hitting one button to compile now, last time we had to precompile -> compile -> assemble -> link with several different tools that could cost hundreds per license
im too young for that 😴
true programmers use code that don't need compilers 
I still pack around my step-father's Kernighan & Ritchie "The C Programming Language" like it's a family heirloom
okay so no more errors, but the text still isnt appearing
ok lets see your code now
yeah thats right its not magic
the script is on the text object under the canvas called displayText
my first computer was black and white.. and my dad wrote code on a Commadore 64, with just a tiny couple line display and code he got from magazines 😉
there are serveral steps involved
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
could you also show the inspector panel of the gameobject that the script is attached to?
yes
you have not made a Text
so you cannot even copy correct
^ i wish everyone would ask this originally.. should be a requirement lol
the issue is they never even call .text anyway
ooof-sicles
i literally spoon fed them the way to do it and they copied wrong
i will give a step by step breakdown of what you need to do.
- add a public
Textto your class. - set the text of your
Textto your score, as a string. - in your scene, go to the gameObject that the script is attached to. drag the Text in your scene into the field
im sorry if im messing this up a lot
issok we will all learn
no worries.. thats how u learn
its fine to learn, but dont blindly copy. if you dont understand something You ASK dont guess
to delve straight into unity is a big undertaking, I'd rather do projects in c# without unity first
should the script be on an empty or the ACTUAL text object
uh its up to you?
as long as u drag in the Gameobject the Text is on into the slot u declaared in the inspctor
it doesn't matter where the script is
most times it makes most sense to include it on the object its manipulating the most
ideally you dont want to put scripts on UI elements
like u'd put a rigidbody controller on the object w/ the rigidbody.. vs putting it on a random empty
how come this isnt working?
they are difficult to find
If my crafting system is based on the number of objects you have on the crafting station (for example: If I place 3 sticks and 2 stones it will craft a hammer, the order in which this objects are placed does not matter just the number of them that are in the station at that moment). I am also using Receipt ScriptableObjects but what should those objects have, any ideas?
im trying to figure it out
its gameObject
the return type of FindGameObjectWithTag is GameObject.
you want a LogicScript
the function returns GameObject
sorry should have been more clear i dont understand the error
how do you get a LogicScript from GameObject
GameObject is a type (could be any gameobject)
gameObject however is this gameobject.. the one ur working the script on
the function you are using returns the GameObject type
you're supposed to tell it you want also another component on it
we dont know what a Receipt is
or what any of your code looks like
okay we are getting closer. now it just says "NEW TEXT"
make ur GameObject -> gameObject in other words
or just simplify it to
logic = FindObjectOfType<LogicScript>()
^ yes this too.. but i find as a beginner keeping gameObject around tends to help solidfy the idea
same with this
but people argue thats not needed either.. which its not.. but 🤷
you've added a gameobject to the scene 🎊
the next step is to let your script know it's there. in your class, make a public Text scoreText. we will only help you once this is ready
I´ve placed three smiley faces and two weird faces, I want that the crafted object is made out of these faces without taking in account the order they are placed in
my question is, what is Receipt
correct they are different type
we dont know what Receipt is
Is Receipt a recipe?
its in
even if its misspelled as Recipe we dont know what it has
awesome thanks. im using the gmtk tutorial, and i think some of it is outdated
yes, sorry
ok could you show us how you added the script to the gameobject?
I think you might have skipped a .GetComponent<LogicScript> maybe ?
An ScriptableObject that I can compare to the ones in the station to determine if an object can be crafted
what is in the scriptable object
nah, most tutorials still hold up today.. Unity hasn't changed too much... there may be a function or two that has changed names (your IDE will tell you that kind of stuff)
since you said not to usually add scripts to text, I made a new empty
Thats what I want to discuss, could you give me any idea?
thats fine
this is wrong though
yep... maybe i should let him finish his sentence...
ScoreManager is a DDOl it should not hold any references to any scene object
idk how many times i had to say that
sorry for my impatience lol, thanks for putting up wit me
nicee scoretext is added correctly. look through this article: https://docs.unity3d.com/2018.1/Documentation/ScriptReference/UI.Text.html
look for the part that says The string value this Text displays.
yes this.. logic = FindGameObjectWithTag("Logic").GetComponent<Logic>(); is probably what the tutorial has @severe lynx
altho thats a hella long line of code 😄
its not, its on the wrong script
changing the Text's text will let you change the script
its referenced correctly they dont know how to change the value of text
gonna make extra dependencies for no reason
Scoremanager is a DDOL having the reference will just break
ohh it is..
thats why its been said from the beginning the UI Text belong in its own script in scene 2
I shouldve known
I mean you kinda started interjecting without seeing the original problem lol
why not use a static variable for the score rather than introduce ddol
yo can someone help me rq, im trying to load up smt i made from a video, and i copied the exact script he said, i can ss if someones willing to help
we can help you here
DDOL are cleaner imo
the score is as static
especially if its a system
ill send ss 1s
and they also did a DDOl
strange combination but sure
wait shit lemme clarify
dont ask to ask, just ask . . .
u can static a variable.. im good with that.. but a DDOL is better for a Manager type script
You can't tell by now they're just guessing their way though it?
its saying this, i can send screenshot of scripts
i can tell now yes
this is in the new script i made
a big part of learning programming is throwing shit at the wall until it works, then learning why throwing shit isnt as good as doing it properly
yeah, im just new here im just trying to be nice
you need to yes..
but not a screenshot
use !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.
okay so why did you show ScoreManager still with a Text field
one of these methods
and you still copied the awake wrong..
make sure you copied everything 1-to-1, exactly . . .
im sorry
i will try to help you but uh
before i came here, i went there and i copied the exact same thing
i'll spit out some code/logic from time to time.. but yea i think u need a bit more understanding of the basics
1s im sending script
unity is a strange place theres multiple ways to do one thing
!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.
the error is with the Character script. can you post that, and also their version?
ok
is displayScore attached to the Text?
or to a manager?
the version is -2021.3.39f1
irrelevant
displayScore is added to the text component
no, the other person version of the Character script. you said you copied, so we need to see what you copied from . . .
I guess at the very least, it needs to identify the required items and their quantities, and the item which they produce.
So maybe like a
[Serializable]
struct RecipeIngredient {
public ItemSO Item;
public int Quantity;
}
public RecipeIngredient[] Ingredients;
public ItemSO Product;
...or similar
ok nice
under Start, could you set displayText.text = "This text is working!"? just to double check it works
thats like saying, you can just get behind the wheel and start driving, you dont need to know anything about How traffic laws work..
when making an item, you need the ingredients, their required quantity, and the item produced. that's all . . .
If ScoreManager is a singleton there's no reason to keep a local copy of the variable
just use ScoreManager.instance
ohh digi in the house
changing displayText.text lets you change the text shown on screen. you can use this to display the score as well.
yeah that one is my bad
was going to add unnecessary null check lol
the article that I sent earlier also has a lot of cool stuff you can play around with
!code
ohh god.. did u not read the bot message?
📃 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.
its not letting me send full
i can't see on mobile . . .
theres 5 or 6 of em posted
plus there are no line numbers . . .
private void CalculatePlayerMovement(){
_movementVelocity.set(_playerInput.HorizontalInput,0f,_playerInput.VerticalInput);``` heres the good part
every one of his errors are on that line i believe
wtf
you are expecting people to pay attention
mb
!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 wonder what's the process to contributing to the unity dyno bot here
i wanna try my hand at making a bot that auto pastes stuff into the paste site
sorry, i cant understand it, i went to the 2nd website pasted the code and idk what to do
talk to the moderators
send the link
and then they'll talk to the Admiins
go to https://gdl.space/
paste your code
done
too much potential for abuse
oh if they let use have bots in here it'd be OV.. i'd have a bot response for everything imagineable
this?
I kind of liked it better when the bot just deleted unformatted code
yep
lets gooo
oh my why was this eever removed..
i did it
Too many false positives
okay im REALLY close. the "this text is working" part worked. I just need to learn how to pass the value from the scoreManager script into a string and add it to the points
whats in scoreManager actually
like the points part of the text object
now can you show the person's code you copied?
until the next problem 
or a link to it . . .
do you know how to use scoreManager.instance?
i can screenshot it
Okay now what is the actual question?
scoreManager.instance.variableYouWant = newValue;
lets talk about line 20. you just set movementvelocity to the player's input, now you're setting it again
i see one of the issues and possibly the other two, as well . . .
Vector.set <--
also line 21, *- is not a valid thing
presumably, the score is a variable on your ScoreManager. ScoreManager is a singleton so you have a reference to it, just get the variable from it
okay I think you figured out the problem. inside of scoreManager, there some stuff with UI and thats not good
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
geee I wonder
"why doesnt this work"
scoreManager.instance.score; 😉
what do i do instead?
what is line 21 supposed to do
What are you trying to do
what does his code look like? on that 1 area?
What were you intending that operation to be?
wait let me make this easier imma send a ss, of the other person
ill send it 1s
big hint: scoreManager.instance.score is an int. we want it as a string
okay
jesus h...why does Scoremanager still have public Text scoreText;
c# things: how to convert your variable to string?
please do, i've been waiting . . .
you're just gonna get a Null Reference on the next scene if you try add score..
@orchid pewter one error is Capitalization... its Vector.Set not Vector.set
theres a displayScore script attached to the text right now so things wont go horribly wrong
im super new to this im trying to make a 3d game, from a course i bought from udemy, i just did everything he said, and copied everything, this was supposed to be a player movement
1s yall
ur making simple mistakes
udemy course 
misspellings and capitalization errors
that's the one i wanted to screengrab from the other person's code. i bet that is there . . .
oh i know it is
Show their code
all the udemy courses jump straight into unity and want buyers to wing it in c#
you realize in the next scene there is no scoreText refrence in the ScoreManager
im finna do this 1s
i've (we've) been waiting for their code for what seems like forever . . .
garbage
as in, displayScore is attached to a Text in the scene thats not on DDOL. the scoreText on the ScoreManager doesnt do anything for now
theres a raccoon among us
that's it, i'm making a udemy course. all GetComponent and Find calls . . .
Bandit 😉
throws my money at you
it does, Thats why i said if AddPoint is run in the next scene it will null ref
i cant send ss, it turns dark yall
well i alrady mentioned ur main error
Then I'll just pre-emptively post this anyway
"I did it exactly like the tutorial so why does theirs work and mine doesn't" counter:
Number of times it wasn't exactly like the tutorial: 167
Number of times it was exactly like the tutorial: 5
Number of times the code literally did not exist: 1
2022-07-19 to 2024-06-26
hey, it's a good way to fund a game, no? or my creative passion . . .
can u go back to it
im tempted to make a c basics course promisinig to eventually move on to game development eventually but teaches development for embedded devices first so they learn to treasure the novelties of memory-safe programming languages and appreciate c# and not think they can wing it through unity
need a live counter of this
u work on embedded stuff?
learning C to use C# is just plain a waste of time
i cant see what line it is
not anymore but I did it for school for a short time
know a little here and there
its torture lol
no vector?
It is a live counter
velocity?
movementVelocity is ur vector
Every one of these is one I personally witnessed
my salutations
ahh ok thanks, sorry for not understanding shi btw, im very new to this
_movementVelocity.Set(otherVector);
i believe thats it. i've never set a vector that way before personally
ok, i reload now ye?
yea we all just vel = new Vector3(1,1,1)
well save and let unity recompile.. it'll clear atleast (1) error
ok, I´ll try that, thanks
damn, C with embedded devices? that's from the beginning. i just started C++ just cause. all the pointer stuff is crazy, from raw pointers to shared_ptr and unique_ptr, delete, etc. using const everywhere and separate files for definition and implementation. very different from C# . . .
the way of the pros
im really close again. im sorry if im being annoying or unhelpful. my code for scoreManager looks like this. I even converted the int to a string, but it still says new text. What am I doing wrong :( https://hastebin.com/share/rabubiqomo.csharp
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
i have a mild disdain for c++
feels like a sin coming from c++
creating a new object just like that
the link dont work
i just started embedded C development.. soo far its as a pain in my ass as i thought it would be 🤣
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
wtf how
that site sucks
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
use gdl
THERE we go
i do all the time. only for vectors that already exist. no point increating a new one if you already have one . . .
well i meant. i do vel = myVector;
i wasn't necessarily talkin about creating a new vector
looks good, what's wrong here?
no it doesn't
the question is how do you get myVector
public static implicit operator ScoreManager(string v)
{
throw new NotImplementedException();
}
}
``` wtf goin here
for some reason it still says "NEW TEXT"
pre calculated / assigned
ohhhhh i see what ur saying
this is the wrong script
oh i must have misclicked
this is in ScoreManager. because of the way you set things up, scoreText isnt set to anything right now
wow, that's scary. i'm just going to make a text-based dungeon crawler with C++. so far it's not too bad . . .
You have to remove the public ScoreManager scoreText;
there is no point of storing Scoremanager in ScoreManager thats nonsense
fun stuff. if you want a very simple graphics library you can give Raylib a try, I use that to teach people brand new to programming
Are you still trying to display the text . . .
bro fr
You got this . . .
it says that Vector3 does not have a definition (in this case, a method) called set. in the tutorial double check what they did and make sure yours is the same. then come back with the result . . .
could it be because of scoreText.scoreText?
its probably with a capital S
teach man to fish..just feed man to shark and get it over with..
ur talkin to a wall
ok at this point you're just trolling
yeah, thanks
why in the shit is
public ScoreManager scoreText;
inside ScoreManager
explain that
your ide needs to be set correctly
i told you I just removed it
teach a man to shark, so you can shark more people
wow.. it just tells you like that?! thats amazing... 😈
@orchid pewter yep, i want them to find that the difference is in the capitalization so they understand that C# is a case sensitive language . . .
So onto the Next Script, show that
Light a man a fire and he's warm for a night. Light a man on fire and he's warm for the rest of his life 😉
this is the way
oh, tysm, u helped me alot
okay before I send it, I just added the public ScoreManager ScoreText to the new script
why
im sorry let me undo it
let's explain the science here.
ScoreManager's ScoreText is set right now. however, when you switch a scene, ScoreManager's ScoreText no longer exists. it is null.
do you still have displayScore?
you're just adding shit to scripts just for shits n gigs it seems
could you use displayScore instead of ScoreManager's scoreText to display stuff
i can try it
blind leading the blind
the big problem of throwing people straight into unity as a beginner is explaining the concept of mutability, how do we tell people that references can be null
how about saying it about a dozen times?
does that click?
This is the beginner channel. Let's try and give folks the benefit of the doubt. If you're not into it today or have an impatient mindset, try and step away for a moment 😊.
i have displayScore script yea
beginner is no excuse for not paying attention
ok nice
in displayScore, probably in update, set the Text's text to Scoremanager.instance's score
literally hand fed the solution and they still write their own lines just because ?
remember the days when game development was only for people who graduated specialising in computer graphics
It kind of is. They may be struggling with understanding your messages.
thats nonsense, i have no background in that..all it takes is a bit of critical thought
Impatient? They are extremely patient for someone trying to display the text for hour and a half, it seems.
how do I do that
erm
do you remember what's in displayScore
the Text that you had
Hello i am New to Unity im trying to make a mod For My summer Car. I have the Model But im doomed i cant code any tips or anyone can help?
man im sorry. ive been awake for over 15 hours working on this game and im really tired and just want to finish this part and then ill go to bed
Haven't you gotten to this point yet . . .
then take a rest.
youre trying to make a mod? have you decompiled the game yet
you being tired should not be a waste of time for us
I'm sorry, but discussion of modding is not allowed here
#📖┃code-of-conduct #854851968446365696
Oh sorry im new here
All good. Best of luck!
display score contains public Text scoreText and public Text displayText
its very helpful to know how to actually use unity now that you've decompiled the game, though we cant discuss that here you should know c# before you continue at all. focus on learning c# before learning unity, then learning to mod
Instead of piecemeal description, you could show the actual code
i mean i did code on roblox meh.
lua is different tbf
That is basically modding.
Yes.
whats the command for the paste stuff
remember how you changed the Text earlier? something like displayText.text = "Swag". you can now replace "Swag" with the score, as a string
how do you convert the scoreManager's score to a string
okay in the update I wrote displayText.text = and now I think thats how you do it but i dont know what to put here
why is it in update..
simplicity sake
lets save us all the sanity for now
how do you get ScoreManager's score from within displayScore?
also heres the entire code https://gdl.space/rugogafuye.cpp
know the policy here: we will not give you whole lines of code but point you in the direction instead
ScoreManager scoreManager; isn't needed anymore
scoreManager = ScoreManager.instance right?
ScoreManager can just be accessed when you need it with .instance
❌ thats for getting the ScoreManager. we now want the Score from the ScoreManager
is this the part of recieving the score or passing it
this displays the score, what do you think
ok
I suppose we're receiving the score? we want to receive the score and use it in the text
i dont know
im really sorry
i know i look really stupid
i just want to get this done
but where can i learn c# for free mind asking?
in the beantime we should talk about the rubber ducky method. take your nearest rubber ducky or person, and explain every line of code you have to them
You refuse to learn for 30 mins how to properly do some c# basics, instead you rather waste hours on one thing you barely understood
thanks
https://www.youtube.com/watch?v=YrtFtdTTfv0
freecodecamp saved my life. in the meantime im making a tutorial too
please tell me how to do it
this implies you want short form c# videos. why would you learn c# from tiktok
have you seen the ones on microsoft learn?
It does not imply that
they are delivered in short bursts
your ScoreManager contains a Score, which is an int. you want to convert this to a string.
Youtube is simply a bad place for learning code
ms learn uses so much nerd terms
"nerd terms"
i learn much faster reading
what
ohh then I use ToString
if its not a string originally u have to convert it to a string yes
this entire page is unreadable for beginners even though its helpful
yesss
now you got the string you can set the text to it
this is the API documentation
not the Microsoft learn site
those 'nerd terms' which you disparage are technical terms and they are used for accurate communication
False
I mean dude is reading API expecting "non nerd terms"
this is from learn.microsoft.com though
what would the final line in Awake be? just scoreManager = score.ToString().ScoreManager.instance?
You need to know the proper terms for things because that's how you communicate. Try reading any tutorial with every noun replaced with "thingy"
I can see the references of API on the side
i have friends that talk like that 🤣 soo sad
thats not the video format i was talking about now is it ?
Score managers score
You'd access the referenced manager via Instance property and read or write to the score.
it is still from ms learn though
i want to find a way to exclude pages like these from my searches
yeah lets keep changing goal posts
Yes, that random thing is from ms learn.
It is also not what they were talking about....
Do beginners need to worry about the Action class?
wrong way around actually
we want to get ScoreManager's instance's score as a string
All the "base unity" functions such as OncollisionEnter() come from making a script inherit from monoBehavior right?
Is there any "unity custom function" that doesn't come from there?
its very convenient
bro is trollin
in the script that changes the text.. u can access the gameobject
wait gimme a se
What are you asking for.
It is. But not for beginners, I think. Unless they come from FP, but then they can read the help text anyway, most likely.
Same for update,start, fixed update...
we dont want scoremanager as a string, neither do we want to set scoremanager as a string to something else
theTextUrChanging = ScoreManager.instance.score.ToString();
Just that, if all of the unity functions come from monoBehavior
No, those are for MonoBehaviours, and Scriptable objects have similar
^ read the lines of code in pieces.. this.this.that
they all come from monobehaviour but note that monobehaviour also inherits from behaviour
but yes
Serious question: Do you know what = means in code
scoreManager doesnt exist in the current context now
So I can check monoBehavior and see what functions do I have in unity
Yes, the ones on a MonoBehaviour at least
oh believe me they will mess this one up too somehow
But there are methods on other types as well of course
So checking the monoBehavior page I should see all the functions unity has and that the engine allows me to do by default
This is called the "api"
yeah
Copy and paste will still fail if not within their specific context - zero integration unfortunately 😅
i think they're ignoring the most important comments anyway
okay I added ScoreManager scoreManager back bcs someone told me to delete it earlieir
replace it with ScoreManager.instance because you removed scoreManager
yup thats how i know its troll
no its fine keep it deleted
Sorry for pointing my "let's behave" finger at you earlier. They should take a rest and come back to give it a try again later 🤓.
https://docs.unity3d.com/Manual/ExecutionOrder.html
This shows all of the message functions, and what order they are sent in
K thank, I was just a bit confused because I thought something like "OncollisionEnter" would be inside a collision component
Like boxcollider2D.oncollisionenter()
now that I think about it yeah why is OnCollisionEnter in monobehaviour
Or something like that
then where does ToString go? doesnt it go after the instance or before ScoreManager?
it goes After the number or int or float or w/e it is ur wanting to change to a string
Shouldn't it be inside a collision component ?
no worries. I'm quite patient when the situation requires, once i see someone isn't even trying and just careless wasting everyone time. Thats where frustration sets in
ToString is not applied to ScoreManager. It is applied to ScoreManager's instance's score
Yeah that link is the order, and the monoBehavior the list of functions they have right?
on a normal day in c++ you'd make an interface, and register the object in the physics server
but unity did not seperate collision from gameobject
Rigidbody and Collider both have that method
does it go before or after
Neither
it goes after, since it s the ScoreManager's instance's score
They do? I was searching for it inside those 2 components and didn't find it
This contains the list of functions Unity will call on an object that derives from MonoBehaviour
you want to get the score from the ScoreManager's instance, as a string
I don't like to use "premade" functions unless is something basic
i put it there and it keeps saying it doesnt exist in the current context
It goes after an integer, float or some type that needs to be converted to string.
You are confusing many concepts
You should absolutely make use of the api
AND in the scoreManager script itself it says the name scoreText also doesnt exist in the current context
Yeah but you can't do something like boxcollider2d.oncollisionenter()
but thats the purpose of the engine, to give you premade stuff
you dont need every game developer to write the same box collider
No, because that makes no sense
It is a callback.
Well in this case, it is a magic method using reflection, which gets a message sent
Components can have their own functions right?
Then why wouldn't it make sense for a collider component to have the collider trigger functions inside of them?
yes. to be precise, a Monobehaviour is a Behaviour which is a Component. thus, if you choose to inherit from Component for some reason you can add your own functions
Could I do something like mygameobject.mycollider.oncollisionenter() instead of the default one?
sure
No
i think fixing one will fix the other 2. Im really sorry
so you cant define the function of an object from another object
I guess yes, you could create your own method that would not be called by unity. But it would not work the way I think you meant. It would be a completely different unrelated method
That's why I asked if the collision components unity had don't already have their own functions
So it's just unity that instead of making the collision functions inside of the collider component, they did it outside of them?
its a Collider thing even though its in Monobehaviour for some reaosn
no
Some of MonoBehavior's members are just for convenience or common caching... like GetComponent() is a shorthand for gameObject.GetComponent(), transform is just a convenient shorthand for gameObject.transform which itself is a convenience and cached reference for accessing gameObject.GetComponent<Transform>()
It is a magic method, and they use reflection, as I said
your objective is to set the Text's text to ScoreManager's instance's score as a string
That's what I thought, I just wanted to use the long wording at the beginning so I can know where things come from
im sorry to be that guy, but just tell me. I feel genuinely ill from how much ive worked on this straight and im very tired and I feel so badly for coming off so stupid and incompetent
It is against policy here to just tell you. Sorry
damn
They're callback functions and are basically subscribed to Mono Behaviour - with some magic, relative to implementation.
So monoBehavior is like "here have some shortcuts to your code"?
Where does "OnCollisionEnter()" come from exactly then?
You need to take a second and actually think through what the code is doing. It's not magic runes, the words have meaning, just as much as the ones you're reading right now. You don't need to memorize what code does or have someone tell you, you can read it and know what it says
Also saying you're tired just comes off as a lazy excuse, the sensible thing would be to work on this with a Fresh rested mind. No one in their right mind wants to code tired. you get no benefits when coding tired.
Nowhere, because OnCollisionEnter takes a Collision parameter so it's actually OnCollisionEnter(Collision other)
I already told you twice. Collider and Rigidbody have those methods
https://docs.unity3d.com/ScriptReference/Collider.OnCollisionEnter.html
https://docs.unity3d.com/ScriptReference/Rigidbody.OnCollisionEnter.html
okay so heres what im trying to do
make the int a string
but i dont know where to put it
how do you get the int
let's talk about the int first
from the Awake that says "scoreManager = ScoreManager,instance
❌
*. instance
that's not an int, that's a ScoreManager
There is no need to have a variable. Just use ScoreManager.instance
okay
That's what's weird because I tried to do exactly that and didn't work
the ScoreManager has the int though
im working in the displayScore script
Will check again
do i go to the scoreManager script?
yep that's fine, don't go to scoremanager
ok
What did you do, what were you expecting to happen, and what happened?
You already have the reference to the scoremanager
Do exactly what?
I am not saying to do Collider.OnCollisionEnter.
I am saying the methods reside there
You write OnCollisionEnter only
It is sent to the two MonoBehaviours involved in the collision. One that has a collider and rigidbody, ine that has a collider
is there anything in the void Update?
ok do you know what a Class is
Instead of you calling your code, mb says I'm going to call some callback functions at certain times and if you decide to implement them, they'll be called during the specific times listed https://docs.unity3d.com/Manual/ExecutionOrder.html
yes
not a Unity object mind you
I put a box collider into my game object
So if I reference that game object with something like
'''Boxcollider2d mycollider'''
its 3 backtics, those are single quotes
I could do something like mycollider.oncollidionenter()
no
that's not how that works
those are Messages that are sent from the Rigidbody, you cannot directly call them
Aren't messages functions?
in this case the ScoreManager class contains a few things to use.
public class ScoreManager {
public static ScoreManager instance;
public int score;
}
the way you access something in an object is to use the .
in this case if you have a scoreManager, you can do scoreManager.score.
scoreManager is the same as ScoreManager.instance
As I said so many times, no
they are like events , the function you are using uses the value(collision/collider) of the said Event (message)
Reread this
#💻┃code-beginner message
so now you can use ScoreManager.instance to get the score
Please stop being passive aggressive, there are like 4 people writing me
Ok thanks
You are listening to none of us, and I am not heing passive aggressive. Please don't be rude because of your misunderstanding of the tone I am using
They are functions called by Unity. If you have a function with that signature, Unity calls it. That's the thing I linked you to. A list of message functions and when they run
so I put this in displayScore?
Yep
It's not just On Collision Enter. It's all of these functions (check the messages section) https://docs.unity3d.com/ScriptReference/MonoBehaviour.html
including the common functions you're unknowingly using: Awake, Start, Update etc.
There are some prerequisites for having them fired though, read the docs for the specific method.
okay so in the Awake I have scoreManager.score = and thren I deleted the scoreManager.instance
what do I put now
Why are you trying to change the score in awake
on a different note if you happen to have a couple instantiated thousand GOs with an empty definition how much of a performance drop is there? since Vs warns about that
We're not supposed to give out code unfortunately.
should I put it in start?
❌ you don't delete scoreManager.instance
Are you trying to change the score?
This is the first I'm seeing about you wanting to change the score
no i just want the score to update with the value from another scene which is the actual game
Yeah so they are functions that unity has as base then right? And yeah I suppose OncollisionEnter doesn't trigger if there is no collider
🤷♂️ Use the profiler and it would be relative to a specific targeted platform/device(hardware specs)
So then why are you trying to set the score to something?
I ask again since you ignored me before: What do you think = in code means?
The thing I just didn't get is why the collision managing was on unity instead of in the collider components
something means something
like something means something elsse
And yeah In the docs it says collider.oncollisionenter
wdym collision managing ?
the rigidbodies are what send the event
But doesn't seem to refer to a boxcollider or a rigidbody
It happens via the physics engine. Either Box2D or PhysX
If you were to write the line of code:
x = 7
in English, what would that sentence look like?
yo so i wanted to add some recoil to my gun so it rotates up when it shoots but umm i dont know how to do that
x is equal to 7
The physics engine refers to them, and sends the message to a registered monobehaviour
Because where else would you make use of it but a custom script?
Rigidbody hits a collider, thats phyiscs.. Both colliders in the collision get broadcasted to both of their respective Monobhaviors if they have one
In order to have collisions, a game object must have a collision component, like rigid body or boxcollider right?
Every line of code is a command or a question. There's no such thing as a statement of fact
One object must have both. The other must have at least a collider
no to have collisions you need a Collider
if you want physics you add Rigidbody
So why isn't it build on those components, instead of having those functions outside of those components
Phrase your answer in the form of an imperative statement or a question
Because that would be confusing and worthless?
Why would anyone want that?
Physx or Box2d just informs the monobehaviour that there was a collision
Don't dodge the question
#💻┃code-beginner message
Translate this, in the form of a command or a question
im not trying to man
Shouldn't the collider component manage the collider logic?
make x equal to 7
int i =5;
I.ToString();```
How would you write code in a collider?
Because then that would make it impossible to write scripts that do something custom on a script you made
🥣
Like, if I put a sprite component I would hope it to have sprite related functions
Correct. x = 7 means "Set X to 7"
they were already spoon fed the answer, you aint helping
i really dont know what im doing wrong lol or how i can achieve what i want to do
Where would you write those sprite related functions?
So, going back to this, when you put scoreManager.score = you are saying "Set scoreManager's score to"
Which is not what you wanted to do, correct?
ok so gun.transform.rotation is not something you can change, you can add a Vector3 to it though
So then why were you trying to write that?
Dunno, the same way you can write custom code in a. Custom script and make a custom component
I'm not a dev
make a Vector3 where the X and y is 0, then change Z
So a MonoBehaviour
A MonoBehaviour is a component. It is custom code. It is where you write code affecting gameobjects
. in code is the same as 's in English
hmm so i make a new vector right?
Yep and add it to the current vector
ScoreManager.instance.score is "ScoreManager's instance's score"
i set it to ScoreManager.instance
Now, what you want to get it the score's ToString(). How might you do that
So that's what ai was asking before, if all of these "commonly use functions" are made their ein monoBehavior because the devs knew they were used a lot
Instead of having them in a component
I just dont know where to put ToSttring()
Independently
In a component simply doesn't make sense. That is what I am saying.
They belong to a component, but they are sent TO a MonoBehaviour, where you can actually do something with it
You write code in MonoBehaviours, so that is where you would want it
the Text wants string, your score is a number.. take a wild guess
My messages got a bit scattered because of other conversations, so I'll put them together in one go so you can read it:
.in code is the same as'sin English
It's a possessive
ScoreManager.instancemeans "ScoreManager's instance"
ScoreManager.instance.scoreis "ScoreManager's instance's score"
Now, what you want to get it the score'sToString(). How might you do that?
Rotation property returns a quaternion. You probably shouldn't be modifying a quaternion. To add your specific Euler angle as a quaternion to the rotation quaternion you'd use the asterisk operatorcs rotation *= Quaternion.Euler(...);
Check the code example from the docs for more details https://docs.unity3d.com/ScriptReference/Quaternion-operator_multiply.html
its on the same line right
fill in the blanks
int score = ScoreManager.instance.______
displayText.text = score.________
we will not provide any help after this
have a good night's sleep and do c# tomorrow 😴
It doesn't matter if it's on the same line or different ones as long as the syntax is correct
Yeah but monobehavioour manages a ton of functions of different backgrounds right? It manages collisions, but also start, update and others
And I suppose that most of the base unity components were also created by the engine devs
There are many magic methods sent to them, yes.