#π»βcode-beginner
1 messages Β· Page 342 of 1
cuz rn I am calling lerp several times
probably should be 1
if your taking a step forwards your moving your leg once, you dont do it 100 times while trying to do it once
im having an issue where when i change the float timeInterval to a smaller number, the reels on my slot machine dont spin faster in the editor, but if i build the game the changed value seems to actually affect the speed they spin, is that some bug with the editor or is there a reason for that behavior?
while (spinTime[reelNumber] > 0f)
{
reels[reelNumber].localPosition = new Vector2(reels[reelNumber].localPosition.x, reels[reelNumber].localPosition.y - 21f);
if (reels[reelNumber].localPosition.y <= -630f)
{
reels[reelNumber].localPosition = new Vector2(reels[reelNumber].localPosition.x, 630f);
}
yield return new WaitForSeconds(timeInterval);
}
wait if Im using one lerp call how am I gunna have different actions happen at differen speeds
Like I dont want to aim in at the same speed my gun sways back and forth
how i make UnityWebRequest with button? Because once I change from public void to IEnumerator I no longer see on list of functions when I set function to run on click
use a "void" to start the coroutine
so you can set it in the button and also use a IEnumerator at the same time
How small is the value?
was initially 0.0075, i tried lowering it to 0.0015 and its the same in the editor but looks right/faster in the actual build
I need help real quick: how can I have a value be one of two classes?
public void Teleport(Player || Crate teleportedObject) {
teleportedObject.transform.position = portalExit.transform.position + new Vector3(0f, portalSize, 0f);
}
cool UI!
thanks
and jumping impossible
the code that looks up and down should be moving a child object.. like a camera..
not the root /main gameobject
figured out my problem
oh
havent solved it yet
public void Teleport(Player teleportedObject || Crate teleportedObject) {
teleportedObject.transform.position = portalExit.transform.position + new Vector3(0f, portalSize, 0f);
}
Still, no idea. Can someone help?
the pickup code isnt referencing dont destroy objects
this is the code for moustmovment
so I would put that on camera
like dis
ur up and down rotation should be moving a camera/child gameobejct not the main object
i can help i think
ohhh I see
no.. not all of it..
wait so is the code I just sent just totally wrong
u'd probably reference ur camera in that script
and apply the up and down rotation to the camera object
or have it on the camera.. and reference ur player gameobject and use it to rotate left and right
I mean, go ahead. Do you have anything so far?
was looking for my example
player.transform.position = startPos;
this is the code i use to spawn the player in a new scene
Thanks!
i rotate the transform.localRotation (camera) up and down..
and then i reference my player object.. to rotate left and right.. the controller.transform
so I can put the script onto the camera
u can try it and see..
okay
Ya that is true
Freebie of the day!
but my teacher wants us to finsih the game by wednesday
so I am just too lazy too
figure out c#
what i showed was a simplfied way of just teleporting but what your code is trying to do is a bit more complex
they both need to share a base class or interface . . .
public void Teleport(MonoBehaviour teleportedObject) {
if (teleportedObject.enabled) {
teleportedObject.transform.position = portalExit.transform.position + new Vector3(0f, portalSize, 0f);
} else {
Debug.LogError("Teleported object is not enabled");
}
}
could work
or just pass its transform instead of a specific MonoBehaviour. you only care about the transform in that method anyway
they're both GameObjects, just use that class, or Transform . . .
so for the transform for controller, I would use the player object
if you only need the position, then Transform makes the most sense . . .
i put controller AND IT WORKS
WAHOOOOOOOO
wait what the
I can do a 360 when I look down
ok did the debug log and the pickup portion in my inventory script is the problem
that number is small, especially for waiting a single frame. maybe the editor cannot correctly show the difference. try using full-screen mode from the editor; that provides better performance, than the in-window editor with the inspector . . .
This logic appears fine
tldr i have 2 test items in a room
if i pick one up and leave the room without the other the pickup script work in destroying the game object but the itemdata doesnt show up in the second slot
Did you change both the data and also the UI, or just the data?
its becuase the itemdata after i leave is now persistence and on dont destroy
Step through with a debugger and see if you can verify after the line slot.itemData = itemData; that your slot's itemData was updated as expected.
I suspect you may be updating the data but not re-drawing it wherever you are expecting it to show up on your GUI
i'll run the debugger but the debug.log kinda confirmed my hunch
like I can look all the way down, look upside down, than right side up
ddol cube i made did not register the log tho the seperate pickup script still did its thing
wait
i might have a fix
nvm my idea didnt work
ya i havent fixed that yet
you need clamp the rotation for the vertical look
u could ask here someone might know how to do it
yo guys how do you clmp rotation for vertical look?
search "clamp camera" in here and you'll find plenty of examples
alr
also obligatory: use cinemachine
man
please finish a though before pressing enter. they have similar syntax, and the absolute fundamentals are the same, but the languages do work a bit differently
i see
so im cooked
nvm bro
that doesent even make sense what I just said
2 completly different language
microsoft java π
As spawn camp games said, if you mean programming in general, it will a bunch if you're getting started with code. If you mean unity unity, then no. Unity operates in C#. I believe you ain't that cooked yet, I started learning unity a week (or so) ago and the C# part ain't that bad.
java and c# are very very similar
The principles are the same, for sure it will help
indeed
yeah, you'll have an easier time ;earning C# if you know java
it'd definitely be much easier than going from python or js to c#
oh okay
https://www.spawncampgames.com/paste/?serve=code_429 since its my code.. i went ahead and clamped it for ya
I did go from js to C# and the switch is not that bad tbh
dynamic vs static
js is just much more lenient
yk my teacher is odd, taught us java the whole year, and our final project is to make a game in unity
you can set the limit to whatever u want @silk fossil
what is this school bro
js -> ts -> c# easier than js -> c#
pain academy
yooo tnx bro
or just cut out the middleman and go java -> c#
or just go c# from the get go π
just normal high school, its ap csa class, we learned java whole year, just to do unity final exam
ok
actaully tnx alot
and just in case u dont know its wrapped in a name space..
if u want to reference this script anywhere you have to
add using SPWN; at the top.. or use SPWN.ControllerCamera as the reference type
i was just about to sleep without fixing that
why bring up javascript and typescript at all here though? neither are related to java in any capacity
yes c# goat
context
I just took the AP csa exam
had nothing to do with unity at all π³
my point exactly
I mean unity wasn't mentioned
Exo and Amster brought up js to c# transition
why were you guys given unity?
okay tnx
(:
ah fair enough
I was just saying it would be harder to go from js to c# than java to c#
I think my transition was so easy is because my js code is literally object oriented
js is inherently object oriented
oooohhh noooo... my syntax script is broken! why tf is this SerializeField not colored... has to be b/c the comment above it
spawn camp games, if I get an A on this final project, it will be because of you lol
πͺ heck ya
ik what you mean, I mean the way I write each thing, structurally similar
idk just kept unity in the back of my head the whole process
enough of that tho
most of the JS I've written is similar to what you'd see in java I suppose
but on a real note.. dont copy and paste code.. unless u understand it.. so take a moment and look at why the rotation is broken up to two different functions and also how the clamp works.. but since ur code was soo similar to mine i figured i'd throw ya a bone
regen project files maybe ?
I almost put bool on the AP java exam
hehe
alr
tnx
lol, no its a pastebin
ohhh thought that was vs
unrelated.. but i just noticed it soo i figured id mention it to 000000
trust me, if i were to do unity without a deadline, i would atleast get a better grasp of c#
nah, im not as cool as VS.. VS knows what its doing π
you can use String in c# too (just need to import the System namespace). in fact string is just an alias for System.String
well that's confusing
thanks a lot microsoft π /j
lots of the original classes are pascal
wait w0t? java is String?
well it's just like int, long, float, double etc are just aliases for System.Int32, System.Int64, System.Single, and System.Double
yup
is int Int
fair point
no int is a primitive
ya
String is a reference type
bool is boolean tho
and then its usually javascript
String hello = "sjssjsjjs";
I love javascript
=== π΅βπ«
==== when?
If anything it's just javas version that's confusing
nuh uh! π
jk
in javascript i recall that being a thing especially for checking string vs digit equality or something
its been a while since i touch js
wait yk how an array can be changed if it is in a parameter of a method and how primitive types cant, since string is not a primitive type, it should be able to be changed in a method as a paramater, but it doesent, Makes sense normally, but being a reference type does not
does it not?
I would imagine it would
my patsebin site i was using earlier is javascript.. but to be fair.. its a library i mainly copied and pasted.. any adaptation i had to do took weeks i think i remember π
i'll just stick to c# for now
~~
actually i think i shouldn't post that screenshot.. those are system type directories.. dont want ppl breaking into my pastebin site :D~~
like if you did public String (String n)
n would not be changed
much like in C# strings are immutable in Java
im pretty sure
oh you're right
when you modify a string it returns a new string
ohhhh
no that makes sense
that's also why string[3] = "e" doesn't work
There is also the ref and out keyword if you need to change/assign parameters
this is true to every data type no?
some are directly modified
no, there are plenty of classes that are mutable. string is not one of them
ya but like for arrays hsha(String[] array)
ahh, well today i learned.. i actually dont think about the internals of stuff too often.. i probably should more often
the array can be changed
mutable
its just weird
see thats a new term for me
cause java werid
you didn't know the term mutable?
interesting
mutated
I learned that a while back
Nope, simple example think of a component. If you modify the component, it doesnt destroy and recreate it
i did not π .. i rely on magic very often
π
like when something just works.. i dont think about it until it doesnt
probably a flaw tbh
If you are making small games, there is definitely an art of just pushing the minimum working version.
lol, very true.. π€¦ββοΈ
from what I remember, its true for primitive types, string, boolean, int
but not refrenced types, array, arraylist, 2darray
ohhhh that makes sense
dont quote me tho cause I learned it in class while I was failing
but im pretty sure
oh i dont.. i fact check almost everyone tbh
yea, im aware of that.. when i first started learning i didn't.. i assumed anyone that published content knew what they were talking about..
then i slowly realized thats not the case
wait so in c# strings are just primitive, not refrence
strings are reference types
strings are not primitive
do they just act like priitive then?
strings are reference types . . .
oh im cooked
computers know numbers.. computers dont know words
got 7 people typing
they are immutable. just like in java
oh ya
are strings really like objects in java
and their equality is overloaded to check the contents rather than reference equality
are they converting those nums to letters?
huh?
me and the homies all do (String)
not sure.. Unity's ToString always works
in c# pretty much every object has ToString
you can type csat????
probably
yes u can cast in c#
i could have saved myself from so many F's
dunno, this here is C# and unity . . .
idk.. if we keep talkin about java ur gonna have to shift into another discord π
this isn't java discord, ask them . . .
np π
Real.
https://learn.microsoft.com/en-us/dotnet/api/system.object?view=net-8.0#methods
not "pretty much" but literally every object has it
ya just using fluff words π
it's a method of object. that makes sense . . .
i'll give it a try in a moment
it returns the name
they overridden it to do that yes
smart guys here @ unity
when you've thought of almost everything π
soo im starting to realize theres alot of redundancy in unity's c#
When I'm colliding with a coin I want to increment a variable and destroy the sprite, is there a better way to do this instead of using tags and strings?
well, don't compare a string.. use CompareTag instead..
if it has a Coin component u could check for the component
with a TryGet
use CompareTag or GetComponent/TryGetComponent, or an interface . . .
!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.
π 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.
!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.
double kill!
double kill
tripple
triplekill!
No other way tho?
lol.. mobile guys can't read ur embed text
wtf happened? lol wahahah
what is the problem with the current method exactly?
and if the class is too large, it cuts off anyway (even for PC users) . . .
post your code correctly. that's what happened
read the Posting Code embed..
mobile people can't see what u posted earlier
i just listed a bunch. is there a problem with your code?
So that's why, okay I'm sorry.
ya, its just protocol around here
this i didn't know actually
100mb limit for everything else..
Hello guys, can you help me on how do I make my AI stop every time its reached it's destination? I tried everything. I have no idea.
it says basically xx Lines Left
it cuts off the preview at like 100 or so lines even under the file limit. but it's still a pain in the ass to read an embedded text file rather than a link
it doesn't stop?
it should when it reaches its destination.. you can modify Stopping Distance on the agent itself
Yes, it doesn't I don't know how though, that's the problem.
when it gets within range of its destination you just give it another. so naturally it will never stop until you stop giving it new destinations
you tried increasing stopping distance?
I'd debug the values too, make sure they are what you think
when it gets to its destination u can make it wait a while before giving it a new one.. if thats what ur doing
my current stopping distance is 0.5
That's what I'm trying to do, Every time it supposed to give direction I try to make it waitforseconds(2f) through the IEnumerator data type
oh wait ur running it every frame
is that why? I just followed a tutorial, that's what's on there.
Am i supposed to call it once?
not every frame?
are you trying to make it pause? what behavior are you looking for ?
ya, u should probably only set it once. and then wait until its stopped before setting a new one
I want it to stop for a few seconds before moving again.
I would use a coroutine or a timer then
^ check if its @ its destination and if its stopped..
if its stopped for so long.. then give it its next destination
so im trying to make an escape menu toggle after escape is clicked twice, a ui that is enabled by selecting another object needs to be disabled by pressing escape first, but i can't figure out how to do so
theres lots of nifty ~~functions ~~ variables of Navmesh agent u can use..
pathPending remainingDistance stoppingDistance
it was coroutine before ? how come you change it
it was not a coroutine before. I tried it that way. it didn't work for me
Am I supposed to only call the setDestinaton once?
if it is a coroutine then yes, put everything inside of it into a loop and start the coroutine in Start instead of calling it every frame in Update
I still have no idea about coroutines and on how and what to use it on to be honest.
is there a smart way to have a whole bunch of items that affect your character without having to reference your Character object on each Item object?
just change the method from void to IEnumerator
IEnumerator DestinationTimerCoroutine()
{
yield return new WaitForSeconds(X);
SetNewDestination();
}```
could call a coroutine once you've reached ur destination to wait for `X` amount of seconds, and then set a new one
lookup the docs on Coroutine
looks like you already had this too
//yield return new WaitForSeconds(2f); // Wait for 2 seconds
ya, looks like u were on ur way to making it work
wasnt working because you probably were calling it every frame in update and confusing the navmesh agent
I knew that from the project I had earlier, but I used my own AI that's how i used it. Not Navmesh and what not. It was 2d.
It's my first time using the agent sorry. I'll try what you guys adviced me .
Thank you.
np
navmesh isn't really AI is it?
no..
its just A* with some RVO
its a pathfinding algorithm
thought so
So supposedly coroutines, when you put it in the update, it will not repeat the code every time?
StartCoroutine will start a new one every frame if you put no limits
Update runs every frame, so a coroutine within Update will start every frame . . .
that's why you run the coroutine once
or just make Start the coroutine
it effectively queues up a new instance of that coroutine every frame
private IEnumerator Start()
no need to start coroutine
Oh I get it now, Thanks.
if (!coroutineStarted)
{
StartCoroutine(MyCoroutine());
coroutineStarted = true;
}```
heres a jank way of making sure it doesn't run every frame π
then at the end of the coroutine u can reset the flag back to false
That's exactly what I'm planning to do now, lol.
yes, but it's an entirely different setup/architecture for items and stats . . .
Thank you guys.
theres probably better ways to do it.. but usually i dont call coroutines from update..
well, i can't remember the last time i did
Can someone please tell me what I am doing wrong? I even already did reimport all and still this issue persists.
It's workign for both move and jump but for some dumb reason it's not working for my interact button
#π±οΈβinput-system probably could answer it better.. but perhaps someone here knows.. I myself suck at the new input system
thanks, i'll try and ask there
comment out the lines with the error, reimport your input action asset, then try again
oh and save after commenting out those lines if that wasn't obvious
you don't want compile errors preventing unity from compiling any changes
thats the worst thing ever.. when importing an older asset and 30% of it is broken..
but it takes u half an hour to figure out that 50% of it is actually broken
I'll try.
if it is still not working after that, then you are not using the correct type
did u regenerate ur C# class?
or is that the method ur using?
not sure if theres a way to tell, just by looking at the code
in your inspector, you have two tabs for PlayerControls (Input Action). are they synced?
ohh, good eye
i'm pretty sure that's multiple separate screenshots stitched together because all of the tabs for both shown windows are identical
^ yeah
lol.. bamboozled
couldn't fit everything hehe
THANKS! that did it!
any time u make an addition to ur actions u need to regenerate ur c# class
or else the references wont be created yet
I see, I thought it was automatic. Thanks for lettign me know.
I tried it now. It still doesn't work am I still wrong about Coroutines?
Context: About me stopping the AI movement through coroutines
Hey! So here I have this test scene and this piece of code.
https://hatebin.com/cabnnztqnk
My main goal is to be able to have a list, which contains lists of "actions" and I want those actions to consist of 3 main parameters:
- the time it takes to start the action/movement
- the time it takes to arrive
- a position to arrive at
But for some reason this implementation I have doesnt work, it doesn't linearly go towards the position pointed out, and the time to arrive variable doesn't seem to affect how long it takes to arrive
I didn't use any tutorials for this so this might also contribute to it being faulty
Slerp seemed to be the best way to do it
and it actually when the list only has 1 element
does it do the same thing with a basic Lerp?
that's something to look into perhaps

but I don't understand why
me neither
also the TimeToArrive is still broken
I have one where the timetoarrive is 5 seconds
it arrives in 2 seconds
and waits for 3 more seconds
that's why slerp isn't working @quick pollen
slerp isn't what we thought it was lol
whoopsies!
how so
Why cant i add an image in elements?
I set it so the time to arrive is 5
but it arrives in 2 seconds
You got no images
okay are you doing proper math or just random scaling?
basically completely ignores the calculation
it wont let me add images
You got no images
clampedTime = 1 - (timeToArrive / actionLists[AL_Index].actions[A_Index].timeToArrive);
transform.position = Vector3.Lerp(selfPos, targetPos, clampedTime);```
this should be the formula for finding the clamped time to arrive
the way lerp works is that it finds a point in between x and y at point t
One Minus, so it starts from 0 and goes ot one, not the opposite
when would clampedTime be changing?
because timeToArrive is gradually decreasing
where are you changing it?
timeToArrive -= Time.deltaTime;
ah
timetoarrive starts at what, 1?
its an inspector element
It doesn't matter, no?
Umm guyss??
I tried it now. It still doesn't work am I still wrong about Coroutines?
Context: About me stopping the AI movement through coroutines
1 - (0 / x) is different than 1 - (1/x)
timeToArrive should just not be smaller or equal to 0
wdym?
ah
okay
okay so what is the difference between timeToArrive and actionLists[AL_Index].actions[A_Index].timeToArrive?
it isnt
The server didn't allow me to say "smaller*".
timeToArrive is the one which's value is used for the interpolation
the one from the list is the constant value
also the one I use to divide the current timeToArrive to get a clamped value
okay I opened your code so I can just check
so timeToArrive initializes to the value and then decreases
got it
so it should increase from 0 to 1 that makes sense
try debug.logging its value?
see what it's equal to
clampedValue I mean
or whatever it's called
you used to use slerp
i was thinking maybe its using wrong values
now I use normal Lerp
lmao wym?
but it still doesnt do the correct position
how can you tell?
like it takes around 5 seconds to go from 0 to 1

it takes visibly more time
okay wait
output the value of the lerp
versus the output of the clampedTime
see what it's giving you
what is it?
It's not about Unity, especially about code, is it?
I had the statement with if (!calculatedPositions)
but I didnt set calculatedPositions to true....
so it kept on updating the selfPos

which would indeed make it independent of time
fuuck
I fucking knew about this being an issue
hence why I created calculatedPositions
Please, provide more context. What specifically doens't work?
I wanted to stop the AI's movement when it reaches its destination. It still doesn't stop. That's the problem for me.
thanks still!
also
once I ran out of elements, I get this error
which would make sense
Do you want to stop it in the move coroutine's condition?
except that I have conditions set up so it disables the script once it runs out of elements
put some debug.logs in there
Hmm can't I do it on another coroutine? Or do I have to do it in the same coroutine? Because I want to isolate encapsulate action in code. I don't want one function to do multiple actions
That was a question where you're trying to stop it
But, right, there are 2 isStopped assignments, one of which is to false.
So you're trying to stop it in Update
Yes, I was. I don't know if its the proper way or not. I have no idea on coroutines to be honest.
Why do you use them then?
Should've read about them first, actually
I asked it here earlier, it was recommended to me.
Coroutines are used when you need something do be done in the specific periods of time. In certain circumstances, a better way when dealing with Time.timeDelta in Update
this is actually for some bullethell stuff
so you know, its important that the positions and times are correct
I haven't done anything. I don't even know your issue.
I don't want to create impossible patterns unintentionally
well you gave hints
so you know
more than nothing, which I appreciate
I really don't follow, sorry.
Let's say you want your character to be simply moved every frame. You use Update, FixedUpdate or LateUpdate, depending on the situation
btw are Coroutines frame-independent? like does something happen in x amount of time even if the game is running at a low fps?
If you have a character which should be moved e.g. 3 times a second, you use a Coroutine, because of the time being calculated more easily there
I experienced that if Time.deltaTime is too high, sometimes things can happen later or earlier than wanted
No
It doesn't happen in the specific, x amount of time, as the Coroutine runs just at the end of the Update.
If you have a game, which runs at 100 fps, it is impossible for the Coroutine to be called more than that.
My understanding is Update is for funtions you want to call every frame. Fixed update is for physics based functions, and lateupdate is used for cameras functions?
thanks!
I have 2 implementations in my code where I create projectiles
one uses coroutine timing, other uses fixedDeltaTime
I was kinda wondering which one would be the best for when you need perfect and frame-independent timings
So the Coroutine is limited to the maximum of 1 / Time.deltaTime calls per second
at 60 frames per second its still 60 calls though
And the specific WaitForSeconds won't work exactly as expected, as the time waited depends on the game itself
Yes, but you cannot call a Coroutine 70 times per second, in your case
kinda interesting
why not? what if you have like 300 fps?
wouldnt it call a coroutine 300 times per second?
I have explained it in the previous messages already
The Coroutine's calls are limited to the fps you have, which is 1 / Time.deltaTime
but isnt it the same with update?
Yes
Coroutines have nothing to do with FixedUpdate
I'm just asking about ways of timing things
FixedUpdate is called in a fixed timestep, which is 50 times per second by default
Can always be changed for the project via settings and via code
what I basically want is stuff to happen exactly when I want them to, independent of update time
That's right. LateUpdate is used for the camera, to ensure it's moed just after the player
I had issues where projectiles would spawn further out or closer in, depending on framerate
which caused some huge issues when creating patterns that required really small and precise numbers
FixedUpdate is independent, but there are certainly some limitations
at first I called it off as a float point error, but I found it to be consistently incorrect at lower framerates
as an example?
what limitation?
you mentioned the fixed timestep
but that feels like more of an upside than anything
because you have full control over it
Is Resources.Load the only way to load a sprite for an object if all I have is the sprite name/location?
The issues shouldn't happen when doing it in Update or a Coroutine, unless the frame rate is too low
provided that name/location is in a Resources folder, then yes
You cannot just make the FixedUpdate be called 10k times per second and hope for your game to work as great as never
I know, the problem wasn't exactly low overall framerate, but on lag spikes
yes I know "just use DOTS 4head" but I don't feel like tackling that just yet
I can put them there, but they are not there at the moment
Just wondering if there are other options that don't require me to put all my sprites in Resources
Then you probably wasn't using the Time.deltaTime properly
perhaps
lemme see if I have a good video
there are plenty of ways to get references to your assets. is there a specific reason you need to do so via its name or folder path?
Well, I have already seen your game with the hundreds of projectiles being spawned, and you probably should use DOTS for these kind of games, but I cannot tell you more, as I don't know it myself
the item is generated on my server, where I can add any type of reference to it, but then my client needs to get the item sprite from the string that is sent from the server
You could throw all of the relevant sprites into a collection on a ScriptableObject and build a dictionary from those sprite references and access it from there, that might be better than using Resources.Load. otherwise Resources.Load would likely be the easiest option if all you're sending is the name or location of it
going with Resources.Load sounds a lot easier
it's probably slower? but I'm not loading new items constantly anyway, maybe like once every 10 seconds or so
I'm working with the Fantasy Heroes megapack from the unity store, it actually has a SpriteCollection built in, could I use that?
The structure of that asset is way too complicated for me though
yeah, seems like that asset is going to initialize that collection as a singleton on startup anyway so you may as well make use of it
Oh awesome, did not know that!
do you perhaps have your own class called SpriteCollection?
according to the documentation that should be correct π€·ββοΈ
yeah, this asset is both heaven and hell lol
the graphics and possibilities are amazing, but it's structured so complex and not the best docs
check what properties that class has to see if perhaps it is named something different
Should I make everthing into a prefab?
No.
My friend created a game manager that overall sees the update of the code but I have a hard time to reference it or even connect the scripts so the ui works such as the life image one
how to get a reference to another object: https://unity.huh.how/references
So you have a GameManager, which you want to connect to?
For a GameManager, you would usually use Singletons
And make it DDOL, usually
honestly, I'm thinking that the "first" game will not use too many projectiles anyway
its only going to contain this one boss, as kind of an introduction to the game idea
and if it turns out to be liked, ill continue
Do i connect my game over screen script over to the game manager?
is this some sort of bug ? is there a fix to it?
you very likely have an infinite loop in your code if it gets stuck there forever
it generates a map in the game and i cant find the infinite loop.
!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.
you can also attach your debugger while the editor is frozen and break all, that will allow you to inspect the main thread to see where it is getting stuck in an infinite loop
Debug.LogError("Infinite loop detected in maze generation.");
UnityEditor.EditorApplication.isPlaying = false;
This isn't enough to exit an infinite loop. It would have to throw an actual error or break the loop with break or return
Sometimes, when I first open the project and then run it, it works. But when I try it a second time, it doesn't work anymore
to add on to this, isPlaying = false won't take affect until the end of the frame, which is never reached due to the infinite loop
I have this code & i don't understand y isKingDefender is still false after setKingDef(vector, move)
are you actually calling that method anywhere?
wdym?
it's calling here
have you verified that code is running?
and that it is affecting the objects you think it is?
debugger says that it entering herec# foreach (ChessVector def in defs) { Figure.setKingDef(def, j); }
uhhh, idu u
& it says that def is a vector of target object
is this normal in unity?
Figure.setKingDef(def, j);
you arent using the 3rd parameter so it is defaulting to true, as per your method definition
step into the method call and make sure that the object being modified is the same one you've been looking at
oh i see above you are using it with false, though the logic is really quite hard to follow.
this is a coding channel, for code
yes, i want to make it true, but it's false
it's the best what i imagined for setting it false for false events
wait
Anyone have an Idea how to make a Hitpoint system? I've been trying to add one to my Tower Defense for quite some time now but I can't figure out how to do so. I want the enemies to do as much damage to the tower as they have hitpoints.
consider moving a lot of logic into other functions, because this stuff is truly gonna be a pain in the ass to debug later. seems to even be a pain right now.
use a float, enemy hits the tower, reduce the float. done
hitpoints at the end of the day is just a number. but if you're having issues with specific code or a specific problem then you should share that
Ok, I will try that
yes
so it is correctly assigning true to that variable then. so however you were checking before was either faulty or something else is assigning it false again
yes
Yeah, you just derive the GameManager from the generic Singleton, I would suggest, and then access it from whatever script you want via GameManager.Instance
Also have more scripts, which should be Singletons and have them access each other
but all the calling of this var r in this functions
I have my Tower set as an endpoint. So like the last waypoint for the enemies to go to. I can't figure out how to make it, so the Tower takes damage as soon as the last checkpoint is reached.
then how are you verifying that isKingDefender is false?
i'm debugging & i see what it doesn't enters in if with this condition
have you verified that the objects you are looking at are the same object?
Is their anyreason this doesnt move my player continously upward? The debug.Log goes through correctly, but the players position stays the same, is the code wrong? or is their an outside source?
public static void setKingDef(ChessVector vector, Moves saveKingMoves, bool isDef = true)
{
chessBoard[vector.x - 1, vector.y - 1].mover.isKingDefender = isDef;
chessBoard[vector.x - 1, vector.y - 1].mover.saveKingMoves = saveKingMoves;
Debug.Log($"{GetFigure(vector).figure.name} {GetFigure(vector).mover.isKingDefender} {isDef}");
}```
-
- Have a script, which manages the variables needed. I would assume, it should be a
singleton GameManager
- Have a script, which manages the variables needed. I would assume, it should be a
-
- Have a script on every
Enemy, which compares its position withGameManager.endPointinUpdate. I don't know a lot about your game, but this should, probably, be afloat,Vector2orVector3, depending on the axes you want to be included.
- Have a script on every
-
- When the
Enemy's position is larger than theendPoint, update theGameManager.towerTakeDamageboolean, or how you want it to be called. This boolean has to be accessed in theTowerscript too. The distance check is also possible.
- When the
The position should be updated based on the ascendSpeed variable, which is also increased via code.
That function is in Update Btw
This is what makes sense, right
Log the ascendSpeed variable and how much your position gets changed
that is going to be moving very, very little. Try debuging your values
I don't understand
my ascend speed goes up every frame i hold space too
ascend speed reaches like 400+ and i dont move an inch
1 * x * deltaTime is very small
It goes up every frame\
ok, this screen says that here linec# col.ForEach(i => Figure.setKingDef(i, null, false));
running after c# foreach (ChessVector def in defs) { Figure.setKingDef(def, j); }
I have written a few sentences for you, and don't seem to understand what exactly you don't understand.
I have assumed, that this should be straight forward. Consider asking well-structured questions about the implementation if you want me to assist you further.
do you have a CharacterController on that object?
Do you have a CharacterController or RigidBody?
CharacterController
that's why. you cannot modify the position of a CC without either disabling it or moving via the CC
then do not use transform.position
Generally you want to multiply dt to acceleration too. Anyways if the position is not changing it is likely that you are overwriting it somewhere after that code.
What should i use?
You have already been told
charactercontroller.move ?
you shuold read the CharacterController documentation and see which methods/properties are available to you to do this
!forums
:speech_balloon: Unity forums β
Have a question that requires a more detailed explanation? We suggest using the Unity forums to ensure your question is answered more effectively.
Is there any way to stop taking input during the time when calling or running a function except for the input that is on hold?
you could Disable the input actions and Enable them at the end
Is there any way to detect which ones are on hold since the last frame?
that way I might be able to disable inputs which aren't being hold
maybe using phase.Started but tbh you would need to test this
hello my problem is the next i have a prefab script called explosion and i try to access to a other object called score for use a variable on in i have try to make something like that but im really bad for reference something someone can explain me how that work ```using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Reference : MonoBehaviour
{
public Score score2;
// Start is called before the first frame update
void Start()
{
explosion expl = score2.GetComponent<explosion>();
expl.score = score2;
}
// Update is called once per frame
void Update()
{
}
}```
what if I create a bool that checks which keys are being held using Input.getKey
that's the old system, I dont think that will work
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class MainManagerScript : MonoBehaviour
{
public event EventHandler OnStart;
public event EventHandler OnEnd;
public void StartGame()
{
OnStart?.Invoke(this, EventArgs.Empty);
}
public class GameTimer : MainManagerScript
{
[SerializeField] private Image timerImage;
[SerializeField] private TextMeshProUGUI timerText;
[SerializeField] private float matchTime = 5;
private bool isStart;
private float originalTime;
private void Start()
{
OnStart += StartHandler_OnStart;
originalTime = matchTime;
timerText.text = "";
}
guys why is this not working after i removed the static
So, does that code not work?
no this code not work but i think he are bad
What doesn't work? Provide more details on the issue.
Does it throw an error? Is there a compile error?
sorry , i cant seem to call the event
"you can't"? Wdym? Is there a compile error?
no it just doesnt work
explosion.Update () (at Assets/Script/explosion.cs:25)
``` he say he dont have the object
What part exactly?
OnStart += StartHandler_OnStart; this part
Okay, let's start from reading the error. Do you understand what it says?
This part is subscribing to the event. There's no way it wouldn't work. Unless there's an error?
yes my instance is null
Which instance exactly? Do you understand what line throws the error?
OnStart?.Invoke(this, EventArgs.Empty); i checked for null thats why it doesnt show errors
it was working when it was i added static to the event
So you think that it's null? Then confirm it with logs or with the debugger.
public Score score;or maybe when he try use it score.gamestart = false;
This is not the line that throws the error. The line number is mentioned in the error.
https://gdl.space/bavizafibe.cpp I have this script and a different script for the damage. It should work but I dont really know why health is not getting set to maxHealth when I start up the game
the line 25 is if (hit.collider.gameObject.tag == "Player")
did u set the number in the inspector?
mb
Ok, so what does the error mean in the context of this line?
yea its null
Great. So what does it mean if it's null?
it isnt subscribing to the event?
Yep
At least nothing is subscribed at the moment when you try to invoke it
There could be several reasons. Start from debugging both the subscription and invocation as well as what objects it happens in.
ok
What do you guys prefer doing when implementing gravity? Manipulating the transform directly, or using rigidbodies/forces?
public GameObject H2O;
void Update()
{
if(Input.GetMouseButtonDown(1))
{
SpawnCard();
}
}
void SpawnCard()
{
Instantiate(H2O, new Vector3(3f, 0f), Quaternion.identity);
}
}```
srry probably very dumb question but how do I check if while clicking you are clicking a GameObject (the card deck)? Everything else works but now I can click everywhere on the screen to spawn the GameObject H2O copy
i dont know
Depends on what kind of physical mechanism you need
What do you mean by physical mechanism? Something like jumping?
but i think my problem come from here my Score is null
and my question is how can i say my score is = to my Score object its a prefab so i cant drag and drop
what about using coroutines?
they won't take input when they are being called right?
Like I have this coroutine which doesn't lets me move when it's called
Maybe this will help? Haven't messed with something like this in a while: https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnMouseDown.html
Hmmm. Maybe not since the colliders need to be marked as triggers for some reason (wait i might be misreading it lol)
Sure. Rigidbody supposed to be general solution for physically accurate case, but player character tends not to be physically accurate thus CharacterController exists for alternative solution. For simple games it could be direct transform move, or case like particles you would want a fomular that you can just directly calculate position from time.
they will take input because a Coroutine must yield at some point
- It means that something on that line is null. You should debug log all the references on that line to see what it is. Assuming that's the correct line.
- If you need to reference something in the scene from a prefab, you'll need to assign the reference at runtime, ideally, when/where you instantiate that prefab.
Hey guys. Is it common practice to use properties in Unity?
Yes, why wouldn't it be?
but other functions won't be running during the time right?
It's preferable even.
they will be when you yield, yes
Gotcha. Guess I'll have to toy around and see what works. Though I'm kind of leaning towards character controller/direct transform manipulation
A lot of YouTubers, Forum posts and Unity docs all use public fields
I should use this to detect collision between 2 objects right? bc what I want to do is to detect if I'm clicking the gameobject with my cursor
Yes, because most tutorials and sometimes docs don't have a goal of teaching good coding practices.
Does it affect performance much?
I don't think so. I think this one works when you click something with a collider
I don't want to disable movement permanently
just when the coroutine is being called
hope it works
No. Properties are just shortcuts for getter/setter methods. Even if there is a performance impact it's small enough for you to ignore it.
For simple properties it will be inlined and won't have any performance harm.
No. There is a small performance impact when accessing the property, which is then accessing the method, but there is no way you would ever mention it.
but what if the object I want to copy is not the object I'm clicking?
Thank you guys. Also does Linq have any obvious disadvantages?
Like performance overhead
Or maybe incompatibility with Unity
It makes GC allocations. Whether that's critical or not for your project is up to you.
I'm not sure that can happen? Unless I'm misunderstanding the question
Sorry, what is GC allocations?
Many Linq operations allocates every time you call it so you might not want to have it in performance critical logic.
Garbage collector. It allocates temporary memory basically, that needs to be disposed. GC is thought to be detrimental to performence, but it really depends.@jack.hk
Ahhh gotcha! Thanks
But if you know the logic behind it then it will be very useful tool
Ok so, I have a deck. If I click the deck, then it should give me a specific card creating that copy in the board.
The card creation works, but I don't know how to check if I'm Rclicking my deck or not, right now I can Rclick everywhere and it spawns the card.
I don't imagine the deck has a collider?
it does, a 2D box collider. Srry if the question is stupid lol, I just started
Oh, cool, in that case, you should be able to use that OnMouseDown method. From the brief description it gives, I think you will be adding the function and its logic to the thing being clicked, so you shouldn't have to worry about clicking the wrong thing, because if you do, nothing will happen
like, the script is linked only to that object, but it still does work everywhere
is there anything else I have to do to make that work?
Hello, Should i connect this to my game manager or The canvas? when creating the game over screen?
You may make is using canvas.
I imagine you can do something with raycasts? Unfortunately, I'm just as new as you are, so I'm kind of just spitballing now
So accessing the Game Over Scene when pressing the button is possible. I would usually create a variable for every button I have, then subscribe to an event, but you may do it via Inspector too
I'll try to look in the raycast system then, I already kinda considered them as an option
thank you
What is the original issue?
Checking if the GameObject is clicked by the player?
this
this is the code
When I create the script should I put/connect it unto the Canvas or the game manager?
What script?
game over script
I would consider using Physics2D.GetRayIntersectionAll.
Create a ray from your mouse position and enumrate thru the colliders hit in case you may have more than one object with a collider
how can I specify what collider should the ray consider?
dividing my colliders in layers?
Well, if you want to assign the logic to the Canvas's Button, add the script with the desired method to the seriaized onClick event
Exactly
I forgot about it
You may use GetRayIntersection for a single object with layerMask parameter specified
this thing right?
should I then import the layer in the code or does the script autodetect the layer?
It doesn't
I would say, serialize the LayerMask and convert it to int in your code
Use LayerMask.NameToLayer method
I want to do this:
Item newItem = JsonConvert.DeserializeObject<Item>(result);
But Item is a MonoBehaviour, any simple workaround?
Make your own class for the data you specifically want to save
Oh, that's wrong
I have messed it up
Simply use LayerMask.value variable to get the integer from the mask
@gilded breach
How do i remove this error?
You have 2 classes called GameOverScreen in the global namespace
oh okay found it thanks
Global namespace means no namespace specified
like, should this work or I'm messing it up? It's kinda hard to understand what the layermasks need to work
Consider sending the code in a text form
that is not even correct syntax
And it's not supposed to work at all. It should throw you at least 5 errors
Consider configuring your !ide
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
β’ Visual Studio (Installed via Unity Hub)
β’ Visual Studio (Installed manually)
β’ VS Code
β’ JetBrains Rider
β’ Other/None
{
if(life <= 0)
{
this.enabled = false;
colliderKeeper.enabled = false;
range.SetActive(false);
anim.Play("Die", -1);
}
No this required for enabled
why the die anim dont play?
because you've just disabled the script playing it
how can i fix it?
Don't disable it?
and please dont just take out the enabled=false line. Think about your code
is it correct?
What is it supposed to mean?
Do you actually understand any of your code?
not much
then that is where you should start
cuz i saw that for this work range.SetActive(false); i need this public GameObject range;
Well, yeah...
but that has nothing to do with your problem
writing clean code is so hard for complex systems π£
Not if you have done any kind of data design beforehand
public GameObject H2O;
void Update()
{
if(Input.GetMouseButtonDown(1))
{
LayerMask deck = LayerMask.GetMask("Deck");
if (Physics2D.GetRayIntersection(Camera.main.ScreenPointToRay(Input.mousePosition), layerMask= deck));
{
SpawnCard();
}
}
}
void SpawnCard()
{
Instantiate(H2O, new Vector3(3f, 0f), Quaternion.identity);
}
}```
I kinda... made it work again but I don't get how the layerMask works tbh.
```Assets\Scripts\H2Odeck.cs(12,97): error CS0103: The name 'layerMask' does not exist in the current contex```
now it gives me this error but when I look on the Unity Documentation it says that it's one of the parameters I can give to the function
but that is NOT how you pass a parameter and value
how do I then?
uhh
it didn't work as I thought
now im thinking if I could lock every axis of my movement vector
when I'm running that fuction expect for my last axis
that way even if any unnecessary input is given won't do anything
is it possible to do that?
I suggest you check the documentation but as a hint a colon is involved
I am struggling to see exactly what you want as you seem to have moved the goal posts since your original question. At the end of the day input will only be processed if you process it
I have coded a slide mechanic
but even when I'm sliding
i can move as the movement function is being called
but I can't slide without it either as it multiplies with the player speed
if you want to ignore input whilst the coroutine is running just tell your input processing code that
input manager doesn't seem to have anything like that
How do I stop the canvas from appearing when i run the game?
Disable it.
Alright it was just a misunderstanding gizmos was active in the game panel 
hmm, that's the scene view
yeah i just went to the game view and saw gizmos light shade bright open
why am i getting nullreference in a line with a CompareTag?
private void OnCollisionEnter(Collision other)
{
if (other.transform.parent.CompareTag("Player"))
{
OnColliderContact();
}
}
parent is null
if you run into a null reference and you're doing multiple dot accessing operations, debug log from left to right
In this case it's not needed, neither other nor transform can be null
how can i fix it?
Hello, Why wont It wont load the game over screen. Even if i already added it the script to the canvas?
you are going to have to learn how to Debug. Add some to the script to see what is happening
it literally tells you how to fix it
do people read anymore
π
Did they read in the first place?
hi im new so sorry if my question is not ok but i dont know what to do'
can someone help me with a problem im having with stopcorutine?
i tried anything , i meen i used invoke and changed the code like 200 times π¦
what problem are you having? whats the code
did you try
Coroutine cor = StartCoroutine(myMethod());
...
StopCoroutine(cor);
?
yea ofcorse
i tried everything i found online lol
then you need to actually explain your problem and show your code
i have a power -up called "speed_pepper"
if i pick it up it will last for 10 secnds an will stop the affect
but in that time if ill pick another pepper it wont reset the timer it stiil go by the original 10 sec of the first pepper
i tried to do stopcoroutinr and tried using invoke and cancle invoke and its stil donf work
that does not explain what the problem is
is there a spesific way to send code here?
or ill just copy past it?
!code
π Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
π Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
tnks
ill post the code and write more understanable problem
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class speedpeper : MonoBehaviour
{
/////// vars ///////
private static bool is_peper_active;
void Start()
{
}
void Update()
{
peper_movement();
}
// trigger speed peper
public void OnTriggerEnter2D(Collider2D other)
{
UI_manager uI_Manager;
uI_Manager = FindObjectOfType<UI_manager>();
player player;
player = FindObjectOfType<player>();
if (other.tag == "Player")
{
if (is_peper_active == false)
{
uI_Manager.add_score();
is_peper_active = true;
player.player_speed = 9;
transform.position = new Vector2(0,800);
StartCoroutine("speed_peper_deactive");
Destroy(gameObject,80);
Debug.Log(is_peper_active);
}
else if(is_peper_active == true)
{
uI_Manager.add_score();
player.player_speed = 9;
transform.position = new Vector2(0,800);
StopCoroutine("speed_peper_deactive");
StartCoroutine("speed_peper_deactive");
Destroy(gameObject,80);
Debug.Log("it works");
}
}
else if (other.tag == "floor")
{
Destroy(gameObject);
}
}
private void peper_movement()
{
transform.Translate(Vector2.down * 3.5f * Time.deltaTime);
}
//cancel speed peper buff
private IEnumerator speed_peper_deactive()
{
player player;
player = FindObjectOfType<player>();
yield return new WaitForSecondsRealtime(10);
is_peper_active = false;
player.player_speed = 6;
}
}
'Large blocks of Code'
ill make it more spesific - i just didnt know if it all was relevnt
just post it all to a paste site
in what way is this
StopCoroutine("speed_peper_deactive");
StartCoroutine("speed_peper_deactive");
like this
Coroutine cor = StartCoroutine(myMethod());
...
StopCoroutine(cor);
It seems to be running already but the problem is that it would pause the game than rather continue its course
is it because of gameObject.SetActive(true);?
oh i didnt think that i should put it as a var just that u ment it to be a corutine
ill try it
I specifically asked if you had tried this, your answer was 'yeah of course'
and that solution is also literally in the documentation for StopCoroutine
yeah, instead of 'trying 200 code variations' try read the documentation once
i didnt find it there and in any other forum that i have serched in
and also the first forum i look at also has the same solution
you have to actually read the page, instead of just glancing at it and giving up instantly
you are going to have a very bad time if you do not take the time to read
TL;DR; apparently that means, nowadays, any sentence of longer than 3 words
guys im new to this and im stuck on a problem that i have tried to fined a solution in a lot of places before i came to this server
its not that i had this and run to this server just to find an answer , i have reed the documentation but maybe from the frustration it slipped away from seeing it (English is not my first language if u didn't noticed) don't act this way to someone who is just trying to lern
u know what ill find it by myself
tnks for the help to someone new -_-
sure maybe, but from our point of view it seems you didnt as we found the solution within 10 seconds of opening google
but it happens i guess
I gave you the correct answer in my very first post and you dismissed it without even checking, so good luck with that
i thot u ment to try using stopcoroutine..
If you do not understand someone's suggestion, ask a question about it.
i understand, but be positive especially if some beginner post a stupide question on a beginner forum
im on this problem since yesterday and ive searched a lot before i came here
but it is your responsibility, as a beginner, to look at and understand what people tell you
ok i accept it
anyway
it duos not work
i tryed to use it as a var of IEnomerator and its not working
show 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.
why would you do that when I specifically showed a varialbe oy type Coroutine?
cos i read int the article that if i used an IEnumerator ill need an IEnumerator var
i tryd what u have sent dont be mistaken
but it didnt let my start it becuse i use IEnumerator
Again, you should read the documentation
If you do not understand what the documentation is telling you, then you need to ask a question about it.
I give up, apparantly OP would rather blunder around in the dark than just implement what he has been told
can i delete unity 2022 and use only the unity 6000
You can uninstall it from the Hub if you don't need it.
Deleting shortcuts from your desktop will not do anything.
If you installed the editor manually -- without using the Hub -- then you'll need to uninstall it manually too
StartCoroutine returns a Coroutine object. This is like a ticket. You can give this ticket to StopCoroutine to stop the coroutine later.
You are also allowed to give StopCoroutine the same thing you gave to StartCoroutine.
The player is moving... alot..
no dude is just that u are being so rude, im new to this
i just started to lern and im lerning alone
im trying to learn by the thing you are sending me
i mean i read that forum and try to implement what i have reed (and don't just copy paste your answer (witch didn't work BTW i tried it when u sent it and then tried what i have sent u)
i am trying to learn but u all just make me wonna quit it
Coroutine cor = null;
public void OnTriggerEnter2D(Collider2D other)
{
UI_manager uI_Manager;
uI_Manager = FindObjectOfType<UI_manager>();
player player;
player = FindObjectOfType<player>();
if (other.tag == "Player")
{
if (is_peper_active == false)
{
uI_Manager.add_score();
is_peper_active = true;
player.player_speed = 9;
transform.position = new Vector2(0,800);
cor = StartCoroutine(speed_peper_deactive());
Destroy(gameObject,80);
Debug.Log(is_peper_active);
}
else if(is_peper_active == true)
{
uI_Manager.add_score();
player.player_speed = 9;
transform.position = new Vector2(0,800);
if (cor != null) StopCoroutine(cor);
cor = StartCoroutine(speed_peper_deactive());
Destroy(gameObject,80);
Debug.Log("it works");
}
}
else if (other.tag == "floor")
{
Destroy(gameObject);
}
}
private IEnumerator speed_peper_deactive()
{
player player;
player = FindObjectOfType<player>();
yield return new WaitForSecondsRealtime(10);
is_peper_active = false;
player.player_speed = 6;
cor = null;
}
which is EXACTLY what I showed you to do
So what?
I dont have the actually main object still when you start it auto moves idk how to make it when to create the object it auto gives it a auto script that i have prepared for it
tanks dude
im understanding that
im saying that its just don't work
i really don't know why
i tried to copy paste the code and it doesn't work
this one i mean
Show your entire script. You can share it with one of these paste sites: !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.
now who is being 'rude' in what way does just saying 'doesn't work' help either you or us?
expalain what you mean
... it just dont work
it doesn't cancel the coroutine
Hey guys! I'm trying to keep my timer object from being deleted when I swap scenes, so I tried to add it to doNotDestroyOnLoad, but I doesn't work? I'm very confused.
it's not in DoNotDestroyOnLoad
I in no way checked your logic, so I'm guessing the problem lies there. At least it is syntactically correct now
nvm, forgot to add the canvas to DNDOL aswell
you are starting an abstract coroutine and stopping Co one
"abstract coroutine"?
I mean, he passes just the "speed_peper_deactive()" into StartCoroutine while passing "co" to StopCoroutine
That is correct.
Notice that the return value of StartCoroutine is stored in the co variable.
oh, wait, missed it
this is a Coroutine object, and passing it to StopCoroutine will stop it.
The true branch does not save the result of StartCoroutine, so it is impossible to stop the coroutine you start there.
oh ok
so i can just make another var so it will check that
a wait no
Perhaps you should stop the coroutine before you even check if is_peper_active is true or false.
Also, I'm pretty sure it is not an error to pass null to StopCoroutine. It's also fine to pass a Coroutine that has finished.
but how i will check the power up is active or not?
if i cant check whitin an if statement
I didn't say to get rid of the if statement. I said to stop the coroutine before you do that check.
cute game
thank you
try adding this to the canvas
yea i understood i just dont know how it will check if its still active then
I wrote
if (cor != null) StopCoroutine(cor);
cor = StartCoroutine(speed_peper_deactive());
you wrote
if (co != null) StopCoroutine(co);
StartCoroutine(speed_peper_deactive());
didnt noticed that, ive changed it.
ive tried something like that
if (other.tag == "Player")
{
if (co != null) StopCoroutine(co);
uI_Manager.add_score();
is_peper_active = true;
player.player_speed = 9;
transform.position = new Vector2(0,800);
co = StartCoroutine("speed_peper_deactive");
Destroy(gameObject,80);
Debug.Log(is_peper_active);
}
else if (other.tag == "floor")
{
Destroy(gameObject);
}
}
its still don't work π¦
i am so confused
my player completely disappeared after i changed some sprites around
basically i minorly changed some sprites in my assets using asesprite
and now all my player sprites have gone invisible
restarted unity, cut up my sprites, but for some reason theyre still invisible
This is a coding channel, delete this and use the proper channel please
sorry