#๐ปโcode-beginner
1 messages ยท Page 474 of 1
it should already be doing that based on your code
it just wont ever hit anything less than 0
it is...but now the walk animation is not playing reverse when walk back
and I'm afraid to tell AI this and it burns out
because back to my question about , what absolute is doing
absolute value, count from 0 how many spaces your negative value is
-1 , 1 space.. 0 + 1 = 1
you could never play backwards animation
or basically how far it went, if it went from 0 to -3 that means it moved 3 spaces
this is what Mathf is doing?
Mathf is a utility struct
Mathf.Abs not Mathf, but yes
for built in math functions that return/work w float
damn
what is the difference of Vector2.MoveTowards and Vector4.MoveTowards, they both have the same description
one works with vector2 and one works with vector4
vector4 is just 4 floats, like vector2 is 2 floats
color is usually a vector4 etc.
i didn't know that unity supported 4D
poor ps1 mia goth...will never rotates in the same place
lots of graphics stuff needs 4 values
All rotations are Quaternions, which are a subset of Vector4s. So all of your rotations are 4D
oh
huh ?
sorry it was a joke
@azure sail can yoi help me to Code unity haha
ohh most be some new . Idk Im older, i thought it was Leeloo
๐ it's the main character of my game...it is a ginger girl with mia goth face
ahh you youngins today.. missing out the classics..
I'm pretty old too, but mia goth is a nice new revelation actress for horror fans
Ps do you blocken me :(
i dont speak german
idk lol
He blocken me :((((
well yea
how
subtract the two positions assign it as pointing direction
are you doing 2d or 3d
if its 3d you could just use look at
[SerializeField] private Transform target;
private void Update()
{
var targetPos = new Vector3(target.position.x, transform.position.y, target.position.z);
transform.LookAt(targetPos);
}``` should only rotate on Y
i have a Transform, not a Vector3
or actually, lemme try something
i got it working i think
the console is spitting 2 warnings but it works
and i reduced a line
nvm i reduced another line
now it's only one line
now it's still one line, but the console isn't spitting warnings
thanks for the idea tho
idk what these cryptic messages mean lol
Incase you are wondering, instead of making a variable for it, you can just plug it in
i mean you can but one liners tend to look like shit after a while
actually even what i wrote looks like shite
I would do
var targetPos = target.position;
targetPos.y = transform.position.y;```
Also, the Transform targetPos is useless in this scenario
it's not going to perform any better by condensing those two lines down to one. it will only make what you are doing slightly less apparent
Normally, yes, but in this case I don't think so
you're the one that has to read it in the future, so do whatever you want. but don't complain when your choice to make the code less readable does exactly that
I think it has the same level of readability in this case, also I put comments anyways
@rich adder are you going to make more videos about resident evil games? like, how to add running anim, aim anim, etc
I been wanting too, I've just been so busy with summer at job. I will be able to have more free time soon to upload such things, its a series i want to finish for sure
nice, please do it!
was actually working on if i should add IK for holding /pickup weapon not to long ago
that's nice...I wish I could learn it all...
you will, just wont happen overnight lol
lol I'm going step by step, never giving up
well, my idea is to make something very simple and retro, maybe this is too advanced for my game
not retro, more like classic
like parasite eve 2 my favorite game in ps1
never heard of this one...
maybe I will play on emulator
its very good
modern games don't give me joy, only the classic one lol
yeah they have a certain charm
component to learn is Cinemachine Clear shot, you place a bunch of cameras it switches the view for you (mostly gets it right)
when I switched to community version in visual studio my code wont show complition errors again and when I tried to fix that with the Ide tutorial I saw that the visual studio editor package dont show up for me
go to the unity registry to install it (dropdown in the upper left that current shows In Project)
looks like a very nice tool...I'm using triggers to switch cameras, gives a lot of work
been there done that.. this component is goated
tnx found it didn't fix the problem tho but 1 more question why half the things they show in the tutorial looks diffrent for me, for example the External tools tab looks diffrent and I dont see the Add button in the installs tab in the unity hub
i don't know what tutorial you are looking at, but presumably it's a matter of different versions
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
isn't it up to date?
well your external tools menu is going to look different until you actually select visual studio there
what add button?
probably the one that has been renamed to "Install Editor"
you said Vscode
that guide is using information from an older version of the unity hub. don't think so hard about it
they didn't actually. they said "in visual studio my code wont"
oops I need my eyes checked
umm but I sitll dont know what to do though, last time I just had to install the work with unity from the workplace but now its installed and a lot of the stuff in the tutorial looks diffrent in the current version so im confused
you do know that the instructions you are asking about are for installing the unity editor (which you already have installed and open), right?
skip that section since you have the editor installed and move on
yes, follow the instructions. but obviously don't bother with reinstalling the unity editor
same stuff later tho, I litterly dont have the Coomon7/IDE directory
or I cant find it
was visual studio not listed as an option?
it does but they said to select browse
please read the words on the page
yes, specifically for if a version "isn't listed"
well then this is it tho cuz I completed every other step that is relevant for me
regenerate project files and restart visual studio
did you not select visual studio with the version listed?
you do have the visual studio editor installed and up to date?
show it in the package manager as well as what your external tools menu looks like
restart the editor
u mean restart the visual studio?
unity
ok
ok now its normal
like the external tools tab I mean
ok it fixed it
now the code is back to normals
tnx mates
this is kind of a general question and apologies if it's too vague for a meaningful answer but what kind of changes should you expect to break saves? a lot of early access games will occasionally have updates which require saves to be wiped. Is it generally just any large refactoring of existing systems?
tbh if you are expecting your save /load system to change you should design/implement it in such a way so that it does not break at all
I'm actually using the Easy Save asset. Maybe I won't need to worry about it too much.
I cannot speak directly of that asset but I doubt it will do all the work for you
sometimes its just not worth catering for, especially if these saves are small things like a roguelite game. it could even be a very small change but something thats just easier to say "old saves wont work on this version" to encapsulate ALL potential bugs.
simple example, you have a deterministic algorithm for where stuff will spawn in a world. you save the seed for that so the player can re-enter the game and have the stuff in the same locations always. Now suddenly you want to update the game, you want to generate new objects in the world that didnt exist previously. A person using the old save suddenly doesnt generate the same world anymore.
certainly not. I can think of some instances, like if I refactored items from some generic item class to a bunch of different classes that inherit from the item class, that would likely break saves and may not be worth the headache of refactoring. Just curious if there may be some obvious examples I'm not seeing. Maybe it's a silly question. Any time the data that is saved is no longer relevant to the scripts using it, the saves either needs converted to a new version or they're unusuable.
tbh I would add a version number to the save file so you can easily see how it should be handled, of course how well this works will depend on the save system and the data format of the save file
Oh yeah, definitely got a lot of world gen algorithms going on. So that's why my Caves of Qud saves always deprecated. Maybe the best way to go about it is, if releasing in an unfinished state where these kinds of things may change, just be transparent with the players that the game isn't finished lol
having some method of referencing a version number for a save seems essential the more I read. Thanks!
How to edit the rotation values seen in the inspector
Have you tried the rotation and euler angles properties of the transform?
yea euler angles was what I wanted
hello everyone, i have created egg_catcher game and exported as APK but eggs are not spawning in apk
Please show us your code
Have you run using the Android LogCat package to see if any errors are being thrown?
no
I suggest you do so as that is the tool for debugging Android builds
whare can i put the code
!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 can also recommend SR Debugger, its not free but it helps with inbuilt cheats + error log
After installing its showing this error
Thats not an error, thats a warning and that shouldnt break your game
it basically just tells you "hey you got a field here thats only written to, its never read somewhere"
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
Where do you call GameStart()?
//StartCoroutine("SpawnEggs");
Somewhat odd, no?
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
Hmm first hunch would be the eggs are either spawning behind your background or outside the screen
So a list of things to check:
- Image of the egg breaks on build (invisible), add something else you can see to the egg like text
- Egg behind background, not sure how you do your background
- Egg outside of screen left/right
@dry spruce does it work normally in the inspector though?
then it seems like a texture issue to me maybe
because the egg is there, u just dont see it
It's on the center of the screen
Are you building to mono or il2cpp?
Il2cpp
can you show us the inspector of the egg texture?
The fact that you're using strings inside StartCoroutine might have to do with the issue (code stripping).
Use the method directly: StartCoroutine(SpawnEggs()) or reference the method name using nameof: StartCoroutine(nameof(SpawnEggs))
Thing is the egg is the only element that can trigger the game over
so it seems to be spawned, just not visible
Better fix the code anyway. It's not fully resistant to renames
It's a simple check, add a debug.log to the spawn coroutine. But the chances are using strings in StartCoroutine will definitely cause problems when the code is stripped
hmm nothing weird in there, yeah then last guess would be that its somehow off-screen
use simulator
Next to Display 1, click "game"
then choose simulator
maybe that could help troubleshoot
Add a Debug.Log to the SpawnEgg method which outputs the spawnPosition.
Do a Build and Run and see what comes out in the Android LogCat window
Also is LimitX set to the same value as maxPos?
how to make a force that will make the character always standing
in ragdolls
angular drive or somethig
The basic way is through configurable joints and set the target rotation. that target rotation could be gotten through another object who is using animations in the way you would want to move.
Though this really isnt an easy task, and you'll need to fine tune A LOT. Do you really need a character that is a ragdoll and moving around? Or do you just need a character which can ragdoll
lets say that i want a GameManager to exist across all scenes with DDOL.
can i make it so that if i start a scene that doesn't have GameManager it creates a new one?
Im trying to make an active ragdoll character
Im editing angular limits now
but somehow
it looks like he broke every bone
Usually it's the inverse, the GameManager is in all the scenes, and when the scene is loaded, the GameManager in it detects that one already exists, and destroys itself
ahh ok2, ty
if (FindAnyObjectByType(typeof(GameManager)) != null)
{
Destroy(gameObject);
}
DontDestroyOnLoad(gameObject);
will this work?
That works yep.
Though prefer using the generic version of that method, it's prettier: FindAnyObjectOfType<GameManager>()
ive been struggling to find an inventory system tutorial and i just want some opinions
would it be a bad idea to do everything else except the inventory system, and then come back to it at a later date?
for the time being i could just have it so the player can only hold one item at a time
I believe when you use the ragdoll wizard to create one, it makes limits for you. Then just create the configurable joints manually and copy those values over.
And yea this is still all gonna be fine tuning for a long time, it's a pain in the ass to setup. Just wait until you get to the joint forces
my primary struggle is that ive noticed that a lot of the times, the youtube tutorials are sometimes unclear, or dont show the entire script, and just give you bits and pieces
or sometimes they'll change something, but not mention it, so you just gotta do your own stuff for a bit to try to figure it out
but im just starting out with this system so i dont fully understand how exactly its doing what its doing, but i feel like everything else can get up and running beyond the inventory system
its not required, but its convenient, as allowing the player to hold more than just one object allows them to actually move efficiently without having to do a lot of back and forth
If none of your game depends on it, then sure do it later. But you should really just plan out what you want the inventory to do then try coding it yourself. It's unlikely, no matter what you're trying to create, that you'll find something which suits your exact needs. At the end of the day an inventory is basically just a collection of items
yes I got every joint to configurable
I made their x,y,z to locked and rotations to limited
which Im folliwing a tutorial
i guess my biggest problem is trying to learn how to get it to store data
i really could just work around this for the time being but i dont want to code everything, and then decide to go back for an inventory system, and oop everything is too complicated to integrate it properly
That is cool
Well that wouldnt exactly follow the "if none of your game depends on it" if you made other systems which depend on it first.
Though not sure what you mean about storing data. Like a List<Item> itself is basically an entire inventory. You just have to define what an item is.
Sounds about right, just dont lock the hips, or whatever limb you treat as the center of gravity.
When testing actually you can lock it, so it stays in the air. It helped me try to fine tune some values so it could follow an animation.
i want so that:
every time the player enter a scene, it will spawn to a spesific destined spawnpoint
i did it by:
private SpawnHandler spawnHandler;
///Start function
spawnHandler = FindObjectOfType<SpawnHandler>();
Transform playerSpawn = transform;
playerSpawn = spawnHandler.spawnTransform;
changing the player's coordinate to a spesific coordinate that has been set by the GameManager. it did not work. anything wrong here?
why is collision detector not working? (I have tried both enter and stay)
Does either of your objects have a rigidbody? Do you have an eventsystem in your scene?
no ridgidbodys thx
not sure what you are trying to do there but playerSpawn is a local varaible and so has no effect outside of the method
transform.position = spawnHandler.spawnTransform.position
ok thats what went wrong
i refered the player's transform as Transform playerSpawn, in which just creates a new Transform variable rather than the player itself i assume?
tysm <3
you just wrote the players transform and then the spawner transform into the same variable, overriding it in the process, you never applied anything to the player
how would i go about having an object know its being hit by a raycast
not the raycast know its hitting an object
the raycast hit will output the object you hit, then you get the script off that object and call a function on it
thank you
i can already tell this system is going to start leaving me confused
trying to follow this tutorial for an inventory system but i have to readjust the entire thing for A) 3D, and B) actually fitting how i want the collection system to work
You can even abstract it with a "IRaycastHittable" then you can do something like this:
public interface IRaycastHittable {
void OnRaycastHit();
}
public class ObjectToHit : MonoBehaviour, IRaycastHittable {
public void OnRaycastHit() {
Debug.Log("Hit by raycast");
}
}
public class RaycastSender : MonoBehaviour {
public void SendRaycast() {
// raycast stuff here -> raycastedObject
raycastedObject.GetComponent<IRaycastHittable>().OnRaycastHit()
}
}
Just make sure only one script on each object has IRaycastHittable otherwise you only get the first
lol, Null Ref Exception just waiting to happen
explain ๐
if it hits an object without the interface
the check should be in a TryGetComponent
i have to have 4 scripts interacting for this one system i can already tell its going to be a pain 
too much back and forth perhaps
perhaps ill do better if i write down a flowchart to visualize whats going to happen
If you are just beginning its fine but if you feel like you have too much back and forth an abstract data layer like ECS or models might be your prefered way
systems are generally made of several different interacting scripts, yes. It's not a big deal
However, appropriate use of composition can often simplify things.
Personally I'd use the observer pattern for this situation, especially if the raycast is executed frequently
yeah dont complicate things for yourself by prematurely diving into those things, finish it your style until it works and if you want go back afterwards to see if you can clean it up and implement a pattern
how do i get the distance between two Objects?
2d / 3d?
Vector3.Distance(...)
subtract their positions then you have a magnitude property
thx
Hey guys! my upgrade hub screen is not recongnising the 'PointerDown' or 'PointerClick' event trigger. The 'PointerEnter/Exit' events are firing however which makes it strange. All 'Raycast Targets' have been checked and theres nothing blocking it.
{
Debug.Log("Test");
//Logic
});
}```
Is there maybe a button on any of your elements that eats the pointer down event?
if he didnt his hover would not work either
wait it was..
i didnt know they conflicted
it works
thank you
๐ thats just experience, had that happen plenty
the button already catches the on click and doesnt propagate it as it is seen as handled at that point
AHHH so frustrating my mind was going crazy
makes sense, thanks so much
Hi, can someone tell me why my prefab isnt being destroyed, and this DontDestroyOnLoad thing appears when i run the game?
1: Please post your code so we can check
2: You can set objects to not destroy on load, this prevents them from being destroyed when you load a new scene, usefull for managers and stuff
That's a lot to ask on the basis of a single screenshot
Because you call DontDestroyOnLoad() somewhere. Not much to say unless you share your 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.
Sorry give me a second
newChoice.GetComponentInChildren<TextMeshProUGUI>().text = currentDialogueSentence.choices[i].choice;
newChoice.GetComponent<Button>().onClick.AddListener(() => SwitchBranch(currentDialogueSentence.choices[i].branchToSwitch));
For some reason, out of these two lines of code, the second one give an IndexOutOfRangeError. I'm not sure how that's possible, can anyone help me?
For context, the second line is directly under the other in a for loop.
public void DisplayChoices()
{
if(currentDialogueSentence.choices.Length == 2)
{
buttons.GetComponent<GridLayoutGroup>().spacing = new Vector2(0, 40);
}
else
{
buttons.GetComponent<GridLayoutGroup>().spacing = new Vector2(0, 10);
}
dialogueText.text = "";
for(int i = 0; i < currentDialogueSentence.choices.Length; i++)
{
GameObject newChoice = Instantiate(button, new Vector2 (0, 0), Quaternion.identity);
newChoice.transform.SetParent(buttons.transform, false);
newChoice.GetComponentInChildren<TextMeshProUGUI>().text = currentDialogueSentence.choices[i].choice;
newChoice.GetComponent<Button>().onClick.AddListener(() => SwitchBranch(currentDialogueSentence.choices[i].branchToSwitch));
}
}
Here's the whole function if needed
public void RangedBasic()
{
RaycastHit hitInfo;
/* GameObject Test = Instantiate(LinePrefab, new Vector3 (0,0,0), Quaternion.identity);
Test.GetComponent<LineRenderer>().SetPosition(0, this.transform.position);
Test.GetComponent<LineRenderer>().SetPosition(1, this.transform.position + this.transform.forward * 20);*/
Physics.Linecast(transform.position, transform.position + transform.forward * 20, out hitInfo);
StartCoroutine(BulletSpawn(hitInfo));
}
private IEnumerator BulletSpawn(RaycastHit hitInfo)
{
if (hitInfo.collider != null)
{
LineRenderer bulletLine = Instantiate(BulletPrefab, new Vector3(0, 0, 0), Quaternion.identity).GetComponent<LineRenderer>();
bulletLine.SetPosition(0, this.transform.position);
bulletLine.SetPosition(1, hitInfo.transform.position);
yield return new WaitForSeconds(1f);
Destroy(bulletLine);
}
else
{
LineRenderer bulletLine = Instantiate(BulletPrefab, new Vector3(0, 0, 0), Quaternion.identity).GetComponent<LineRenderer>();
bulletLine.SetPosition(0, this.transform.position);
bulletLine.SetPosition(1, this.transform.position + this.transform.forward * 20);
yield return new WaitForSeconds(1f);
Destroy(bulletLine);
}
}
Here the code for spawning and destorying the prefab, should i also provide the inspector for the prefab?
then theres no Button on it ๐ค
put the array access in a single line, like var currentChoice = currentDialogueSentence.choices[i]; and just use the properties below, I suspect its not the array access causing the error, I suspect the same as spawn camp ๐
the error happens when I press the button so there must be
then its not that line.. and more likely something in the SwitchBranch(currentDialogueSentence.choices[i].branchToSwitch
try debugging every value u use before u use it
try narrow down whats missing
yeah i set currentDialogueSentence.choices[i].branchToSwitch to just a random number and then it worked
aye!
and the error points to that line as well
it's lambda completion
SwitchBranch(currentDialogueSentence.choices[i].branchToSwitch));
i will contain currentDialogueSentence.choices.Length when the code is executed
lambda completion
I'm not sure what that is
me neither.. i figured id say it out loud just in case it rang a bell
haha
basically i is passed by reference not by value, so the last value it has is what the method gets
oh yeah write the value of currentDialogueSentence.choices[i].branchToSwitch into a new var before that lambda and use that variable
yeah what spawn camp said ๐
Would this DontDestroyOnLoad thing appear without me calling it? I dont remember adding this nor do i know how this works
doesn't matter you are still passing the same i to each button
locked in today
ok lemme try that ty
lambda completion .. it makes so much more sense now 
int branchToSwitch = currentDialogueSentence.choices[i].branchToSwitch;
newChoice.GetComponent<Button>().onClick.AddListener(() => SwitchBranch(branchToSwitch));
Just to make sure I understood what you said, should I do it like this?
yep that looks correct
or just currentIndex = currentDialogueSentence.choices[i];
Ok, thanks
Yeah it did work, thanks!
is there any reason why I have to do that for the second line and not the first?
lmao
Have we learned something today?
the => part
i did ๐ช
oh, ok ty for the help and lesson
this is why I hate lambdas
lambda's are cool for basic stuff
Oh nevermind i was destroying a lineRenderer and not the actual gameobject
i use em for returns religiously
Search for the keyword, it should exist
What is inside the scene anyway?
The DDOL scene
syntax sugar can oft lead you astray
sometimes unity will create its own DDOL for certain things
Debugger or some crap
i cant remember
Is this directed at me?
URP makes a DDOL scene
^ thats it
Sounds like you're confusing it with expression bodies, which use the same syntax =>. Lambdas are different.
i could be.. u right
Yes
myFloat => MethodThatReturnsFloat();
See what's in it
expression body i guess @brave compass
yup the debugger thing i told ya #๐ปโcode-beginner message
thats normal.. ignore it
Odd that it just spawned in aft im encountering the destroy issue, but it wasnt the cause lol
Yeah, shortcut for:
float myFloat
{
get => MethodThatReturnsFloat();
}
which is a shortcut for:
float myFloat
{
get
{
return MethodThatReturnsFloat();
}
}
All pure syntax sugar, compile to the same thing.
it was probably always there.. u just didnt notice it until u startd looking @signal mantle
maybe lol
Thanks for the help
๐
i doo love me some syntax sugar.. im now at that stage where im learning more and more..
extension methods the other day
yesterday i learned about the index[0..index] range thing
and today learning about lambdas, and expression boddies
๐ช
gotta calm my jets w/ the syntax sugar tho
you get a good workout via syntax it seems
we see that ๐
Lambdas are also pure syntax sugar for a feature that existed before them called anonymous delegates. You used to have to write this:
Func<int, int, int> sum = delegate (int a, int b) { return a + b; };
But with lambdas, you can get the same compiled output with this:
Func<int, int, int> sum = (a, b) => a + b;
ahhh the Func part scares me
for some it still is ๐
lmao same I still don't even really understand the lambda stuff
is it c# that compiles all that down to the necessities or is it unity?
dont flatter yourself to much now ๐
Same thing with the more familiar Action.
Action sum = delegate { Debug.Log("hello"); };
Action sum = () => Debug.Log("hello");
Both valid C#, both result in the exact same compiled output, the first is just older, more verbose syntax.
bruh my brains making my neck hurt.. j/k you know that you always find me in #๐ปโcode-beginner sometimes i venture to #archived-code-general never to #archived-code-advanced tho.. that place is too big brained for me
This is all part of C#. Microsoft saw developers were making use of anonymous delegates and wanted to make them easier and less verbose to use.
Other languages might just remove the old syntax, but Microsoft is very serious about backwards compatibility.
I post in code beginner or code general depending entirely on how I'm feeling
i see.. isn't Microsoft the ones that updated the new VSCode plugin?
seems to me they stepping up to pick up the slack or something to that nature
cant fault em for that
Yeah, I think the old one everyone used was abandoned by its maintainers.
cant say im a fan of microsoft.. but i will give them credit where due
and then you look to windows 11, what a mess
windows 11 has been an epic trade from win10
even if its b/c i get 5x fewer updates
If i ever get too confident with unity i look into #archived-code-advanced to know that i am relatively speaking still a toddler in unity knowledge
just to humble urself eh?
๐คฃ
tbh there should be a lower channel..
lmao
#unconfigured-ide-code-beginner
#posts-code-as-screenshot-beginner
sad, but true
yup.. see sidia knows
extra points if its a phone picture
we all do lmao, i can look past it once or twice though
but.. my school dont allow discord ๐ข
there are fantastic OCR apps
i'll look past a unconfigured ide before i look past a mobile picture
nah just post code in paste site imo
mobile picture gets hard ignored
or that ๐
then u have guys that absolutely struggle w/ configuring they're ide..
everyones been at the unconfigured ide state before
so fair
then to me thats a red-flag right off the bat..
kinda like.. u sure u wanna do game-dev?
in german we have an abbreviation for such users, DAU (dรผmmster anzunehmender nutzer) = dumbest user you can assume
my favourite is error 40, when the error sits 40cm from the screen ๐
ohh thats a good one lol
dรผmmster anzunehmender nutzer
even not being a German speaker i can tell this is an insult
tbf hearing any german word sounds like a curse word for most people
lol. fair
when they scream at you its terrifying
well i dont know any other language that can curse your whole family tree with a single word, no whitespaces needed!
!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.
Configure your idea? ๐
hi, my unity is giving me trouble at login
@ login?
that isnt code related
#๐ปโunity-talk take it here @wet path
arabic
I don't speak arabic though but that's what they do
Dutch will do it, of course German is just an offshoot of that (lol)
Those are the words you speak to randomly find a german chasing you with a club
yo does any1 knows for how long the !code saves?
๐ 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.
Wdym? Saves where?
from gdl.space
Duration
Pastes are perminent right now, But i would not expect that to last. 30 days will probably be the expiry time for most users.
Some users of gdl may get more.
can't spell either
If your question is because you want to store code, then don't rely on external sources and make your own
Paste sites are usually for temporary sharing
you could use github if needed
bro i cant get my script working
i added a gun controller which is the best one i have ever used and now my camera keeps snapping back to centre when i move it left and right
i cant find any solutions in words i understand this is my first game idk what im doing
i would recommend !learning unity
:teacher: Unity Learn โ
Over 750 hours of free live and on-demand learning content for all levels of experience!
and you should also show your !code so we can help
๐ 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.
๐ 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.
use one of the paste sites. not everyone can the code โ from mobile โ and it doesn't contain lines numbers . . .
and heres my second code and i think theres 2 diff ways of camera but idk im not that smart
https://gdl.space/eribilerak.cs
hey guys can someone help me make a script which when we hold an item and we colide into an object while holding the item it makes the item disseapear and triggers a sound because i cant find any tutorials on youtube
break down the problem into separate tasks:
- collide into an object
- check if holding item
- make item disappear
- trigger sound . . .
- pickup / hold item
- oncollision/ontrigger enter
- disable/destroy object
- play sound
and how do we do that ๐ญ
you can look up the individual task and then put them together . . .
research it on unity hub and forums
did you manage to figure out what the problem is?
like how to hold an item.. how to make an item disseapear on collision? and trigger a sound when the item is gone?
basically, that is how you create systems. spฮwn cฮmp gฮmes gave you the unity/programming version while mine is the english (readable) version . . .
are there tutorials for that on youtube?
no, i didn't know you had a problem or question. i just saw you post with code that people would ignore because it was sent inline . . .
yea, idk what im doing i just joined to try and get help
i would direct the paste link toward instead of pinging me because others will think it's just for me (though i don't know anything about your question) . . .
ok thx
what class is it in
not too sure
alr
you can literally google each step to find helpful links . . .
are there tutorials?
on youtube or something
yes, there are tons for doing the stuff you need. you're trying to find one video that does everything which is very specific to your case/game. you need to search for tutorials that do one thing, then you combine those tasks to work together . . .
is this good?
no normally it older posts dont matter (most still work)
but that one is soo old it using Monoscript / javascript
2010 damn
ya, but like i said normally that dont matter.
u see where it says function thats not the syntax for that anymore
lua uses function
its private void OnTriggerEnter()
Unity doesn't use Lua either
Ik
What Spawn means is, you can't use function in Unity anymore. It's still the syntax for JS..
That will destroy a specific game object after a collision, which may or may not work for the system that you are wanting to build.
Watch Untitled and millions of other Roblox videos on Medal, the largest Game Clip Platform.
how do i make it so it cuts the tree where ever the mouse is
instead of a fixed point
because i could do a fixed position where it cuts even if the mouse isnt on it
Presumably by cutting at whatever position your Raycast hits
Without seeing code, can't get more specific than that
but how would i split the model at that point
How are you splitting the model now?
Runtime mesh modification presumably
It's not really beginner stuff
There are assets that will do it too
You could use one of those
Watch Untitled and millions of other Roblox videos on Medal, the largest Game Clip Platform.
it makes the cuts wherever you are
but i'd only know how to make one preset cut at a location that starts even if the mouse is at the opposite side of the tree
Yeah didn't really need another clip, it was clear.
maybe this wil help you
I decided to learn how to slice meshes in unity. Going through Unities documentation I learnt that you can cut meshes by iterating the triangles in the mesh object and create new ones based on the intersections of a plane.
Subscribe: https://www....
in this case actually the tree seems to be made of simple rectangular prisms though
so you could do this with:
- a little texture magic for the black cut line
- spawning two new smaller pieces in place of the large trunk, just scaled properly
That's perhaps a simpler alternative to modifying the mesh.
I didnt actually lock their rigidbody or transform but their configurable joint's xyz and rotation
he needs to lay off hte donuts
thats a bird
where there ya go, your solution is remove the hands, birds don't have hands!
I never said it had hands
honestly I have no idea, but you might get better luck in #๐โanimation
{
XCretionsCanShop = true;
}
else if (Hit.collider.transform.name != "XCretions")
{
XCretionsCanShop = false;
Debug.Log("Not Hitting XCretion");
}``` would anyonre know why this isnt working
wait i should prolly provide more code
{
if (Hit.collider.transform.name == "XCretions")
{
XCretionsCanShop = true;
}
else if (Hit.collider.transform.name != "XCretions")
{
XCretionsCanShop = false;
Debug.Log("Not Hitting XCretion");
}
}```
im using a raycast right, and the if statement works but no the else if
first you don't need to check if something is not in the else
Then your raycast is never hitting something whose name is not "XCretions"
i dont know how to else turn it off
yeah and if it isnt hitting anything with that name shouldnt it turn off that bool
if(condition) { do something } else { do something else }
i also tried using just an Else Statement but that doenst work either
No, you set the bool to false when it does hit something that doesn't have that name
Which is not the same as when it doesn't hit an object with that name
should i just remove the else?
remove the if part of the else
If you want this to fire when your raycast hits nothing then you need the else on the raycast, not on the name check
so like a if hit = null?
Physics.Raycast returns a boolean. True if it hits anything. False otherwise.
yeah then why isnt just an else stamement working?
if it hits smth with that name its true
and if its not true then it does the 2nd option
Which condition did you put the else on
the raycast or the name check
the name check
Okay, so you want that code to run when the raycast does hit something, but that thing doesn't have that name "XCretions"
when the raycast hits smth named "XCretions" i want a bool to be turned on, if it isnt then i want it off
That isn't the question I asked
Do you want the code to run when the raycast does hit something with a name that isn't "XCretions"
if there isnt any other way then yeah
If you want the code to run when the ray does not hit something
then you would want to put the else on that condition
not the name check
sure
ok
i think that way would be better yes
you need to know what you want before you code
for a racing game, is there a way i can get navmeshes to pathfind where there's no mesh? for example, if there's a ramp, i want the pathfinding to recognize that it's allowed to move off of the ramp to move forward
not even just navmeshes, how would you do that with a*?
oh that's off mesh links
duh
i forgot they existed ๐ญ
i want an raycast that looks for a gameobject that is infront of it, and if that gameobject has the name "XCretions" then i would want the bool "XCretionsCanShop" to be true and if that smth infront is either empty or isnt named "XCretions" then i would want it to be off
raycast with transform.forward as the direction, write an if statement
So, you have a check for if the ray hits something or not. If it doesn't hit anything, set it to false.
If it does hit something, check if that thing's got the name you want. If it isn't, set it to false.
If it is, set it to true.
so why not set it off before the raycast and only set it on if the raycast is true and the correct gameobject has been hit?
i already have the raycast in place i just need the detection
then write an if statement
yes
That wasn't a question, that was the answer
i already did i have the if statement to check if the gameobject is named "XCretions"
cause idk how to do that
oh
bool thing = raycasthit.transform && raycasthit.transform.name == "name here"
what? You are already almost doing that
I mean, that was how to do that. Set it off before the raycast and only set it on if the raycast is true and the correct gameobject has been hit
why not just declare it equal to the boolean expression that would be in the if statement?
like this
Because there's two conditions
If the raycast has nothing, there's no object to check the name of
just check raycasthit.transform. if it hit nothing, it'll be null
๐คทโโ๏ธ
Ah, you're right. RaycastHit is a struct, so it's non-nullable. It won't throw an error if you check the transform of it, nevermind. Yeah, that'd work
There are many ways to do this, actually.
yeah
ffs
bool = false;
if (raycast)
if (gameobject.name)
bool = true
not good enough, spoonfeed harder.
They seem to be utterly incapable of translating words into procedural logic. We've already given them the exact answer three different ways but they just can't connect the dots
yeah thats kinda how im doing it
then what is the issue ๐ญ
the bool is true but once its true it never gets set to false
if you have the code, what do you need help with? is it not working?
And unfornately "Kinda" doesn't mean "Same"
send ur code
the relevant section
public void RaycastManager()
{
if (Physics.Raycast(RayCastGameObject.transform.position, transform.forward, out RaycastHit Hit, 5, Interactable))
{
if (Hit.collider.transform.name == "XCretions")
{
XCretionsCanShop = true;
}```
XCretionsCanShop = false;
if (Physics.Raycast(RayCastGameObject.transform.position, transform.forward, out RaycastHit Hit, 5, Interactable))
{
if (Hit.collider.transform.name == "XCretions")
{
XCretionsCanShop = true;
}
}
Is this what u want?
thats literally my code
This isn't the same
No, it isn't
i edited like steve showed
my guy you initialize it to false in declarative space
You set it to false once. When the object is created
if you put it in declarative space, it won't get set back to false
yeah i need to to be false at the start
when the method is called again
have it be false at start, and whenever the method is called
Okay, so once you find it one time it should be true forever?
right now it won't get reset because declarations in declarative space happen before anything else
and they only happen once
Do you need the bool to be class level or should you put it into a function? Read into the concept of scope.
wait is it called declarative space? one of my professors used that term like 2 years ago but i've never heard it since
the area where you declare fields and methods
in C# we call it scope
You mean we did it
gj!
how amny coders does it take to make an if statement lol
1 but if ur speaking to a guy who drinks paint for fun then alot more
what's the time complexity of asking for help with an if statement in a discord server
O(n!) because it becomes
"hi can someone help me"
"ok so my problem is that i'm trying to get a struct buut like a reference type"
"why doesn't my code work? doesn't post code"
wait quick question how can i make the stuff only run once?
Only call it once
for exmaple the ray thing is in a loop, so it just loops forever if i place a Audio.Play(); thing it it, it will play the sound infinitly until i stop looking at the gameobject how can i make it do it once
Only call it once
how do i call it only once tho?
the thing will run every frame
Then you probably don't want to do something that's only supposed to happen once in there
post your code using this: https://hatebin.com/
If you don't want to run this every frame, when do you want it to run
only once and then i want it to stop
Forever?
you didn't post anything with a while loop, are you referring to running it in the Update() function?
no, look for example when i look at that gameobject i want
an audio to be played and an animation once
and when i look away i want it to play another audio but im having issues
the audio code was running in an update function yeah
only play the audio when your conditions are met.
So, when you look at an object, play a sound.
And then what? Is it now off forever, to never play again?
no like a hi, and bye then no more sound
you need to focus your efforts on learning basic code flow a bit me thinks
Listen, if you want to program, you're going to need to actually know what you want to happen
You need to be able to put into words on what conditions things occur. You can't just give general "vibes" to code. You have to define things.
call a function that plays the sound once when you look at it, and once when you look away.
So, question:
Is it now off forever, to never play again?
Answer this question specifically. Not the question you think I'm asking. This one.
no, it isnt off forever
Okay, next question:
At what point can it happen again?
you're going to get such better results if you just post your code https://hatebin.com/
At this point code doesn't matter they don't even know what they want yet
lol true
The Greetings should only happend when the bool is true the canXCretionShop
so check for that bool and only play The Greetings when it is true
Okay so, any frame when canXCretionShop is true, you want to start the sound
yeah start the sound to start and when the sound is finished i want the sound to not play until the bool is true again
This is the first time you have mentioned "when the sound is finished"
This is a condition you've never mentioned until now
oh
When I say when do you want to be able to play it again, you need to be specific
this is a condition you'd want to be true before the sound can play again
this is, in fact, the exact condition I was trying to get you to realize you needed to specify by asking leading questions
You have to tell the code that. It doesn't just know what you want
So, now that you actually know what you want to happen, you can check for it.
https://docs.unity3d.com/ScriptReference/AudioSource-isPlaying.html
So, start the sound when the condition is met and a certain boolean is not set. Then, set the boolean. When the sound ends, un-set the boolean
and no, I will not translate this into code for you. This is the exact solution and learning how to translate thoughts into code is something you are going to need to learn on your own
i dont want you to translate it to me tho, then im not rlly learning i did the mistake of always copping code once and i dont rlly wana do that again
try to write it out as pseudo code and use the unity documentation to slowly transform it into something that works. Maybe use Debug.Log(""); as a placeholder for systems you dont understand.
focus on the basic programming logic for now
wait a sec i think i got smth going ion
looks like its working
i just need to tweak it a lil and it might work
i did it guys
how do u get the colors btw?
!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.
oh
public bool XCretionsPlayed = false;
public bool XCretionGreet = true;
public void AudioPlay()
{
if (Movement.Instance.XCretionsCanShop == true)
{
XCretionGreet = true;
}
else if (Movement.Instance.XCretionsCanShop == false)
{
XCretionGreet = false;
}
if (Movement.Instance.XCretionsCanShop == true && XCretionsPlayed == false)
{
XCretionsWave.SetTrigger("Waving");
XCretionsVoice.clip = XCretionsHi;
XCretionsVoice.Play();
XCretionsPlayed = true;
}
if (Movement.Instance.XCretionsCanShop == false && XCretionsPlayed == true)
{
XCretionsVoice.clip = XCretionsBye;
XCretionsVoice.Play();
XCretionsPlayed = false;
}
}
heres the codeรข
whats the isssue now?
its working
which is unexpected
there has to be a hidden error
why
why does there have to be a hidden error
i dont trust myself
you dont need to trust yourself, you just need to understand the code.
i do
i wrote it
i mean it works il just leave it at that
thanks for the help guys
you still don't understand how an if statement works, first thing I told you was you don't need to check the opposite of a condition in hte else part
it depends.. it cant hurt.. assume I can't do deductive reasoning
if (x < 10) {
// x is less than 10
} else {
// well, x apparently is greater than 10
}```
well hold on a minute...
if (x < 10) {
// x is less than 10
} else if (x > 10) {
// x is greater than 10
} else {
// x is exactly 10
}``` there we go
but yea.. i know what u mean..
he's doing if (condition == true) {} else if (condition == false) {} which will work sure, but is redundant and shows he doesn't understand how it works
ya, that is a bit too much lol
if (bool == false) {
} else {
// bool == true
}``` and viceversa
if(!bool) return;
// bool is true
// do everything you need to do
// for a true bool down here``` ofc my favorite
hey guys i need to make new string using script only after i press a button how do i do that?
you need to make a method such as public void MakeNewString()
it has to be public
then in that function you should put what you want to do, which is make a new string
then in the unity inspector
you should attach this script to an object
such as the button
and then on the button you should see a 'Button' component
on that there is a menu where you can attach an object and access a function from one of its scripts
attach the function you just made and it should work
thank you gonna try it now
how should i make the string? i wasn't coding for a while so i forgot some things
Noob Questions. Iยดm trying to make a pingpong game and i cant get the ball bounce to work as i want it to. i have tried to make a picture(i paint like a 3year old) how can i go about making it so it workse like the green arrows?
You're gonna have to explain more the relationship between your start angle and result, because I don't see anything consistent between the green arrows
They seem to be completely arbitrary
not sure, i mean the pingpong game i played when i was little didnt have exact angles like reflect does. not sure exactly how it worked. but i know when you hit the ball in the center of the paddle went straight up from the center. You could kinda stear it depending on where it hit on the paddle
Well, in order to implement it, you're going to need to understand it.
thats why im asking here if someone remembers ๐
This isn't really a "Remembers" thing, you are going to need to decide what you want to happen
string myString = "Hello world"
also check pins for the courses on basics
but it is a remember my arrows explains it i would say
yeah thanks just wasn't sure
i need to use the string how should i do that?
alright alright alright guys i have a issue where when i click play my player model spawns in the air like a sigma
In what context would you want to use it
This might not be a code issue and more an animation issue
type in inputfield and make the string what i typed in the inputfield
You can get the string of an input field with .value
Your collider is too big and intersecting with the ground, so its pushing the whole object up
Make your collider smaller so that it lines up with the bottom of your character
yeah i know but i need to make new strings because i want to make infinite strings and every string will be different
have different value
I'm not really sure what you mean by infinite strings
Do you need to store the string somewhere?
that i can't make just one string with the button
but infinite amount of strings
you could put them in a list
as a field
instead of them just being a local variable
i want to kiss you
Cant blame you
smooth
Any wizard with unity able to assist me with a box collider issue?
:thinking: Asking Questions
:mag: Search the internet for your question!
:book: Use the API Scripting Reference and User Manual and this troubleshooting site for commonly posted issues.
:wrench: Attempt to debug your issue.
:thought_balloon: Find an appropriate channel by reading the name and description in #๐โfind-a-channel
:grey_question: And don't ask to ask, ask a full question illustrating with screenshots if needed.
-# For more posting guidelines, go to #854851968446365696
If I want my game to restart (remove previous entities and instantiate new ones, generate new terrain) how can I "remove" everything that was previously on the map (trees, entities, bushes which are not part of the tileset. I thought of Destroying every object but that is surely not efficient
Store all the things that should be cleared in a list as you create/spawn them.
Use that list for cleanup.
should I Destroy all of the objects of the List?
If they're GameObjects, sure.
Oh, okay then, thanks as always!!
Can you simply restart the scene? Objects that were instantiated wouldn't be there if the scene is fresh. Another idea besides making a list would be to give them all a tag and then destroy gameobjects with that tag when you are ready. A third idea, instantiate them all under the same parent when you spawn them and then simply destroy the parent. Not talking about deep nesting, just 1 layer... parent and children.
guys,
how do I make my ragdoll character balanced in the t-pose, its in the t pose but how do I add forces to him that the forces will make the character balanced
I think I made a basic topic more contrevortial by writing so much but I need help
using slerp drive dont work
sorry guys I didnt do the rotation drive mode to slerp
but now
it still falls forward
and looking like this
Look up active ragdolls. Basically, you need to record the rest pose(your T pose) state and apply forces/torque to each bone/joint such that the ragdoll always tries to go back to the rest pose.
I dont think you specifically need it on slerp. I think I mentioned this earlier to you, the target rotations should be set based on whatever pose you want it to be in, likely gotten from a separate object using animations.
Then it's really all fine tuning to get it to move how you want
!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.
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
Hi. I have everything i want to work. only thing is. When i select another item without placing it. It will briefly show the "not enough resource" message. I'm aware it's simple. just need an if statement or something but just cant figure it out
Where do I go to in order to talk about a multiaim constraint problem
I'm guessing here
So basically Iks are not working on my characters with their avatar set to humanoid but for some reason works on characters with the avatar set to generic
if it deals with any coding or a script you made you can ask here. any general problem would be #๐ปโunity-talk
ok
cs List<string> player_is_dead = [ "No", "No", "No" ];
i was trying to add this line, but i got this error, anyone knows a fix without updating?
I don't think that's a valid way to initialize a list.
how do i add a list with the elements already added
Create a new list and you can use {} to inline elements addition.
thx
incorrect list initialization . . .
hello, quick questions
is there a big difference between UnityAction and C# Action?
And what is better to use?
there is no "better", it entirely depends on your needs. a UnityAction can be assigned to in the inspector, a regular System.Action cannot
so, like, they are basically the same, with UnityAction just being serializable and C# not?
there are some other minor differences, but they are used for very similar purposes
Difference is that you can set UnityAction from inspector, and C# Action is language feature (delegate)
alright, i'll settle with c# for now.
big thanks to all 
Unity Action has integration with the Unity inspector. C# Action has an unlimited number of type arguments whereas I recall Unity action only has a certain amount - don't recall exactly how much, but there would be enough.
System.Action can actually only have up to 16 arguments rather than an unlimited number. I think UnityAction is something like 4
Delegate has much generic purpose, and is not necessarily event handler, could be used just anywhere you want to pass lambda or method
Ah yeah, 16 for C# (plenty enough)
C# provides 17 overloads of Action delegate in the System Namespace, one of them is: public delegate void Action<in T>(T obj); This Action delegate would only accept one argument of type T . However, it can support up to 16 arguments of type T .
I thought it was UnityEvent inspector not UnityAction
hi i have just changed my dash code to limit my gravity while dashing but now while i am grounded i cannot dash can anyone help me: https://gdl.space/uzonurijoh.cs
Honestly if you even need more than four you're doing something wrong
Hello everyone, I'm starting with Unity and 3D video games in general. In my project I would like to make a modular construction system. I'd like to know if you have any resources to give me (Docs/Discussion/Tuto) about it?
Have you even attempted to research the subject?
Yes, but that's a long way from what I want to achieve with modular construction
TIn fact, this is an example, but I'd like players to be able to set up their own sound system or concert stage, but to do it in their own way. Without too many limits.
Above all, I'd like the speakers to snap together, but without the grid system, so that players can orientate the object in their own way.
Here's where I'm at, and yes I've done research before, but this is particular... At least I think it is, I'm just starting out.
I have an object that stores level data, and a static function that changes scenes. I'd like to run a function inside that stored level data object which is in the scene transitioned to, passing the previous one's data.
I don't know how to explain this. Basically, in every scene there is an object of LevelData class, and it has a ReadLevelData(LevelData previousLevelData) function, which does stuff with the previous one. The SetLevel(...) function changes scenes, and I'd like to pass LevelData from the object from the scene transitioned from into the ReadLevelData function of the LevelData object in the scene transitioned to, and immediatelly run the function.
If this needs any further explaination or any code, let me know.
So for example, during a level the LevelData stores how long it takes you to beat the level. When you finish it and switch scenes, the next scene reads that data, and updates your best time on that level (level select scenes are also levels (or hubs))
So to do that we need previous LevelData
Or is there a much better way to do that?
Maybe I'll put this script directly on the players as they go through the different scenes?
Like the name, parent hub, id
Add a property of type TimeSpan that stores how much time had passed during a specific level
Then store that class in a static List that spans across your assembly
When a new level loads, it checks that list for the LevelData of the previous level
And displays the according information on the screen.
I don't think I understand. You mean store all leveldatas in a list?
I think for all this I'd need a json file or something, to store progress
like is a secret found already, if yes, specific objects will appear around levels or stuff like that
Do yall know a reliable tutorial on things like that?
public static class AssemblyStaticCache
{
public static List<LevelData> Levels { get; set; } = new List<LevelData>();
public static LevelData GetLevelData(int levelNumber)
{
return Levels.FirstOrDefault(level => level.Number == levelNumber);
}
}
Either store that in memory cache
or the storage of your choice
how would i link my interaction keys with my games localization so it says "Press [interaction key] to use"
The best way to self-implement a localization technique is through a string, string key-value pair Dictionary
Seriously?
lmao
Ok
It's a separate package you need to import
yes, shift+enter is a thing
Yes, because there are plenty of people that send basic messages that contribute nothing
If it's to prevent spam, it doesn't really do much
You'd be surprised how much it helps a conversation
Most people don't know how context works in questions (when they come here as a beginner)
It's to make what you post more readable, so we don't have to wait 5 minutes for you to finish a thought
void Load()
{
if (Application.dataPath + "/levelSave.text" == null)
{
return;
}
string saveString = File.ReadAllText(Application.dataPath + "/levelSave.text");
LevelJsonTemplate saveObject = JsonUtility.FromJson<LevelJsonTemplate>(saveString);
unlockProgress = saveObject.unlockProgress;
}
i want to check if a json save file even exists before loading (i want it to be empty when you play the game for the very first time), how do i do that?
if(File.Exists(fileName))...
thanks! sorry if it seems like a basic question i am very new to system.io stuff
But that's not what you should be doing for your case. If the JSON file doesn't exist, that's not strictly a problem.
you could have just looked at the rest of the File class docs
it gives me an error because i call Load() every time the main menu scene is called
Google is your friend. If you format your question correctly it often gives you a straight answer.
It's a skill by itself, make sure you use it and learn how to search properly
In this case, see the second result.
i checked and didnt found lol
Make sure you specify it's for c#, and don't include unnecessary info
ok i tried and it worked thank you
For example, don't google "Check if json exists on system". Instead, google "check if file exists"
Considering the main issue is finding a file, and not the json specifically
so I'm trying to get the DOTS system working in my project, but the tutorial I'm following just does this and it works while mine doesn't?
do I seriously have to make a forum post for a beginner question?
Show the tutorial, and what is Baker?
If it ends up being DOTS specific then yes it goes to the dots channel/forum
Unity DOTS (data-oriented technology stack) is a stack of tools that will help you to improve the performance of your games even 10 times! It is composed of multiple tools such as ECS, Burst, C# job system, and more. In this beginner's DOTS guide you will learn the basics of ECS on a simple example of spawning many cubes and moving them in rando...
I wish I knew
it just says "yea just do this" fast forwads by 30x and doesn't properly explain anything, so I'm not sure what to do
please, it's simple C# compilation error, not even related to dots in any way ๐
its missing for me
the tutorial I watched said you need 2020+ and Entities version 0.50
and the other one said 2022+ and Entities version 1.1
guys do any one know a platform to learn c# for unity
!learn
:teacher: Unity Learn โ
Over 750 hours of free live and on-demand learning content for all levels of experience!
yes learn
oh thanks
overall I'd suggest the Unity Learn website and the dotnet documentation/guides, but personally I used codecademy back then
i'd say your best bet is to learn the basics of C# first and then slowly create small projects using unity learn or other methods
Hence the "if"
can u tell me more abt code acdemy
I'd suggest you look it up, its a website which basically tells you what to do and you do it
and it explains how it works
oh thanks broooooo
i think it asks you like 30 times to pay but theres a free version
Hey guys!
I wrote a function which works when button clicked (I added listener from script)
But when I click any of the buttons, it destroys only Button2
As you can see, I tried to check by names etc.
Buttons are stored in a list currently
what are you trying to do
that would be the first question
becauase you haven't explained that
you almost certainly do not need those individual if checks inside the loop
Also please share code via !code not screenshots
๐ 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.
Oh sorry, I'm trying to make a 2d target system but with buttons. When I click to the enemy (or its button), it will get destroyed.
so which object / script is this code running on? If there's just a single script here, this isn't going to be possible in this way
you would need to call the function with a parameter of some kind to indicate which button you want to destroy
right now there's no way to tell
typically for this kind of thing you would instead iterate over the buttons in Start and set up a listener in code that calls it with the right parameter
for example:
[SerializeField]
Button[] buttons;
void Start() {
for (int i = 0; i < buttons.Count; i++) {
GameObject obj = buttons[i].gameObject;
buttons[i].onClick.AddListener(() => Destroy(obj));
}
}```
butt = GameObject.Find("EnemyParent").GetComponentsInChildren<Button>();
foreach (var item in butt)
{
if(item.name == "Button0"){
GameObject.Find("Button0").GetComponentInChildren<Button>().onClick.AddListener(() => {CrossClick(GameObject.Find("Button0").GetComponent<Button>());});
}
else if(item.name == "Button1"){
GameObject.Find("Button1").GetComponentInChildren<Button>().onClick.AddListener(() => {CrossClick(GameObject.Find("Button1").GetComponent<Button>());});
}
}
finally i did it
๐
If I'm reading your intentions correctly this
Button[] butt = GameObject.Find("EnemyParent").GetComponentsInChildren<Button>();
for (int i=0;i<butt.Length;i++)
{
Button item = butt[i]
item.onClick.AddListener(() => {CrossClick(item);});
}
Does exactly the same thing
you do not need to keep repeating the same code. You have the reference already
although why you are passing the same object as a parameter into the script you are calling is on I'm not sure
the if statements are not needed and the GameObject.Find stuff is wasteful and unecessary as well
I am having trouble with Canvas component sortOrder property.
My button cannot be clicked even if I set sortOrder to 520, which is higher than any other canvas component.
Button can be clicked properly if I remove Canvas component from it, but I can't position it on top of another element that has sortOrder at 500.
I need sortOrder for my UI, so I can position things behind/on top of my UI without worrying about hierarchy order.
After doinng some tests, it seems like Buttons are just not clickable with Canvas on them
Sounds like a #๐ฒโui-ux #๐งฐโui-toolkit question
ok so I have to add GraphicRaycaster to each button in order for them to use Canvas component properly
that should've been applied to them automatically . . .
Each canvas needs that to be interactable, yes.
Using a whole canvas for each individual item is not a typical use case
Yeah It wasnt added automatically, this isn't a whole canvas afaik, it's Canvas component but if applied to an object manually(?) it becomes something else
Maybe it detects a parent canvas, not sure.
But this is recommended, for sorting UI on Z axis which is what I need.
So this canvas is inside a canvas basically for the sake of override sorting
Hey guys can someone help me with how to make a pickable item cuz tutos on youtube dont work with the specific item i have (which isnt a block)
The code shouldn't care what the item is
Then you're going to have to actually say what the problem is
also dont crosspost
hello guys,
I made a walk cycle with code in a normal character
but I try to make an active ragdoll so I wanna make a ragdoll to walk too but the ragdoll becomes a ballerina when played
(also the foot should follow the spheres, [there is no sphere colliders so ragdoll wont touch it])
I can send code if you want
Hello,
When I start my game, I have this error : ArgumentException: Value does not fall within the expected range.
I use a script in attached to a GameManager to use all inputs functions.
My error is in these lines :
private void OnEnable()
{
inputSystems.Player.Jump.performed += PlayerMovementV2.instance.OnJump;
inputSystems.Player.Jump.Enable();
}
The function OnJump :
public void OnJump(InputAction.CallbackContext context)
{
if (isGrounded)
{
rb.AddForce(Vector2.up * jumpForce, ForceMode2D.Impulse);
}
}
can you show the full stacktrace?
What is stacktrace ๐ฅฒ
areyou sure PlayerMovementV2.instance is assigned by the time you hit OnEnable?
InputManager.OnEnable () (at Assets/Code/Scripts/Inputs/InputManager.cs:15)
so instance is null
How can I verify it ?
can you show where you assign it
I assign the function OnJump when the InputManager is enable
Where I assign it ?
Like that ?? (sorry I'm not fluent in english :/) :
public static PlayerMovementV2 instance;
private void Awake()
{
if(instance != null)
{
Debug.Log("+ d'une instance de PlayerMovementV2");
return;
}
instance = this;
}
alright. Can you place a log in here (put it after instance = this, doesnt matter what you write),
and put one inside of the other script OnEnable() Debug.Log(PlayerMovementV2.instance)
It says Null ๐
can you show both logs in console
I have Player (PlayerMovementV2) after the line instance = this
But I don't have the one in OnEnable()
did you put the two logs in the two script i said?
yes
But I thinking, do I need to create a variable PlayerMovementV2 and assign the instance in the awake and after use this variable for the input ?
please dont crop them i want to see both messages printed
lol overcomplicating such a simple request myguy
The fourth is an another issue
Sorry, I try my best men ๐ญ
ok, is the first log the one in PlayerMovement
Maybe create an InputManager is not a good idea ๐โโ๏ธ
no
Because before this, it worked
no
It's in the OnEnable()
i wanted to see if awake was running after this scripts OnEnable..
whatever it seems like it is
script order issue
The solution is script Execution Order but I hesitate to suggest it
i want to receive data in unity through serial connection to raspberry pi pico ...i am able to open port but data is not being received
there is not much we can go off on here..
But how ? I assign the instance in an awake and use it in an OnEnable
OnEnable is after Awake no ?
ok.
yeah but they are different scripts and its not guarantee which one will run first
Ohhh okay, I see
You could change the execution order ig, i try not to do that . Input setups should be ok, but if this object is part of the scene already instead of using a singleton maybe you can do a inspector reference assignment ? (this guarntees its not null on Enable)
singletons are handy but if those two objects are part of the same scene , ie not a prefab vs scene object then just make serialized reference
otherwisehttps://docs.unity3d.com/Manual/class-MonoManager.html (use with caution) . https://docs.unity3d.com/Manual/ExecutionOrder.html