#💻┃code-beginner
1 messages · Page 571 of 1
because someone pays for it, gets the invoice id, publishes it on social media and then everyone else can mod your game to use the same id
usually the easiest option is to use Firebase Functions or similar service to provide server-side validation
you don't need user login for that
public GameObject fullHeartPrefab;
public GameObject emptyHeartPrefab;
public Transform heartsParent;
private GameObject[] heartImages;
void Start()
{
UpdateMoneyUI();
SetupHearts();
}
private void SetupHearts()
{
heartImages = new GameObject[lives];
for (int i = 0; i < lives; i++)
{
Debug.Log("he ik wordt aangeroepen");
heartImages[i] = Instantiate(fullHeartPrefab, heartsParent);
heartImages[i].name = "Heart " + i;
}
}
what im i doing wrong?
Hi, If you want help then please explain the issue you're helping instead of "What is wrong?" because I have no idea what you're referring to
This code looks wrong. Do you have errors in the console at all?
noop
Also please screenshot your editor with the code in it if possible
I just want to verify your editor is configured
ok. I will look into it. thanks @runic lance @languid spire @burnt vapor for your time.
Ah, okay, nevermind. LGTM
What do you want exactly? Do you want the hearts to show up in the game or in the inspector?
Because the former needs actual UI components to appear, or sprites to draw
The latter is because your array is private, and it must be public
to show the hearts in game and be empty when the player looses a level
This is more a #📲┃ui-ux thing then. Your code already exists, you just have to attach heart prefabs on the gameobjects
i made a script the deletes an object when it gets touched by the pointerobject. however, if i time it correctly i can stop the objects from falling without deleting it. its like the code didnt reacted to the quick collision. how can i fix that?
void OnCollisionStay2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("EnemyObj"))
{
Destroy(collision.gameObject);
timeManager.time_left += 5;
scoreManager.score += 10;
}
}
I believe there's an interval how often collission checks are actually invoked. Maybe you need to reduce that
Can't say where that's done, though
I assume your solution is to reduce it at least
How are you moving things?
BTW you could also make this a trigger. Then it does invoke the method but it doesn't stop the object
You'd still have the issue where you could touch it but not trigger the method, though
nvm i fixed it by using OnCollisionEnter2D instead
use on collision enter
oh you got it alredy
the red cubes are falling due to gravity and the pointerobj by lerping (idk how its called) the position to the mouse position
yeah oncollisionstay executes every frame where oncollisionenter actually executes as soon as there is a collision
and physics happens before oncollision stay
Oh, I didn't even realise you used Stay rather than Enter
I assumed it was on a similar cycle
Hello, everyone. How do you do these special lines for code in discord?
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
📃 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.
well, to find this parameter (angle) i use this code:
ANGLE = Vector3.Angle(rotator1.GetComponent<rotator>().collisionpoint - rotator2.GetComponent<rotator>().collisionpoint, Vector3.right);
how to find this parameter?
i tried:
ANGLE = Vector3.Angle(rotator2.GetComponent<rotator>().collisionpoint - rotator1.GetComponent<rotator>().collisionpoint, Vector3.left);
but it returns me the same
rotator1 is this gold point in front of sonic, rotator2 is a white point behind sonic
anyone?
Did you check the manual what you should put into a to direction vector? https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Vector3.Angle.html
See example
do i have mistakes in last code?
What does it return, like what is wrong about the output you are getting
Resulting angle is the difference, and it seems you are feeding it the same difference just inverted.
resulting in the same difference angle rather
Maybe you need Vector2.SignedAngle or Vector3.SignedAngle
like, he returns me 45 here
and here he returns he 45 too, but he must return me -45
Note: The angle returned will always be between 0 and 180 degrees, because the method returns the smallest angle between the vectors. That is, it will never return a reflex angle
Always check manual
ow... okay... maybe, i should read manual and thinking about the question before asking... my apologies
Even if you used Vector2.SignedAngle, both of these images would result in the same angle - see the red arrow. It's the same, just rotated 180 degrees
It's more obvious when you flip the other side
You can use Vector2.SignedAngle and invert the resulting angle when you are facing left
guys how can you visualise physics2d.boxcast with physics debugger
Or use Vector3.SignedAngle and use a different axis parameter (forward/back) depending on if you face left or right @echo copper
should it work fine on default or should i change some settings
I think it only supports 3D physics
nice
You can use Gizmos.DrawWireCube/DrawCube to draw a box anywhere you want
You have to mess with Gizmos.matrix to make it rotated tho
chatgpt hallucinated that i had to change 3d to 2d debugger
aight thanks
It tells you the things you want to hear
Not necessarily things that exist
ye i can see it now
Lemme know if you have problems rotating the gizmo
IT WORKS! thanks
Can someone help? Loading files from Application.streamingAssetsPath doesnt work properly on android
https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Application-streamingAssetsPath.html
The doc has some info about android specifically
i make call trough WebRequest and it doesnt make the request (download handler is null)
it also uses link that starts with file:///
But when i manualy input "jar:file://" + Application.dataPath + "!/assets" it gives me 404 error
When using Application.streamingAssetsPath
okay...
Updated unity and realised that the input manager became a legacy feat
I'm still learning the new input system, just asking how is it compared to the old one?
Does it really provide more flexibility? Since I prefer to implement it through code
New one allows you to do both, tbh, using it via code is so much easier than the crappy UI-UX unity offers
yeah i agree, i never understood why so many people were fond of it
I don't think anyone is fond of it, they just dont have the skill to do it themselves
I just skimmed through some bits of the input system and my head hurts
It looks so convoluted
it's actually not if you ignore most of it and only look at InputActions
Hi guys!
Is there any way to have a UI above any GameObject visible in the scene? I want text on a Canvas to always be visible, even if an object is in front of it.
UI Layout:
- Canvas:
-
- Panel:
-
-
- TMP_Text
-
Thanks!
Hmm let me take a look at this, thanks
Do not use world canvas but screen space
And not really a coding question
I think the new input system is good. It lets you configure differnet controls for say gameplay and your UI. How actions work are nice too as you can easily setup say keyboard and controller inputs to go into the action (e.g. WASD or L stick for a Vector2).
It looks intimidating at first glance but I'm currently reading lots of good things about it
You can also get a certain device in code (e.g. get the keyboard and listen for key inputs this way)
100% supporting using the "new" input system entirely and do not look back into the old one. The only reason, a lot of people still use it is because of older tutorials.
Its also quite nice to learn about event callbacks and listening for them and so on. Win win 🙂
I recently updated my 2021 unity to the latest ver, and there's a lot of things that are already in legacy
I didn't know that TextMeshPro was also gone
Its not gone, but its part of unity now
oh whoops yep, misremembered
This is my Gamepad controller set up, used in the editor and at runtime. Code based on new Input system InputActions and ignores the rest of the Unity set up system
oo that looks neat, guess there's something new for me to do this week
What is the best way to show and hide ui elements? I am using canvas group and just change its visibility via code.
You can completely disable the graphic components or deactivate the entire game object.
This would be appropriate if you wanted them to stop taking up space in an automatic layout
all right. Thanks.
looks like you already have it working. there are always multiple approaches, so it depends on your needs. as Fen mentioned, you disable the visual component that displays the UI, deactivate the entire GameObject, or change the alpha of the canvas group . . .
Ah yeah playing with the canvas group's alpha works fine. I just wanted to know if there are better approaches. I found it myself messing with the UI's so yeah. Thanks.
My raycaster wont work properly on my animation object, but it does on my movement object.
The animation when im on the wall wont play when I climb a wall from on its right side
private bool OnWall()
{
RaycastHit2D raycastHit = Physics2D.BoxCast(boxCollider.bounds.center, boxCollider.bounds.size, 0, new Vector2(transform.localScale.x, 0), 0.1f, wallLayer);
return raycastHit.collider != null;
}
this is the code I used, I have tried to fix it by changing the size of it to be the same size as the object or larger than it, but it didnt work
Are you not using the same BoxCast for both?
I would think this is a problem with whatever code is supposed to set that "CLIMB" parameter, not the boxcast itself (which theoretically is the same for both)
im using the same
that is the code that sets the CLIMB parameter
anim.SetBool("CLIMB", OnWall());
You need to show it in context lol
can't do anything with this
show the full script ideally
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
using System.ComponentModel;
using UnityEngine;
using UnityEngine.UIElements;
public class Animate : MonoBehaviour
{
[SerializeField] private LayerMask groundLayer;
[SerializeField] private LayerMask wallLayer;
private Animator anim;
private BoxCollider2D boxCollider;
private float wallJumpCooldown;
private float horizontalInput;
private double integer;
private void Awake()
{
//Grabs references for rigidbody and animator from game object.
anim = GetComponent<Animator>();
boxCollider = GetComponent<BoxCollider2D>();
integer = 1.5;
}
private void Update()
{
float horizontalInput = Input.GetAxis("Horizontal");
//sets animation parameters
anim.SetBool("RUN", horizontalInput != 0);
anim.SetBool("GROUNDED", IsGrounded());
anim.SetBool("CLIMB", OnWall());
if (OnWall() && ((Input.GetKey(KeyCode.Space)) | ((Input.GetKey(KeyCode.LeftArrow)) && (horizontalInput < 1f)) | ((Input.GetKey(KeyCode.RightArrow)) && (horizontalInput > 1f))))
{
anim.SetTrigger("jump");
}
if (Input.GetKey(KeyCode.Space) && !OnWall())
{
anim.SetTrigger("jump");
}
if (OnWall())
{
Debug.Log($"on wall ong fr fr");
}
}
private void OnCollisionEnter2D(Collision2D collision)
{
}
private bool IsGrounded()
{
RaycastHit2D raycastHit = Physics2D.BoxCast(boxCollider.bounds.center, boxCollider.bounds.size, 0, Vector2.down, 0.1f, groundLayer);
return raycastHit.collider != null;
}
private bool OnWall()
{
RaycastHit2D raycastHit = Physics2D.BoxCast(boxCollider.bounds.center, boxCollider.bounds.size, 0, new Vector2(transform.localScale.x, 0), 0.1f, wallLayer);
return raycastHit.collider != null;
}
where's the wall climbing logic
thats just for the animation,
We need to see the wall climbing logic because basically you should be using the same logic
FYI, Rigidbody2D.linearVelocityY/X exists now if you want to just change one axis of your velocity
Seems like an honest mistake if you read up
where is the freezing xyz positions? Im pretty sure ive used this option before but I cant find it in the rigidbody or box collider, and online sources have it through code instead of inspector
Your inspector is in debug mode
Debug mode will show all the private fields among other things
its helpful for certain things like in a scrollbar when choosing how many steps you want
its capped at 11 outside debug mode
thats what i use it for mainly off my head
the debug mode skips all of the normal editor and property drawer code
it just kinda...shows every serialized field, in order
They're completely transparent
The scene view is drawing an outline around the particles
what does it look like if you turn off outlines?
They won't run outside of Play Mode when not selected
hm, so they appear in the game view, but not in the scene view?
yeah ive been told just now and its real
i can see in main camera
awesome unity features
I haven't observed that before. I wonder if it's a rendering-order problem
Yesterday, i was getting help from some people here, and i was told to change my method of closing the doors in my game. So far, there is no more "Shaking", BUT now the door is rotating like this, and i stopped getting help. Here is the code: https://hastebin.com/share/rigapegomi.csharp
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
As far as I can remember that code is nothing like that which you were advised to use
Praetorblue helped me alot with the code: Most of the code is for my scene, but the stuff i was told to change is here: ``` CurrentRotation = Mathf.MoveTowardsAngle(CurrentRotation, newYRotation, 1 * Time.deltaTime);
Door.transform.rotation = StartRotation * Quaternion.Euler(0, CurrentRotation, 0);```
This is the code after i fixed it how praetor told me.
I think StartRotation should be cached in awake/start instead of ontriggerenter
I'm pretty sure there was a lot more to it than that, I suggest you revist the conversation
The reason it isn't is because the player is meant to hit a trigger, so it would be stored then.
I don't like how you're trying to remember a starting rotation at all, really
- The object you have selected doesn't seem to be the one rotating
- Your inspector is in debug mode which makes it hard to understand the data
Just operate in local space. The door should only care about changing its local rotation.
That makes it trivial.
I had the same thoughts
You're piling on a bunch of complexity by trying to use a world-space rotation
Dead-simple.
Set up the door so that it is closed when its local rotation is [0,0,0]
(or, heck, any other y-axis rotation -- just plug that value into closedAngle)
and then put angle = closedAngle into the Start method in that case
I'm not sure whats happening for me:
How are you doing the "open door" part
you never showed that
and that's working fine
It does seem odd that the door's opening has nothing to do with the door's closing, yes
That implies you have multiple components all trying to spin the door in various ways
which sounds nightmarish
indeeed
the door should have one component whose sole job is to rotate the door based on its current state.
Other components can tell the door to change it state.
But they shouldn't be trying to fuss with its rotation
pretty sure you pointed him in the right direction for doing this
I have a door dragging mechanic in my game, that does that, but I'm trying to create a mechanic that closes the door back.
Oh well that explains it.
You can ask the hinge joint to move to a certain angle using its Motor setting
If you need it to be physical then yeah that^
er
Or limits
Nvm yeah just use the motor
Could i add force to the door?
Fun fact: if you have Scene Reload disabled, then joints will remember things from prior play sessions
You'd want to add a torque!
But yes, you can do that
In that case, you'd write a function whose job is to apply torque until the door is in the right orientation
OKay, well that explains why i have this issue. That makes sense.
(it should also give up after a period of time)
eh, your problem is that you're rotating a thing that is also being controlled by a Rigidbody
Yeah, i completely forgot about that, that would have saved alot of time yesterday.
Always good to show the components when debugging
I just happened to see it flash in the beginning of the video
Thank you.
How can I prevent the player from getting stuck in the air while jumping and activating a dialogue?
dont turn off gravity for the player when dialogue gets activated
Are you setting timescale to 0?
I'm just freezing the character...
you can just disable input instead
then gravity will still work
You need to set your movement input to zero obviously
When conversation is start?
@feral moon Keep media Unity related, please.
Hello, are there any cool tips on how to make functions with loads of parameters more readable? (this is me with having definined a bunch of stuff in vars before hand to shorten it)
I wish I could make radius and center have default values, but since Vector2.zero is not compile time constant you can't
the parameters should describe what it's used for in the method . . .
you can easily do this with an overload that doesn't have those parameters but just calls the overload that does and passes your preferred defaults
oh parameters is a dictionary, its used to pass extra data to the bullet scripts (dw about it)
wait thats such genius, although kind of annoying to make a bunch of variations
but I'll do it, thanks
cant you do this? public void SpawnCircle(Vector3 radius = default(Vector3))
yeah, overloads with default (optional) values are pretty common . . .
oh apparently I can, had no idea that was a thing
yay thanks, its a bit more readable now
just remember that optional parameters must be at the end . . .
Doesn't localization package handle that automatically? Anyway if you're going custom I think there's a setting for that on TMP Text (I could be wrong)
(btw localization package is the best thing ever, like the only thing I import everytime)
if you're passing in this many arguments, it's best to use a struct or a class . . .
do you not have a programmer on your team, this is pretty trivial
would it really be better though? Just more overhead, and you'd be creating the wall of parameters in a struct and then immediately passing it anyway. It'd be more code overall to do the same thing
if this is modding or decompiling you are in the wrong server
ok buddy use pastebin atleast, i cant even look at all that in discord (without downloading file)
also what is Token? I've legit never seen it
anyway you should probably learn unity or get a friend to help, its kind of hard for anyone here to help with such a specific issue if you dont know what you're doing
it's just an idea. definitely more readable and you can set default values as needed. that was your original question, no? you can also re-use the data, if needed . . .
It's working! Thank you for your helping!
unity events are only used if you need to hook up events from the inspector. if not, use a regular event (action) instead . . .
Action<object[]> but yeah ok
ah wait, actually i kinda might want that too
this one is programmatic but you're saying i can configure them in the editor this way? like if i made a public or serialized field list for them on my GameData?
mainly want a way to allow entities to call out to other entities. in this case it's setting the background terrain scroll speed (nested in a TerrainManager) from an actor in a cinematic sequence
the UnityEvent will appear in the inspector, then you would drag a GameObject with a MonoBehaviour script attached to it that has the method you want to invoke. using the drop-down, you select the method from the script
if you're not going to do that then there isn't a reason to have/use a UnityEvent instead of an Action . . .
Yeah that sounds perfect actually. Thanks
Hello. This is my first time when I want to put some scripts to an downloaded asset (character, animal etc.). I have a small problem. I made an HP script where the character will take damage when hit (in this case, the tiger is hit by a projectile), but it's HP isn't dropping or dissappearing. Where should I put the HP script?
how do you determine if the tiger is hit by the projectile?
using a collider (I had a capsule with it and it does work)
make sure the collider is setup correctly to collide with the projectile. besides that, we don't know what method you use to damage the tiger or how the collision interactions works. you have to provide that information to us . . .
yeah, it was because of the collider
idk why, but I though when I download a character asset, it would come with a collider in it
have you bothered googling it?
the script could go anywhere, it depends on what the script is doing and how you want to organize it. Maybe its a bug in your code instead of where the script is placed, in that case do some debugging
or did u figure it out
i've got a question i know for a fact has been asked a million times & i bet is simple but i can't find anything simple online to fix
i am trying to throw projectiles in my game, specifically spears & i need the flight path of the spear to follow the head, image in case i'm not explaining myself very well. it's all physics based & there is no script on each object that gets launched
I did figure it out
There are only two persons who are offering socket.io package on GitHub but they are full of errors. The other one is nan but i didn't tried it.
a lot of the times, the best way to do something is by doing it how it works in real life
and in this case that means making the spearhead the heaviest part
which would make it do this naturally
seems like you've already found the available ones. i don't know what else you are expecting to hear
I'm really confused
private void DefaultListener(String string)
{
Debug.Log("Default listener triggered!");
}
// Update is called once per frame
void Update()
{
onCustomEvent?.Invoke("Rats");
}```
How can I do something like this
what about that is not doing what you want?
use a delegate that has parameters
does your listener have parameters?
you do that part yourself . . .
what
how about you show where you've declared the onCustomEvent so someone can point out what you've done wrong since you clearly don't understand the information that was provided to you
lol
this 'String string' wont work either
how does it know you have a parameter if you don't tell it, it has a parameter. it's the same way you create a list. you tell it what type of list it is . . .
They are full of errors box. I am not finding without errors. Did you worked on socket.io.
lol i think ur missing something
okay so now look at the documentation and you'll see that there are generic versions of UnityEvent that look like UnityEvent<T>, use that but use string for the generic type parameter
how about instead of bitching that c# isn't a shitty dynamic language, you maybe try and bother learning how it actually works?
Do be what I'm doing
no i haven't. but you've found the available resources. if they do not work then either fix them yourself or do everything manually
Using C# is learning it lol
i think if they did, they would've mentioned it by now (at the very beginning) . . .
it's exactly because of lazy programmers who wrote shitty code that type safe languages were invented
seems more like you're skipping the "learning how c# works" and going straight for "brute forcing your way through c# and expecting everything to work like lua"
did you though
I can take a college class I guess
or like, free online guides
I did
that'll enable god mode, if you can beat it . . .
Learn c first.
copy/pasting what you see in tutorials is not the same as actually learning and understanding
i tried this & it didn't work but let me try again a little bit harder
I'm looking at docs not tutorials
sure, YouTube University . . .
True!!
great! so instead of reading documentation you clearly don't understand, start by learning how the language works
Okay, having some difficulty just…thinking through a plan. I want to remove all children of an object in one frame, then in the next, have two objects added as children to that original object. This would be in a method whenever a button is pressed. What would y’all’s process be? Don’t want yall to code for me (I need to learn), but would you start with a method? Coroutine? How would yall think through it?
if you don't have enough background knowledge/experience to understand them, they're not gonna be as useful as they could be
why the 1-frame difference?
so you remember that information about coroutines i provided to you yesterday? read through it
yeah i would do the 1st thing then yield return null in a coroutine then do the next
So the Destroy() can fully work, as there would be an issue as all the objects have a max amount
does it have to be the next frame? why not remove all children, then add the two children afterwards?
Coroutine is the obvious choice if you want a frame pause
I do, so would I just do a coroutine?
be careful with unity’s destroy command, the objects destroy on the next frame, not the current btw
yes, a coroutine would be the easiest option here. or you can always go and refactor your code so that it isn't relying on the number of children an object has and instead is using some collection to track the number of objects
they destroy at the end of the current frame
its at the end of the frame . . .
Just go to W3 schools and study its lessons on any language, pretty much explains the concepts in itself.
yes
or nvm lol its probably end of frame as they said
Alright, thank yall. Going to look at the docs boxfriend sent me yesterday on coroutines, still getting used to them. Thank yall!
it would be complete insanity for C# to grab random methods by name and subscribe them to the event
i just know it was annoying to check if something existed when it wasnt actually destroyed yet
I was pretty lost in Unity until til I started college tbh lol
yeah that was their issue two days ago
It DEFINITELY is 😭
oh, you mean "give it the correct type", not "type it with your keyboard"
lol
transform.forwards = rb.velocity.normalized
Surprised yall remember this. It’s very sweet tbh
my response remains roughly the same. static typing keeps me sane.
LMAO
No way to really know shit about what’s going on unless you do some learning about the language and concepts of programming
I've worked on game written in javascript before, and it's hideous
It's so nebulous and ill-defined
I got the brain chip to type my listeners
Does it work? I don't know!
Runtime error!
💥
Being able to do static analysis beyond "I think this variable probably exists" is so, so helpful
i'm going through information about js now for some web dev stuff and this language is horrifying
Typescript is a huge improvement
Yeah I made a simple rogue like in html,css,JavaScript, it’s unnecessarily unorganized
The TS type system is really cool
I'm so sorry for you js was rough for me lol
typescript was nice tho
I think js can be nice if you include a database
I liked js.
one thing about js that is absolutely baffling, is that when calling a function with a string literal you apparently can just leave out the parentheses
you can't
Yeah i dont know about that lol
do you mean a tagged template? that's a bit more involved than "pass a string without parens"
Js doesn’t specify type so technically you can pass any type to a function, doesn’t mean it will work though lol
There is one bit annoying about js is you have figure out runtime time errors.
i mean, this is valid: console.log`hello world`
Oh I see
but it's specfically for template literals, not string literals
and it does more work when you actually use templates
console.log isn't written to use them, it's just allowed and happens to work
split and join also work like this, handy tips for golfing
One thing I always wondered is what is the point of arrow functions in js
i remember using this in a CTF
you mean anonymous functions?
they're wildly useful
Yeah
@slender nymph
Can’t u just do the same thing by leaving the function parameters empty
are you comparing it to a named function?
it's syntactic sugar
the point of an anonymous function is that it has no name -- it's just an object
But what’s the point of it lol
You can just write its contents on its own to execute
a => b is syntactic sugar for function(a) { return b; } in js
you often want to run something later
technically no, non-arrow anonymous functions also exist in js
I fail to see its benefits
not when you need a callback
oh, by writing it like this? #💻┃code-beginner message
been a hot minute
void a() => b();
if you want to add 1 to each element of an array, you can't just map(+1), you have to do write a function for it, like one of these
function increment(x) {
return x + 1;
}
map(increment)
// or write a function directly
map(function(x) { return x + 1; })
map((x) => { return x + 1; })
map((x) => x + 1)
ah, i see
interesting
yes, but with arrow functions it's not very common anymore, unless you need a new this for some reason
That looks wild
this isn't even an anonymous method, this is just expression body syntax for a regular method
yes
they're all basically the same
c#, java use syntax (arrow) while python uses a keyword (lambda)
while js has both
how would you suggest to do this? i've tried adding in a secondary, heavier, rigidbody but this doesn't affect it. I've seen that you can edit the rigidbody centre of mass in code but i don't have scripts on these objects
I haven’t used the arrow in Java
have you done streams in java
I’ve done things like generic, making interfaces, abstract classes
I never learned about the arrow
Streams???
streams are where you utilize lambdas the most so if you never touched on streams then you probably wouldnt have had to use them
By streams are you talking about cryptography? Lol
no
bascially java's equivalent of linq
yeah, fp-style manipulation of collections
(in comparison, js has this built into Array, python has map/filter, and also comprehension)
I dont know what linq or fp is
have you ever used Array.map in js or comprehension in python
No
i dont do a lot of physics stuff like this honestly so i would have figured that a second rigidbody would work. Have you confirmed that separately, the 2nd rigidbody falls faster?
Does that have to do with dictionaries?
😭 bro i can't even give you equivalents in those languages
not really, more about data structures in general
linq: https://learn.microsoft.com/en-us/dotnet/csharp/linq/
and fp is just functional programming
i've found that you can manually edit the centre of mass so i'm playing with this now, i haven't confirmed that first though
map/Select, filter/Where/select, reduce/fold, flat, etc are operations on collections
That’s basically what the arrow is?
well no, but it's used frequently with those
What is the arrow doing syntactically
it creates a function
Like if you could write it in code
think its just { }
What would the arrow look like
Thx I’ll check that out haha
params -> body or params -> value
i use it a lot in something like a list of a script where i need to find the first thing in a list where x is true, i can do it in one line
generic type parameters
In Java that specifies generic
But this is specifying such a primitive data type for a generic
fyi: these are broadly called anonymous functions or lambdas/lambda functions/lambda expressions, for example python has the keyword lambda which does the same thing but it doesn't use an arrow
it's also a generic
It’s just weird haven’t seen that much lol
c# just doesn't restrict generics to reference types
You want weird?
I would always see a generic with a class name not a primitive
C++ templates let you do crazy stuff like Foo<3>
They're both types.
That is true
Nothing weird about a List<int>
java has a different generic system to c# but they're still generics, the core logic holds
Man there’s a lot more to c# than I thought, I thought it was basically the same as Java lol
But there’s namespaces that apparently act a lot different than packages
And some other stuff
java doesn't let you use primitives with generics and instead provides wrapper reference types
c# doesn't separate primitives in this way, users can define value types themselves (struct) so it wouldn't make sense to restrict value types, so c# doesn't have wrapper types
Right, that’s where I was confused
java doesn't have structs or this concept of value types
they are both syntactically similar, but there are some surprising differences, like in java you can't define your own value types. everything you create is a reference, the only value types in java are the primitives
I believe that's because each instasntiation of a generic type with value-type parameters winds up affecting how much memory the type requires
public class Holder<T> {
T item;
}
not to be confused with value-based types
java's type erasure kinda breaks that i guess
it's different in a way that's entirely unlike Holder<Foo> vs Holder<Bar>, where both of those are reference types
templates feel so cursed to compare with generics lmao
The C++ template section opens up with talking about how you can't use floats
array<int, 5> moment
like, it's the first thing it talks about
as if this were normal
and that we all wanted to do that
and anything else is fair game? 😰
That was the only section of the C++ standard that I could not understand by reading it
How do you define your own type in c#??
struct/class/interface/enum
Java just has references to objects yeah
every class, struct, enum, interface, etc is a type definition
damn too slow again lol
Lol
same as you would in java/js/python
Wait so it’s basically the same in Java
you, or someone else, has to make everything you want to reference
no language will automatically know what you mean by some given name unless it's defined
Is Unitys source code in c++ or c#?
why did you choose unity?
Someone told me it’s better for solo devs lol
damn, wasn't what i was expecting
And apparently offers more freedom
ok that's more like it
so a variety of reasons, yeah?
Because it’s abstracted to a higher level language
same thing for any other decision
Unity seems somewhat user friendly though
i mean, so are all the other engines, they gotta be to be usable
And I was told that Unreal offers a ton of prewritten templates which I didn’t like
I like doing everything from the lowest level, and from scratch
Because I’m still learning programming, and I need to learn that way
you can write your own stuff in Unreal if you want . . .
Probably lol
and you can use templated stuff in unity too (hence the entire asset store)
I opened unreal and had no idea how to access anything, like scripts or anything
Isn't an Engine by itself technically a prewritten thing?
When I opened Unity I saw the scripts at the bottom of the screen
Yeah, I’ll probably attempt making my own engine at some point 😂
Like, if you truly want to do things yourself use a C# base and write an engine yourself
doesn't unreal have the same basic interface as unity
I know in one of my classes they make you write a basic 2d engine in c++
Assuming you have the time and patience, it's a hell of a thing to do and a great learning opportunity
I dont know I spent 30 minutes on it, and figured I should go back to Unity because I didn’t know how to do anything
project - content browser
inspector - details
hierarchy - outliner
I just want to make a working 3d multiplayer fps in unity before I do anything else
that's why guides exist lol, noone's expecting you to spontaneously understand it
Hello, I'm currently baffled at C#, and would very much appreciate help.
This is the print:
Processing task at index 0```
Error cause by RemoveAT:
```ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index```
How? The list is private, nothing outside can access it, I do reverse indexing to ensure no problems when removing elements while iterating, yet it breaks. How is this possible?
This is the code:
I know haha, I just looked at it and figured I barely know Unity, and this looks more complicated so I went back to learning Unity
also before anyone mentions using fixedTime in Update, this is not a monobehaviour, be sure that this function gets called externally in FixedUpdate
What type is your collection? List?
Yes
Can't you just reverse the list, do a normal foreach, then remove all?
or use a queue to let the removal of items be managed
I mean yes, but thats technically slower and I can't think of any actual reason for this to not work
A queue is even better here, yes
Removes basically any trivial operations apart from just iterating
Hey, quick question. Currently attempting to call a coroutine in another script, but it won't "call" it. Still new to all this, so if this is idiotic I understand, but when you call a coroutine, does it have to be inside another coroutine? Here's the code calling the coroutine:
public void ResetCurrentHand()
{
PlayerDeckManager.GetComponent<DeckManager>().ResetPlayerHand();
DealerDeckManager.GetComponent<DealerDeckManager>().ResetDealerHand();
}
``` and the coroutine itself:
```cs
public IEnumerable ResetPlayerHand()
{
Debug.Log("Reseting Player Hand");
foreach (Transform child in transform)
{
Destroy(child.gameObject);
Debug.Log("Destroyed an object");
}
yield return null;
Debug.Log("Coroutine ended");
handManager.cardsInHand.Clear();
Debug.Log("Cleared cardsInHandPlayer");
StartCoroutine("DestroyPlayerHandObjects()");
hand.GetComponent<CardValuesScript>().handValue = 0;
Debug.Log("Number of children in handtransform before waiting: " + hand.transform.childCount);
DrawCard(handManager);
DrawCard(handManager);
}
``` Thanks
Sure I can make a queue instead, but like why does this cause an error? I can't think of any reasons
Alternatively if you need a LIFO collection, use Stack
you have to use StartCoroutine
try debugging the count and index right before you remove
but I do, look in the code
right before you remove
alr
That's the thing, whenever I try to, it won't call it. I've done StartCoroutine(ResetPlayerHand()), in which it will say it is not a string or inside the script currently opened, and when I do the string (StartCoroutine("ResetPlayerHand") or ("ResetPlayerHand()"), neither will work
I just realized what's going on, when my object is destroyed it clears the list (to ensure no schedules run after), but it happens before the update... Fixed and very stupid of me
you are changing the count of the list while it needs that information inside the for loop? not entirely sure but i dont think u should be removing in here
you still need to reference the function correctly, StartCoroutine(PlayerDeckManager.GetComponent<DeckManager>().ResetPlayerHand());
it normally wont matter due to the reverse indexing
don't use strings. and you call StartCoroutine and pass in DealerDeckManager.GetComponent<DealerDeckManager>().ResetDealerHand() or give the deck manager components a method that starts the coroutines internally
public void ResetPlayerHand() {
StartCoroutine(ResetPlayerHandRoutine());
}
private IEnumerator ResetPlayerHandRoutine(){
..etc
}```
ah i getchu
Doesn't matter considering this is in reversed order and the total length isn't used
That makes... a lot more sense. Thank you.
Real quick though, it still says I need a string when using StartCoroutine?
it needs to be IEnumerator, not IEnumerable
Yeah, that checks. 😅
It's just that a Coroutine using a string is probably the first signature defined to it errors mentioning that one
I did research on get and setters since I made it to the part I needed them and there kinda awesome so thanks theres way different than I thought so very cool
Oh I know, I thought we were talking about this #💻┃code-beginner message
yeah but that was javascript syntax which are anonymous methods
yeah properties are super nice
Ah okay, got it
Haven't really touched JS and from everything i've seen/hear I hope I never will
it's a crazy language that i wish i didn't need to know about
I feel like you guys have had a bad experience with an actually interesting language
Hello, apparently my problem was not fixed. I removed the clear code, it was not the issue. The only thing which affects the problem is whether I call Invoke or not. I commented out ALL the code in the function getting invoked, it still causes the error only if invoke is called. Even if it's called AFTER I call RemoveAt
It's just that everything around the language is trying to be the best
Take a look at this:
it prints "a 1", then immediately throws error at RemoveAt. If I comment out the task.Task(), then no error occurs. The task getting called is literally empty.
Things you will never experience if you just use the language like a normal person
C# also has these
(yes, but it's funny)
Yes, it's very weird
i do use quite a few languages and passively hate all of them 🙂
This is so bizarre, I can confirm that in this code the Task never gets called. However if I comment out the third line, it works perfectly fine with no errors at RemoveAt. Like what the actual hell??
this feels like a race condition
i had that vibe from the original code but i can't pinpoint it
but the task does NOTHING but Debug.Log
i have no idea what kind of c# illuminati bs is going on, Im gonna make it store things to remove in a list each frame and remove that stuff at the end of the frame
wait what's task there
don't use Task, use coroutines instead . . .
Task is just a name, its a System.Action<float>
wha? confusing AF . . .
yeah sorry, not the best naming scheme
Hope this clears it up
so how's task defined here?
wait, are these anonymous delegates?
how is task, the variable, defined
that's object initializer syntax for some ScheduledTask object they've created
Bullet.Schedule is the schedule function from above, RunSpawner is task, 1f is delay
im not 100% sure what this means, but you can see in the ss how I use .Schedule()
i was referring to task, like Chris was asking since we had no idea how the Action was defined . . .
@gloomy cosmos can you show this please
or paste the relevant code formatted
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
📃 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.
should share the full class tbh
like this?:
private class ScheduledTask
{
public float TimeToRun;
public Action<float> Task;
}
sure, Ill put on pastebin in a sec
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
and just to confirm, the exception is being thrown on line 40 and not line 41 now?
Yes
the print in the task never runs at all
yeah that seems like it'd break on line 41
have you tried adding a Debug.Log between the remove and the call
as I said, I'm baffled. SOmehow commenting out code that hasn't yet ran fixes it
this really points to the exception being thrown on line 41 then
Ill add
I double checked, its not
make sure you've saved
I will run with print in between
i haven't chat. so, im not sure if this is what you guys are currently talking about. but, does anyone know of a shorter way of doing this?
public float time;
float t;
private void Update()
{
t += Time.deltaTime;
if(t >= time)
{
//code here
}
}
note that this this script doesn't include the using directives, so the line numbers will not match
Very strange, I added the inbetween print now unity repots the print line causes the error. I guess you guys were right, no clue why its showing wrong line
shorter way of.. doing what exactly?
if the goal is just to compare 2 numbers you can't get much shorter than that
again, make sure you've actually saved and recompiled. and if you have any assets that fuck with compilation like hot reload, then disable them or restart the editor
yes I know, the file contains several classes so it was mismatched anyway
my bad, just fixed it
a timer
generally "shorter" is not the right direction to go it
I thought that using var element = List[i]; would cache it, but I guess not. Thanks for the help, I think it's fixed now
you should go for stuff like more readable, more generalizable, more elegant, more flexible, etc
you could use coroutines for example
well, hang on a minute
with this approach, you could set t as some time in the future and check that against deltaTime instead of adding to it, for example
that would, but on line 41 of what you showed you were still accessing by index. what did you actually change to fix it?
I guess technically if you wanted to you can steal the schedule code that I posted, it does pretty much that
not really a shorter way but using a coroutine or a Timer class is more readable and reuseable . . .
{
if((t += Time.deltaTime) >= time)
{
//code here
}
}```
Okay thats ridiculous
The object isn't getting magically destroyed
it's just being removed from the list
element remains exactly as valid as it was before removing something from the list
well the error implies that it does not, somehow
@rich ice
the error doesn't imply that at all
I can assure you that you're not correct!
swapping the two in order (removing and calling) fixes the problem
Yes, because you're accessing List[i]
of course it does, but task isn't relevant, tasks[i] is
i am aware, i just have to right it out a lot
wait
yoink
I just realizes List[i] was used in there, I am so silly for noticing earlier
...we told you bruh
which is precisely why i asked you to confirm which line the exception was thrown on
I swear it said the line before the actual one
this is the culprit: tasks[i].TimeToRun); . . .
*i actually didn't know you could do that
*
anyway now its fixed, thanks a lot people, (I really do feel stupid tho lol)
(please don't, assignment expressions are such a pain to read)
Yeah don't
t += t += t += t += Time.deltaTime;
let's goooo
g u h
this code is bad because it is framerate dependent! ✨
nothing else wrong here, no sir
i didn't know you could do that either
there's a line from Jurassic Park that comes to mind
and it's not the one about how smart the dinosaur is
i've never watched jurrasic park
so... this adds dT and then octuples the result
i hate you so much right now
t = t++;
noop in plain sight
your IDE will probably correctly determine that this doesn't do anything
may your ide forgive you because i sure won't [racks shotgun]
t += t *= t -= t += - Time.deltaTime;
finally, readable code
Hey boxfriend, don't know if you're still in the chat, but wanted to thank you for the help for the past couple of days. Helped so much, and finally got it to work out!
Hey, I'm making a clicker at the moment and I am trying to make some sort of golden waffle flying aroudn that you have to click for some extra cash, when it was forced to spawn in 1 place it would work but when i added that it spawns in a random spot on the canvas it stopped spawning at all (can't even see it on the list of objects), debug log still says spawned but its nowhere to be found https://paste.ofcode.org/nFTZq92TJGHhPsQqCN5X9U
wow why is it not formatted at all
tab key machine broke
Who needs that anyway
And I remove it:)
why are you starting Chance every physics tick
why do you hate yourself and everyone here
While loop caused some problems earlier so I changed it
your while loop should just be in the coroutine which could then just be started in Start instead of every 0.02 seconds
your yield break and yield return null are also pointless because they don't do anything after they yield
as for why it doesn't show up, instead of spawning the object up to 900 units away from the origin in world space then setting it's parent to the canvas, spawn it as a child of the canvas immediately
Oh god I thought I have to use either for the enumerator to end
you aren't yielding the WaitForSeconds so you're spawning it and immediately destroying it
Can someone please help me?
For some reason my player doesn't jump, even though in the debug, I added debug.log to show when the space button is being pressed, and it shows it but I don't know why it doesn't jump.
I can provide my code, a screenshot of the interface.
also I'm using a camera holder which maybe is the problem
just noticed that too lol. so there's literally no waiting happening
Oh I didin't notice that
you're leaving out a lot of information here
format your code
you will need to provide the code. #854851968446365696 has guidelines on what to include when asking for help. don't force everyone else to ask you to provide the information you intentionally withheld
Ok. thank you
how can I paste it in a way that it will not look like a lot of text, but rather as a formated code
I'm facing an issue where an anonymous function passed as a parameter become null, but the value 5 (another parameter) works as expected.
private void Update()
{
if (Input.GetKeyDown(KeyCode.F))
{
_objectDetected.Interact(() => {
_isInteracting = false;
}, 5);
}
}
// objectDetected
public override void Interact(Action action, int a)
{
Debug.Log(action); // this become null
Debug.Log(a); // and this still 5
}
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
📃 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.
Surround code with three backquotes. Not quotation marks.
use this ```csharp
but also more importantly
📃 Large Code Blocks
Use links to services like
A tool for sharing your source code with the world!
you didn't save the paste
unless you are calling that method elsewhere and passing null explicitly to that parameter there is no reason it should be null. what does the log actually print
What exactly does the first log show? Just empty?
oops
don't save the webpage, press the save button on the page that stores the paste on the site and generates a link to share it
...why would you ping me twice for that
Yea, sorry
A tool for sharing your source code with the world!
Does it work now?
wait nvm i read it wrong
so you're getting the Jump Key Pressed log, but not the Jump Triggered log?
Ohh wait, It shows me the cooldown and the state of "Grounded"
I dont think it's working
Got the waffle to spawn now (thanks Chris) but after a few times it just spawns outside the canvas even tho the Vector3 is set to the corners of it
you never reduce the cooldown or reset readyToJump
see boxfriend's message
Here are the references, i call it twice with (null,1) and (anonymous function,5) and last one is the base class definition
do you think that is the problem?
I can try that out!!
i call it twice with (null,1)
so you explicitly pass null and it prints that it's null? so what's the problem?
ah wait i see you're setting the cooldown, nvm on that
the (null,1) works as intended but the (action,5) become (null,5)
but you never reset readyToJump, still
show what it actually prints.
can I do this?
private void reset_jump()
{
readyToJump = true;
}
what does readyToJump even mean
you already have cooldown and grounded checks
It's for checking the state of the jump and if the "Player" can jump or not
what defines if a player can jump or not
I dont think that even If I will delete that, then it will work
if he is on the ground and the cooldown has passed
ok, so that's handled by grounded and jumpCooldownTimer
what does readyToJump do then
So it doesn't do anything
exactly
in what order do these calls happen?
It did show the player velocity this time, but it showed this
and your player is on the ground?
what all the 0 means?
that It's probably a problem in the jumping function?
player velocity isn't relevant here
that's a postcondition, what comes after the action
what you need to focus on are the preconditions
Input.GetKeyDown(jumpKey), grounded, jumpCooldownTimer <= 0f
so the input and cooldown work
is your player on the ground in that screenshot?
no, but when starting the game he is falling down
I ran the game again and encountered another bug. I will fix this first. The print result here
....ok, so you have other issues
those look like the two null calls you mentioned . . .
where's the 5 from the call with a non-null action
not falling through the ground
falling from the air to the ground
I checked before coming here, and there was a 5, but now it's gone. Let me check again. Thanks everyone for the help 🤯
yep
player height is 2 in capsule collision, 3 in general and in the code it's 3 as well
I have tried a lot of things but the y pos of the waffle says -717 and the random is capped at -350
what's your current code
ok and have you set the other thing i mentioned
yes
not formatted yet but https://paste.ofcode.org/Sziap9dVuNfP996FtqphFw
there's probably a button in your ide to autoformat your code
have you set it correctly to whatever layer the ground is
yes, the ground layer is
whatIsGround
Oh yeah it was shift alt f
Shouldn't hurt as much now
thank you
where are you looking? the inspector?
yep
Chris what do you think I should do?
that's gonna be the relative position, but transform.position is the worldspace position
So how could I get the worldspace pos of the canvas edges?
it'd just be the position of the canvas
but you can just assign to localPosition instead
Alr i will try that
could try debugging the raycast to see if it's actually long enough
Tysm that worked
I dont know what to do anymore
It doesn't even show that it went to the jump method
right, because the conditions aren't fulfilled
you need to debug why grounded is false right now
sure
I will try to figure out why
this is to check the grounded
grounded = Physics.Raycast(transform.position, Vector3.down, playerHeight * 0.5f + 0.3f, whatIsGround);
Is this good?
me again, I'm getting the error "The name 'ggg' does not exist in the current context" it's an Instantiated game object and I'm trying to Destroy it when pressing the button using a function https://paste.ofcode.org/H55FhtnnpyY85N9TFbFkWR
There is nothing called ggg in the MoneyGoBig function
Is it possible to pass it from the enumerator to the function?
If you store it in a field variable, whenever you call MoneyGoBig, that would destroy the most recent object that ggg refers to
There's a missing piece here: What calls MoneyGoBig and when
The prefab button
When clicked it's supposed to destroy itself
But the script is on another game object
Wouldn't I have to drag and drop then?
Why not just Destroy(gameObject) then
So if it's supposed to destroy itself, you should have a script on that object
Why is an object sending a message to a different object to destroy itself?
That'd be like me writing a letter to someone in another town to come and bring me a coke from my own fridge
To be fair I forgot I could even do that since I don't really understand prefabs
I will try that
A prefab is just an object that exists as a file instead of in a scene
A prefab is the same thing you have in your scene, just existing as a file instead, to be instantiated in any scene
Is there inherently anything wrong with this code?
It's causing seriously glitchy behaviour with my projectiles but i haven't the slightest on how to fix it
void FixedUpdate()
{
if (rb.linearVelocity.magnitude > 1.1f)
{
transform.forward = rb.linearVelocity;
}
```}
What is the "glitchy behavior" it is having?
whenever i throw my projectile spear, it will orientate itself correctly to follow the head however whenever it lands & begins colliding with the floor, it then spazms out & teleports all over the floor, i have a clip but it's too big to post, i can share a google drive link.
This might wind up causing the spear to clip into the floor
which will then make it go flying
hmm so it might be just because the spear is glitching in the floor?
Here is a clip of the issue
Don't use transform when dealing with rigidbody objects.
Either try setting the rigidbody's centerOfMass to the tip (or even a bit futher) or use torque to rotate it
The center of mass solution should be "realistic"
If you manually rotate it, I'd also add a speed limit below which it will not rotate
i have tried this, nothing worked for me. I've managed to get it sorted now with one line of code & suddenly it works perfectly
transform.forward = Vector3.Lerp(transform.forward, rb.linearVelocity, Time.deltaTime * 0.25f);```
I guess that'll prevent it from very rapidly turning
it seems to have done the trick, been playing around with it for a while now & hasn't broken at all yet
Unity/Visual studio dreaming about a file here.
The Workspace does not exist, and just links to WorkSpacePanel.
I really have to be careful with ctrl + r + r
https://hastebin.com/share/onadobowuc.csharp
I gave a link to the movement, but the swaying doesn't work.
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
how do I fix this? Im trying to access CanAtk from another script, but it wont let me
It says because of the protection level
You made it private
I want to make a game like this, if you can notice the blocks above look 3D, so like shall i make a 2D project or a 3D project?
2d
Or 3d
you can pull it off either way really
The fact there are real time shadows in this, use 3D.
how do I get the ground that a wheel Collider is colliding with
Also, the clickable/interactable elemts look 2D, so I can use them in UI, and create a 3D project as well, right?
yes
Basically you have to select slots and the slots can shoot the front row blocks if they match the same color
yeah you can do that with UI
yeah
These can be world space ui, sprite renders or even just mesh renderers. Just because it looks like ui or 2d, doesn't mean that you need a 2d template for it.
yeah true, so its safe to start with 3D
Yes. And you can always configure it to the same state as a 2d template.
The templates are just starting config/settings. Nothing that you can't change later on
okay, thanks!
so how do I start? like a grid system is needed for this game?
That could be one way, yeah.
I mean im approaching a game like this the first time
Maybe look up tutorials on similar games/mechanics
Yeah
so how do I do that?
But basically break it down. The top grid could be just an empty game ojbect with a script that instantiates the blocks in ordered fashion and controls them if needed.
Did you look at the docs?
yeah, thanks
how do I make this a chain(sorry if its not the right term, if there is one)? like if I press left click, it will trigger Attack, and if I press right click within a certain timeframe after I trigger attack, its triggers Attack2
private void Update()
{
if (Input.GetMouseButton(0) && cooldownTimer > attackCooldown && playerMovement.CanAtk())
{
Attack();
}
if (Input.GetMouseButton(3) && cooldownTimer > attackCooldown && playerMovement.CanAtk())
{
Attack2();
}
if (Input.GetMouseButton(2) && cooldownTimer > attackCooldown && playerMovement.CanAtk())
{
Attack3();
}
cooldownTimer += Time.deltaTime;
}
private void Attack()
{
anim.SetTrigger("attack");
cooldownTimer = 0;
}
private void Attack2()
{
anim.SetTrigger("attack2");
cooldownTimer = 0;
}
private void Attack3()
{
anim.SetTrigger("attack3");
cooldownTimer = 0;
}
}
use some type of integer track which attack you're in, not even needed to have so many seperate methods
how do i manage the background (being 2D) and putting 3D blocks in the same 3D scene? Please someone explain I am new to this type of style
not a code question - #🔎┃find-a-channel
Weird issue I'm having. Currently, I call on a button and it does what its supposed to do, but after I press another button, the first button acts like the 2nd? It's weird, and I can't figure out the function thats causing it when I press the button, since it works before I press the 2nd button. If it helps, here is the code that acts on the 2nd button press and repeats on 1st:
https://paste.ofcode.org/YFvpGrFgxKUvScSdnGNxYn . Any ideas of what's causing it? I've never had this problem before, and absolutely can't figure out WHY it's changing the first button function. (Please @ me if you respond)
Crap that code is probably a little long, moving it to a pasteofcode...
so the intended behaviour is that you want to:
deal card
stand
deal card
but whats happening is
deal card
stand
stand
is that whats happening?
Yep, and I don't know why it's switching over since I'm clicking the original button
how are you assigning the function call to the button?
are you doing it via unity events in inspector or manually assigned in code via button.onclick.AddListener?
Unity events in inspector
do they both call separate functions?
or is it the same one with a different param or something
They do, they're entirely separate. Most I can think of is they are on the same script, but I don't get why it would call a different function. I'll show you a quick photo of both button function calls:
send me the full script for deckmanager and dealerdeckmanager
throw it in a pasteofcode or something
Gotta:
Deckmanager: https://paste.ofcode.org/34N6sMtLaLTaKHtUJuwUVCc
DealerDeckManager: https://paste.ofcode.org/cUH4ECsFZ8YgYT9F9qsuNP
nothing suspicious here?
when the issue happenns, click on the "resetting player hand" log under ResetPlayerHand and send then stacktrace screenshot here
specifically this after clicking on the log
I don't know why it would do MoveNext()
is that the full stacktrace or is there more if you scroll down
Thats it
also MoveNext is just because fo the coroutine
better yet, throw a debug.log under ResetPlayerHandVoid
something is calling that coroutine and because its under a coroutine its not sending the source call
so just throw a log in there and try again
Yeah, it's not even calling ResetPlayerHandVoid, it's just moving straight to the ienumator, which is really weird
the yield return null means that something at least a frame before is calling the method
what are all of the things that can cal ResetPlayerHandVoid?
is it just the buttons?
It's only these two, which are only called when the deckmanager or dealerdeckmanager call for them. the buttons just start the things that call these two methods
and youre saying that even when you put a log in ResetPlayerHandVoid nothing comes up when you click on deal?
Yeah, Here Ill get a quick video to show you the entire logs
sure
Alright, finally got it to show up the ResetPlayerHandVoid comment, maybe it was just slow. I think it's something with DealerDeckManager. Currently gonna try it out...
it was the stupid variable. playerstands, I never turned it back to 0. Ugh! So happy you helped me with that though, I NEVER would've figured that out. Finally going to go get some rest. Again, thank you!
nice, and np!
Why is this code uncreachable?
because you are returning
ima ctually so stupid
code runs each line top to bottom
I'm sorry the easiest things always miss me
also is there a reason you're doing this instead of just using Keycode ?
not in particular
but I'll try thgat
wait yeah I want to get the input not just a keycode
wdym the input ? GetKey gets inputs
doesnt getkey return a bool
yeah checks if ur holding the button
im trying to make sure that the button that is pressed is the same as the letter
does input.inputstring not suffice?
I currently have one M key
and im trying to make it so that only when I press m it changes sprite
is released is supposed to chjange sprite of the key to fgray
this is where I use checkkey
are you pressing these on the keyboard or the mouse ?
keyboiard
Input.GetKeyUp gives you when certain key was released
I have a quick nonrelated question
in a case like this m is a child of keys and keys is a child of keyboard correct?
yes
looks overconvoluted, I still don't know what you want you're going for tbh
Ok so
you just want to change sprite according to keypress?
Im trying to make an on screen keyboard
with all keys of course
then when I press it
it turns to another sprite
sprry i meant when I press the corresponding key
it changes sprite to a pressed down one
is Key a custom class?
yes
So in this i made checkkey ourput hello in the debug log and made ispressed output lol in the debug log
but there is hello in the debug log but not a bye
I would do it a bit different
how?
Make it clear if Key is the UI button / key. if it is store the char in there
Key is the highlighted gameobject and it is the M key on screen
are you going to manually create these? that painful lol
well how else would I do it lolo
store the chars in an array , iterate through array instantiate a UI button and assign it the char
Im not good enough for that lol
you should probably be starting with a simpler project
make it simpler?
so you're telling me your school just throws you this project without any basic understanding of the thing you're supposed to do?
no I chose unity like an idiot
so what is the assignment and why did you make it this complicated ?
IB computer science internal assessment
how is that a specific project?
its not you make one up
look I made some mistakes but theyre not something I can fix now
Maybe thats true but I'd have to do all my previous work again for that
that'd be harder
do as you wish, better than being stuck on a much more complex system / problem imo
I dont have the guarantee of my previous parts all being perfect scores
The code is only half of my grade and my teacher of course wont grade it again
What is it called when you use a single int to represent multiple pieces of information? For example a three digit int where the first two digits convey thing A and the last digit conveys thing B. I thought 'bitcode' but idk if that's right
or for example a hexcode where each int represents the state of a surrounding tile
bitflag?
A bitmask is a representation of many states as a single value.
And then what's the best practice for 'cutting out' certain digits (the part of the bitmask that's needed)? Have to convert to string?