#💻┃code-beginner

1 messages · Page 404 of 1

raw token
#

There are a few means to obtain a reference to a GO by name like GameObject.Find(), but generally the preferred solution is to create a field for that game object on your script, and assign it by dragging the GO from the hierarchy to the field in the inspector

still pond
#

Or i can't refer directly to a game object?

#

Ok, thanks!

wise cipher
#

hello, does anyone know how I can fix the camera on my character without having my background completely stretched? as you see I am in isometric, I am trying to add a character in 3d but I want it to be in isometric view in my 2D decor, I searched a little on the internet I saw that it was necessary put a camera on it with a rotating parameter of X:30 Y:45, the problem is that afterwards... my background is completely disfigured and stretched lol. But my character is displayed well, it is in isometric there

short hazel
#

Rotate the background so it faces the camera

astral basin
#

whenever the autoBtn() is being run, at the second for loop, it sets all the issongsource to true instead of setting them one by one every time each audo source is done playing (the goal of the code is to play 4 audio sources one after another automatically, and possibly looped)

queen adder
#

how to make it so my tiles fill the grid

#

im a bit lost here D:

wise cipher
# short hazel Rotate the background so it faces the camera

actually it works but then it breaks my tilemap 😦 nothing is proportional anymore, it makes my brain go crazy lol, I tried to base myself on this video and do like it but I can't get the same result https://youtu.be/v4S1ClQJg2E?si=j6yqE99iALrqR84p&t=119

In this episode I added a 3D model of a character into my 2D isometric game. This process was a bit tricky but at the end everything came together nicely. I learned a lot of new things such as handling Animations in Unity (state machine), implementing a simple AI for my character and pathfinding on an isometric grid.

Support me on Patreon - ht...

▶ Play video
late burrow
#

ok so one thing i wondered about, if big blocks of ifs are bad and instead setting index of x is more optimal

#

if i have many different paths of code is it good store various functions in array and run them by index?

summer stump
swift crag
#

the PPU determines how many pixels there are per unit (hence the name)

#

the default of 100 means that a 16 pixel image winds up taking up 0.16 units in the world

short hazel
# astral basin whenever the autoBtn() is being run, at the second for loop, it sets all the iss...

It's probably because you use i in the lambda expression =>. The compiler has to do extra work in order to be able to refer to the variable from inside the lambda, this causes your issue. By the time the lambda executes, the for loop will already have finished running, so i does not contain the number you think it is.
To solve that, create a copy of that variable inside the loop and see if that fixes it:

for (int i = 0; i < 4; i++)
{
    int ii = i;
    yield return new WaitWhile(() => thing[ii].isPlaying)
    //                                     ^^ NOTICE USE OF LOCAL
}
eternal needle
queen adder
# summer stump Not a code question. But fix the ppu

yea i did, works now 😛

So then another one. In my 2d game as usual you can farm stuff and chop trees. So i would make another grid and just put it over the other one for such objects as stones, ore or trees?

or how is that done code wise

astral basin
short hazel
summer stump
queen adder
#

so i guess procedural would be good here, yea

short hazel
summer stump
queen adder
#

randomly generated would be a bonus ofc

still pond
#

Hello i have the following two pieces of code:
void Start()
{
timer = FindObjectOfType<Timer>();
scoreKeeper = FindObjectOfType<ScoreKeeper>();
}
and

scoreKeeper.IncrementSeenQuestions();

When i try to call the method "IncrementSeenQuestions" i get the error "NullReferenceException: Object reference not set to an instance of an object'

summer stump
summer stump
#

Probably scoreKeeper?

still pond
#

The error is on the line where i try to call the method

summer stump
#

Do you HAVE an object wjth ScoreKeeper in the scene?

still pond
#

Omg dumb me, i forgot to attach the script

astral basin
still pond
#

Thank you

short hazel
#

It's like a method body

astral basin
#

oh i see thank you

wooden socket
#

how do I call a function from a click? I know how to do it in the inspector but I need help with the code

wintry quarry
wooden socket
#

click a button

#

mb lol

wintry quarry
#

Buttons have an gnClick you assign in the inspector

wooden socket
#

yea ik

wintry quarry
#

assign that to the function you want to call

wooden socket
#

but all I get is this

wintry quarry
#

you need to drag a GameObject with the script attached to it into the slot

#

you dragged the script itself

#

very common mistake

astral basin
short hazel
#

That would mean isPlaying is false, so it does not wait (or maybe just a frame)

astral basin
#

in order to run autoBtn() you press a button and after you press the button you press the play button in order to run the song itself

#

oh so i should check if the button is clicked with a bool and if yes run it inside the play buton script?

#

right?

short hazel
# astral basin right?

Nah I think what's happening is that it doesn't start playing until the next frame, so if you call Play() then immediately check if it's playing it'll say that it's not.
A hack would be to wait until it's playing before waiting that it has finished

yield return new WaitUntil(() => songSource[ii].isPlaying);
yield return new WaitWhile(() => songSource[ii].isPlaying);
#

Try that

#

Or yield return null; as a replacement to the first one

astral basin
#

yeah it works thank you so muchhhh

earnest raven
#

why can i not assign the text? when i drag the text on it nothing happens

keen dew
#

Is the text element TextMeshPro or legacy text? The field is for legacy text

earnest raven
#

TextMeshPro, thanks, i'll modify the code

wintry quarry
fading seal
#

can someone help me with this error heres the code ```cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PauseMenu : MonoBehaviour
{
public GameObject pauseMenu;
public static bool isPaused;

// Start is called before the first frame update
void Start()
{
    pauseMenu.SetActive(false);
}

// Update is called once per frame
void Update()
{
    if(Input.GetKeyDown(KeyCode.Escape))
    {
        if(isPaused)
        {
            ResumeGame();
        }
        else
        {
            PauseGame();
        }
    }
}

public void PauseGame()
{
    pauseMenu.SetActive(true);
    Time.timeScale = 0f;
    isPaused = true;
}

public void ResumeGame()
{
    pauseMenu.SetActive(false);
    Time.timeScale = 1f;
    isPaused = false;
}

}```

eager elm
earnest raven
languid spire
eager elm
# fading seal ohh ok i forgot about that

keep in mind that Update() doesn't run on disabled objects. So if pauseMenu is the same gameObject as the gameObject with this script it won't work once it's disabled.

fading seal
eager elm
#

well, try it out and see

fading seal
fading seal
#

ty tho

queen adder
#

can someone tell me why stones are not generating?

eternal falconBOT
queen adder
stuck palm
#

im really not sure what could be messing up my determinism anymore

#

i've

  • got everything running on a fixed timestep
  • used seeded random functions, and save the seed for replay
queen adder
stuck palm
queen adder
#

well i mean i have now a procedural generating world
but it should be big so people can explore. Now i have created width and height of 10000
thats a giant map and takes time to load. How to fix this?

how do publishers fix this? only generate more when player is moving in that direction? and then a bit by time like minecraft? instead of generating it all?

wintry quarry
wooden socket
#

for some reason my animation plays in editor but not build

#

im so confused

fading seal
#

none of my buttons are working heres the script and inspector ```cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class PauseMenu : MonoBehaviour
{
public GameObject pauseMenu;
public static bool isPaused;

// Start is called before the first frame update
void Start()
{
    pauseMenu.SetActive(false);
}

// Update is called once per frame
void Update()
{
    if(Input.GetKeyDown(KeyCode.Escape))
    {
        if(isPaused)
        {
            ResumeGame();
        }
        else
        {
            PauseGame();
        }
    }
}

public void PauseGame()
{
    pauseMenu.SetActive(true);
    Time.timeScale = 0f;
    isPaused = true;
}

public void ResumeGame()
{
    pauseMenu.SetActive(false);
    Time.timeScale = 1f;
    isPaused = false;
}

public void GoToMenu()
{
    Time.timeScale = 1f;
    SceneManager.LoadScene("Menu");
}

public void ExitGame()
{
    Application.Quit();
}

}```

queen adder
verbal dome
wooden socket
#

its not an error in the logs

verbal dome
#

How do you know?

wooden socket
#

i think its position weird

wintry quarry
wooden socket
#

how would I even make a dev build\

verbal dome
wooden socket
#

no

#

the animation just

#

isnt showing for some reason

queen adder
#

i did 10000x10000 on height/width in unity on my procedural gen map

Now whole unity froze. any idea?

wooden socket
#

like the editor its fine

verbal dome
raw token
raw token
fading seal
#

everything shows up and the esc key works but the buttons dont

raw token
#

Oh I see. Are the buttons visually reacting to hover/click events? Have you sprinkled in some Debug.Log()s to see if the methods are getting called?

fading seal
stuck palm
#

didnt see this, will probably have a look at that

fading seal
#

ill get a screen recording and show you

wooden socket
#

damn it man why the hell does it work in editor but not build

raw token
fading seal
queen adder
#

this is just for testing, but why is it blurry?

fading seal
still pond
#

I get the following error: ObjectDisposedException: SerializedProperty questions.Array.data[4] has disappeared! Can someone explain please what is this error? Because i expected to get a NullReference error since it seems like im trying to acces an object that doesn't exist

stuck palm
wintry quarry
#

And the full stack trace?

solid mango
raw token
# fading seal the "rawimage" is basically the camera since i technically got rid of it to make...

For giggles, you might try moving that canvas up in the hierarchy before the pause menu canvas...

Unity provides two methods for handling input - the older Input Manager, where you generally just ask it for the current state of an input device like Input.GetAxis("horizontal"), and the newer Input System in which you generally configure "InputActions" and have a number of different options to hook them up to your code... Edit > Project Settings > Player > Other Settings should have an "Active Input Handling" dropdown to select which one you're using

queen adder
still pond
still pond
fading seal
#

i cant move now

raw token
eager elm
solid mango
# still pond

use online paste bin so i can see full script and can you tell me where the error coming from

fading seal
fading seal
still pond
raw token
fading seal
eager elm
# fading seal and when i disabled it nothing changed

Select the EventSystem in your hierarchy, in the inspector at the top right click the 3 dots and switch to "Debug Mode". Now Your Standalone Input Module should have a field called "Current Focused Game Object". Hover over the buttons and see if it changes to something that is not 'None'

fading seal
eager elm
fading seal
eager elm
#

does it have a component called "Standalone Input Module"?

eager elm
#

And you see the "Current Focused Game Object" field? If yes, when you hover over an object it should be set to that, like so:

olive galleon
#

How should I handle SoundEffects for my game? Make an event that a SoundFX script listens to and plays when event fires off?

eager elm
# fading seal it still says none

mhh, you might have "bugged" your game by doing the changes to your camera, since mouse events rely on the camera to calculate the position.

earnest raven
#

how can i add audio?

#

background music

earnest raven
#

thanks

eager elm
fading seal
eager elm
# fading seal how could you help tho

You have to figure it out yourself. Try Making a new Scene with nothing but a button and see it if works, then one by one add stuff from your main scene until it no longer works.

fading seal
earnest raven
#

i assigned the sound but it says i didn't

queen adder
#

any idea how to stop him rotating when hitting something? LMAO

earnest raven
#

lock rotation in rigidbody

queen adder
#

i could make him static i guess, but i feel like this will block features later on

#

oh

earnest raven
#

(if you have it)

#

i dunno i just started unity

queen adder
#

well what option lol

earnest raven
#

constraints

queen adder
#

yup that worked, freezed Z, ty 😄

earnest raven
#

np

queen adder
#

okay so now i want to give the stones a collider aswell that i can adjust
the problem is just: is it bad for performance when giving each tile a collider or is there a performance issue later on?

otherwise i could just give the stone texture a collider and rigidbody

earnest raven
#

so you want an exact hitbox?

queen adder
#

yea

#

on the stone object

#

and trees etc

earnest raven
#

man i dunno i use a box collider

#

i just started

late burrow
#

why classes can have list[i].int++ edited directly but structs cant

brazen crater
#

Hello, I am new to C# and was just wondering if there is a built in way to generate a random integer between a certain range?

verbal dome
#

UnityEngine.Random to be exact

#

There is also System.Random but it works a bit differently (instance instesd of static)

queen adder
#

where can i ask for graphic stuff?
Since this is messed up at import for some reason (hands and foot)

brazen crater
#

Been trying to steer clear of tutorials, and couldn't find anything on google, or I just wasn't searching the right things.

atomic yew
#

Hello everyone, I have a problem. While testing my game in the Unity editor, my recording system in json format works very well, but when I install it on my Android mobile phone, it does not save some places. For example, while the transform values ​​of a character are recorded properly in one script, the animals I catch in a different script are not recorded. How can I solve this problem?

iron wing
#

Hi, I'm using Mirror's networking solution in my project. Does anyone know what these errors are at all about? They show up everytime I launch my game. I believe they've only showed up after changing my scene via LoadScene()

atomic yew
verbal dome
earnest raven
#

how can i make things invisible during gameplay?

wintry quarry
earnest raven
#

it's like telling a baby to jump

wintry quarry
earnest raven
#

cool

wintry quarry
#

Once you know the basics of referencing stuff in Unity you can use it for everything

queen adder
#

okay so i have a collider for the whole second layer at all objects. So when the player runs at a stone, he will collide. But the collider is of course not custom sized for each object. Stones need another collider size than trees and so on.

How can i now assign a box collider/custom collider to just the stone tiles within this tilemap?

wintry quarry
queen adder
#

thats what i looks right now

rich adder
still pond
#

Hello, here i have a game manager script. I get the error NullReferenceException: Object reference not set to an instance of an object
EndScript.ShowFinalScore () (at Assets/Scripts/EndScreen.cs:18)
GameManager.Update () (at Assets/Scripts/GameManager.cs:23)

Here is the GameManager script:

"'cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class GameManager : MonoBehaviour
{
Quiz quiz;
EndScript endScreen;
void Start()
{
quiz = FindObjectOfType<Quiz>();
endScreen = FindObjectOfType<EndScript>();

    quiz.gameObject.SetActive(true);
    endScreen.gameObject.SetActive(false);
}

void Update()
{
    if(quiz.isComplete == true)
    {
        quiz.gameObject.SetActive(false);
        endScreen.gameObject.SetActive(true);
        endScreen.ShowFinalScore();
    }
}

public void OnReplayLevel()
{
    SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}

}
"'

And here is the function ShowFInalScore:

public void ShowFinalScore()
{
finalScoreText.text = "Congrats! \n You got a score of "
+ scoreKeeper.CalculateScore() + "%";
}

I have to mention that i assured that every SerializeField is properly assigned

eternal falconBOT
rich adder
#

reference on line 18 on EndScreen.cs is null

still pond
rich adder
still pond
#

How do i post it properly

rich adder
#

if thats whats on line 18 then endScreen is null

rich adder
still pond
#

I tried to add cs in my message but it didnt work

rich adder
still pond
#

is it good like this?

rich adder
#

yes

#

but this is not the script the error throws on

still pond
#

oh ok

still pond
#

i think i know what it is, thnaks

rich adder
#

if endScreen is ony line 18 then its endScreen is null

#

but thats not in the other script is it

still pond
#

its in this script

#

wait

rich adder
#

the null ref is coming from EndScreen line 18

#

the second line tells you wich script started the call

still pond
#

yes its the finalscore

rich adder
#

finalScoreText is null

#

did you assign it in the inspector?

still pond
#

yes

rich adder
#

its possible you might have a copy of script on another object, with it unassigned

still pond
#

Ok, i will track it down, thanks!

rich adder
still pond
#

it's only assigned to one object

rich adder
# still pond it's only assigned to one object

try log, you can click it after it prints

public void ShowFinalScore()
    {
Debug.Log($"Changing score text on {finalScoreText} using {scoreKeeper}", this);
        finalScoreText.text = $"Congrats! \n You got a score of {scoreKeeper.CalculateScore}%"
    }```
still pond
rich adder
# still pond

where did you put log, copy mine. then click on the log

outer coral
rich adder
outer coral
#

Ahh thats useful thanks

still pond
rich adder
#

click the first one

#

which object it brings you to

still pond
#

to the endscreen

#

second debug still at the endscreen

rich adder
#

also
when do you set quiz.isComplete = true

still pond
rich adder
#

anyway it looks like the one missing here is scoreKeeper

#

you can see "using ___" is blank on the first line debug

still pond
#

But i do FIndObjectOFType<ScoreKeeper>

rich adder
#

and you have one in the scene ?

#

also try moving it to void Awake()

#

at least by the time you call method on scoreKeeper its not there

still pond
rich adder
#

are you somehow calling ShowFinalScore before Start ?

#

I think Update can do that sometimes before start

still pond
#

I only call ShowFInalScore thru the gamemanager screen

#

script

rich adder
#

yes I asked where you set quiz.isComplete to true

still pond
#

Well, i have a timer, when the timer runs down on the last question thats when i make quiziscomplete to true

#

but i guess i can debug.log quiz is complete

still pond
#

Yes, the problem was with when I set quiz.iscomplete to true

#

I solved this

#

Thank you so much!

rich adder
#

the power of debugging!

still pond
#

Yea :))

queen adder
#

Assets\Scripts\drops\BreakableTile.cs(9,13): error CS0246: The type or namespace name 'Dictionary<,>' could not be found (are you missing a using directive or an assembly reference?)

#

why?

raw token
#

@queen adder you are missing using System.Collections.Generic; - if your IDE is configured, it should be annotating Dictionary with an error, and providing an option to import relevant namespaces

sage abyss
#

Hello guys, I'm very new to Unity. So how can I fix this?

rich adder
#

you must call it on an instance of Transform

#

unity has a nice property of transform in MonoBehaviour script, referring to this object's transform
(capitalization matters)

astral basin
#

this code is ment to wait until one song is finished and then it passes to the next song automatically, and it works, however when you pause the song while its playing the code thinks that its done so it skips to the next one and when you resume its a different song, i tried to make a bool in order to check when the song is paused but had no luck. any other suggestions?

astral basin
rich adder
#

you can see autoBtn is inside annother method

rich adder
astral basin
#

no

polar acorn
astral basin
#

ok wait

polar acorn
#

You've got a compile error

rich adder
#

You cannot use access modifiers on nested methods

#

since they are only local

wanton kraken
#

Does anyone know why 'velocity' isn't being filled in my intellisence? I can't figure this out for the life of me, and it's hard to learn when VSC isn't working right

rich adder
sage abyss
rich adder
#

instead of doing GetComponent<Transform>()

wanton kraken
rich adder
#

!vscode

eternal falconBOT
#
Visual Studio Code guide

If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:

https://on.unity.com/vscode

rich adder
#

make sure you check the Package Manager stuff

#

remove the Visual Studio Code Editor package, make sure the Visual Studio Editor one is Update to 2.0.20+

wanton kraken
#

i have vscode! as well as the plugin loaded

rich adder
#

i know you got vscode

#

click the link lol

wanton kraken
#

will do. sorry, new to all this

astral basin
rich adder
wanton kraken
#

got it. thank you

rich adder
#

or added ?

wanton kraken
rich adder
wanton kraken
#

yep

rich adder
#

and you removed the old one?

#

the Visual Studio Code Editor one

wanton kraken
#

yep

rich adder
wanton kraken
#

sure, one moment

raw token
#

You want Edit > Preferences, not Project Settings

wanton kraken
#

as in at the top menu on mac?

#

file - edit - assets, and the like?

raw token
#

I'm not sure, but I would assume so. It's here on Windows:

wanton kraken
#

it won't show up for me on mac, that's the issue

rich adder
rich adder
raw token
#

What a strange thing to vary based on platform 🤔

rich adder
#

haha yeah Project Settings is still under "edit"

#

!code

eternal falconBOT
astral basin
rich adder
astral basin
#

alr ty

wanton kraken
rich adder
#

its because you're not using your isPaused condition

astral basin
rich adder
astral basin
#

because it didnt work

rich adder
#

isPlaying is a bit tooo broad

#

a bool would help

astral basin
#

yes

#

ill redo it and send again

rich adder
#

show how you tried to use the bool

astral basin
#

and then tell me what i did wrong

rich adder
#

sure. you can also check things like the cliplength vs how far in the clip you are playing rn

keen dew
#

tbf the Mac convention is that Preferences is in the [app name] menu. That's where it is in all apps. It's not something that Unity came up with

rich adder
#

yeah very true. I commonly look there for app preferences in general

#

the shortcut key is usually the same too command + ,

swift crag
#

in fact, that's the standard shortcut for user preferences

#

it always works. it's very nice

astral basin
#

this code is ment to wait until one song is finished and then it passes to the next song automatically, and it works, however when you pause the song while its playing the code thinks that its done so it skips to the next one and when you resume its a different song, i tried to make a bool in order to check when the song is paused but had no luck. any other suggestions? https://hastebin.com/share/ideduboyez.csharp ( no error in console )

raw token
# rich adder

The more I think about it, the more logical it seems to group conventional application stuff like that. I find myself mildly disturbed by this touch of Mac envy 👀

rich adder
swift crag
raw token
astral basin
raw token
rich adder
astral basin
#

approach

#

oh equals

rich adder
#

don't == floats

astral basin
rich adder
#

yeah always use those with floats

willow scroll
rich adder
#

thats also an option

astral basin
willow scroll
rich adder
astral basin
#

yield return new WaitUntil(() => songsource[ii].time == songsource[ii].clip.length);

#

this is the line

#

like where do i insert it

rich adder
#

is just a regular bool

willow scroll
rich adder
#

the return is result of , if they are approx the same number

#

though for a clip/time I would use if(as.time < clip.length) // not done with song
(don't copy exact just example)

willow scroll
#

Unity has small mistakes when calculating floats, so it's rarely that 2 floats can be equal, when compared with the == operator

astral basin
#

so in the big scheme of the things of stuff

#

does it really matter

#

approx or bigger

#

both reliable right

rich adder
#

if you need more "precise" check approx is better

astral basin
#

meh

rich adder
#

in most cases < and > work perfectly fine

willow scroll
#

When willing to use the >= operator, consider

if (f1 > f2 || Mathf.Approximately(f1, f2))
#

The same goes for <=

#

You can also create your own methods

MathExtension.ApproximatelyGreater(float, float)

MathExtension.ApproximatelySmaller(float, float)
astral basin
#

nah those stuff are way too smart for me for now but thanks ill remember that if i ever get good at ts

#

it workssss

#

thank you very much guys

#

all of you

cosmic dagger
#

if you want approximation, just check if the (absolute) difference is less than a tolerance value. that way, you can determine the range of error . . .

willow scroll
# astral basin nah those stuff are way too smart for me for now but thanks ill remember that if...

You can put this somewhere in your project if you want

namespace UnityEngine
{
    public static class MathExtension
    {
        #region Approximately

        public static bool Approximately(this float f1, float f2) =>
            Mathf.Approximately(f1, f2);

        public static bool ApproximatelyGreater(this float f1, float f2) =>
            f1 > f2 || f1.Approximately(f2);

        public static bool ApproximatelySmaller(this float f1, float f2) =>
            f1 < f2 || f1.Approximately(f2);

        #endregion
    }
}
rich adder
willow scroll
cosmic dagger
rich adder
#

ahhh

cosmic dagger
#

basically, margin is the error of precision . . .

rich adder
#

I see the original is return Mathf.Abs(b - a) < Mathf.Max(1E-06f * Mathf.Max(Mathf.Abs(a), Mathf.Abs(b)), Mathf.Epsilon * 8f);

willow scroll
rich adder
#

yeah thats what source does

cosmic dagger
#

Mathf.Approximately uses Epsilon . . .

rich adder
#

you can just change 1E-06f to increase the margin

willow scroll
astral basin
#

yo guys need yall again

#

it doesnt print done waiting

cosmic dagger
astral basin
#

i have a button that skips 5 seconds ahead of the sound clip thing if its relevant

raw token
astral basin
#

oh ye

rich adder
astral basin
#

will => fix everything

willow scroll
# astral basin

Not sure how the current time of the clip can be greater than its full length

#

It can just be equal when finished

astral basin
#

shoulda moved this to code-advanced ngl

#

alrrr it workss

#

thanks once again

remote osprey
#
    private IEnumerator waitForClickPress()
    {
        bool done = false;
        while (!done) 
        {
            if (Input.click)
            {
                done = true;
            }
            yield return null;
        }

    }

How can I check if a click event happened?

rich adder
remote osprey
#

Cool

rich adder
#

actually not even needed the extra alloc

#

isnt what u have already working ?

#

Input.click is nonsense though

remote osprey
#

Yes

#

it's gibberish

#

That's what I want to know

rich adder
#

so put the correct one

remote osprey
#

Which one

#

thats my question

rich adder
#

oh so google "Unity How to Detect Mouse Click"

remote osprey
#

Then how do i make sure The mouse has been clicked after a starting moment/Event?

#
void Update()
{
    if(Input.GetMouseButtonDown(0))
    {
        clickMouseButtonEvent = true;
    }

}
#

I did this but I'm not sure it's concurrency proof

#

Oh wait, I think I just gotta set clickMouseButtonEvent to false right after the event occurs

queen adder
#

Are the links pinned the best way for me to start to learn scripting

dusty shell
#

My player sprite looks fine in scene view but is all pixelated in game mode, any idea why?

frosty hound
#

Make sure the slider at the top of your game view is all the way to the left

crimson folio
#

Hello, I have a question. I have a list that conains elements that are null. When I try to change them I get a null reference exception. Is this normal behaviour of unity?

eternal needle
keen pecan
#

Does anyone know why my rigidbody addforce wouldnt work if I collide straight on but does at an angle?

crimson folio
#

Thing is I want to keep an index of gameobjects (transforms actually) and at some point I set some empty indexed to null

#

like
List<Transform> Transforms = new List<Transform>();
Transforms.Add(null);

#

that is not a problem at this point but when I try to
Transforms[0] = gameObject.transform;
I get a null exception

#

I can post the full code

rich adder
crimson folio
#

Ok I get it it was calling the code before list was set up at the awake I belive

#

Thanks you for your help !

wanton kraken
#

animator.SetFloat("Speed") = CatBody.GetComponent.velocity.x;

#

Why's this invalid? I'm trying to set an animation parameter to the object's current velocity

slender nymph
#

why would that be valid? you cannot assign to the return value of a method. look at the docs for the Animator.SetFloat method

wanton kraken
#

mkay, will do

swift crag
#

there are...a lot of problems with this

wanton kraken
#

yeah, i'm not very good at coding. quite new too

slender nymph
#

start with the beginner c# courses pinned in this channel

wanton kraken
#

i've got the basics, no worries

swift crag
#

with all due respect

wanton kraken
#

just confused with this one part

swift crag
#

no you do not

slender nymph
swift crag
#

this line is really wrong

wanton kraken
#

i'm well aware lmao

#

it needs to be (id, value)

#

should i attach the current speed to a variable and then use that in place of the value?

#

"public void SetFloat(string name, float value);"

swift crag
#

that is the signature of Animator.SetFloat, yes

#

you need to give it a string and a float

rich adder
#

CatBody.GetComponent.velocity.x; Certainly not grabbing it this way lol

wanton kraken
#

the string that i'm naming is the string of the animation parameter, isn't it

wanton kraken
swift crag
#

It's the name of the animator parameter.

#

but yes

rich adder
wanton kraken
#

maybe i'm confused. i thought the function of Animator.SetFloat is to name an animation parameter and then give it a float value

wanton kraken
swift crag
#

The float parameter is identified by the string.

swift crag
wanton kraken
#

i see

#

so i'm trying to update an animation parameter with the current speed of my game object. how should i go about doing that?

wanton kraken
#

i was going to have it update it each frame with said command

frosty hound
#

Pass it in as an argument

swift crag
#

i would start by adding a field to your class that holds a Rigidbody

#

e.g.

#
public Rigidbody rb;
#

Drag the Rigidbody component into this field.

wanton kraken
#

i've got one, it's CatBody

#

i already coded it to move with inputs and all that

swift crag
#

what is the type of the CatBody field?

wanton kraken
#

you mean in-engine?

swift crag
#

I mean in your script.

#

You declared a field named CatBody.

#

What is its type?

wanton kraken
#

public Rigidbody2D CatBody;

swift crag
#

Okay, so just do CatBody.velocity.x .

#

You don't need to use GetComponent here. You already have the component.

wanton kraken
#

yeah, i got rid of that a bit ago. however, SetFloat is underscored with red

swift crag
#

GetComponent<Rigidbody2D>() would be necessary if you didn't already have a reference to that component

wintry quarry
#

Components are the big boxes in the inspector window

wanton kraken
#

"no overload for method"

swift crag
wintry quarry
wanton kraken
#

will do. please don't thrash my sphagetti code

swift crag
#

animator.SetFloat("Speed")

#

You are invoking the method with one argument.

#

It wants two arguments.

#

1 is not 2

wintry quarry
swift crag
#

you are then trying to assign CatBody.velocity.x to the return value from the method

wintry quarry
#

you don't pass parameters with =

swift crag
#

the method returns void so this is especially bogus

swift crag
#

this is Very Wrong(tm)

wanton kraken
#

i have a basic understanding of coding, enough that i was able to code the thing to move myself. i'm still becoming aquianted with C#, i know i'm far from a software engineer

frosty hound
# wanton kraken

Literally look at the link I sent to see how ot use the function. You don't need to guess.

wanton kraken
#

so i need to preface it with public void, rather then "animator."?

swift crag
#

no

#

that is even more wrong

wanton kraken
#

bear with me guys. there's a learning curve to this stuff, i learn by doing it

frosty hound
wintry quarry
#

Looking at examples is better than guessing

wanton kraken
#

i am looking at it, no worries

#

in the documentation it's shown as "public void SetFloat(string name, float value);"

wintry quarry
#

but look at the EXAMPLE

#

there is example code when you scroll down

wanton kraken
#

ohh, i see. i'll give that a try

wintry quarry
#

The signature does tell you how to use it exactly though

ionic zephyr
#

what does this mean?

#

I cant find what it is

rich adder
rich adder
#

if its UnityEditor could be something just went wrong for a second within tabs or separate window

frosty hound
#

If it's an editor bug, then usually yes

ionic zephyr
#

It has to do with this code

rich adder
#

could even be a bad asset

ionic zephyr
#

with the _itemsInTable.Clear() method

rich adder
#

this would be something that would be inspector or something on the gui

#

did you restart unity?

ionic zephyr
#

yeah

ionic zephyr
cosmic dagger
#

you're removing or deleting an instance somewhere . . .

ionic zephyr
cosmic dagger
#

did you comment out the entire method or just the Clear line?

ionic zephyr
#

just the Clear line

cosmic dagger
#

_itemsInTable is your inventory?

ionic zephyr
#

its the items in the crafting station

cosmic dagger
#

are those items instances that are created/instantiated or prefabs?

ionic zephyr
#

it is an array of a class called ItemAmount

cosmic dagger
#

you mean a List<T>? array doesn't have the Clear method . . .

ionic zephyr
#

yeah sorry

cosmic dagger
#

hmmm, you don't have a custom inspector for this, do you?

ionic zephyr
#

it seems that the problem is that I have to minimize the _itemsInInventory Serialized list

rich adder
#

could be a bug

ionic zephyr
#

and now the error doesn´t occur

ionic zephyr
cosmic dagger
#

it's a problem when the size of the list is changed . . .

cosmic dagger
ionic zephyr
#

so it is an editor problem

cosmic dagger
#

are there usually a lot of items in the list?

ionic zephyr
cosmic dagger
#

try creating a new list instead of clearing it. see if happens . . .

ionic zephyr
#

This error occured with 3 items in the list

ionic zephyr
cosmic dagger
#

yeah . . .

ionic zephyr
#

Same problem

ionic zephyr
#

anyway, thanks a lot for your help

cosmic dagger
#

the other option is using an array with a fixed-size. if you know the max amount of items needed to craft anything, use that as the size. then you create a method that manually nullifies each element . . .

tulip parrot
#

Hi, i'm beginner and i try to implement perlin noise but i have some problems

queen adder
#

i used a gameobjects and put a worldgeneration script on it
procedural generating chunks when player moves to edges (well with a bit distance so it does not look ugly)

but how to center it

#

as you see in the preview, its more "top-righted" lol

#

fixed it but its not equally

#

bottom left is missing LOL

dark sluice
#

(2D Game) im having trouble with parent/child objects atm, i have a rigidbody attached to an object (a circle) that just rolls done a hill, i want to set a child to it that doesnt actually "roll" but still follows the parent, anyone know how i can achieve this?

true garnet
#

guys i made a simpy script for 2d car movement... but i have issues with basically infinite acceleration speed

queen adder
#

so im a beginner, learning fundamentals. I want a procedural generation for my world and now seeing that with hard working, good descriptions and some time chatGPT gave me 400 lines of code for just 3 blocks, patches, generation, trees and stone... i could never write that within next time by myself. Never ever lol. I can maybe try to read and understand, but thats it and probably adjust a bit.

Should i stop doing that?

teal viper
teal viper
queen adder
#

well i could try to do that, but yea...

#

lets see

shell herald
#

i have 2 objects in my scene with a PlayerInput component. how can i do FindObjectsofType<PlayerInput> and only get the one that i want?

eternal needle
shell herald
#

thats not possible bc the code is on a prefab

eternal needle
shell herald
#

hmmm, maybe that ll work

queen adder
#

well i could define the public classes but i wouldnt even have an idea of how to code/write the tilemap generation around the player lol

slender nymph
#

that's the point of learning. don't just give up on attempting to learn because you found a tool that approximates intermediate knowledge

queen adder
#

but whom even to ask if chatgpt is bad xd

#

like who would teach me now procedural gen

slender nymph
#

start by worrying about understanding the fundamentals. then when you actually understand that you can start learning more interesting topics. you'll also actually have a better chance at actually understanding the learning resources available like the documentation

queen adder
south hollow
#

I'm very new to programming, and am currently following a unity tutorial for making a platformer that tells me to use "Vector3.one" when the character moves. Is there any way to set the scale to 2 on all axes instead of one?

slender nymph
#

multiply Vector3.one by 2 or create a new Vector3 with 2 on every axis

south hollow
#

thank you!

teal viper
queen adder
teal viper
#

The specific implementation might be specific to your specific case, but with experience you'll find out that it's probably very similar to what other people do with slight variation and different names.

#

If you're doing procedural generation, there are plenty of games and tutorials to reference. Take minecraft for example.

normal thicket
#

please help i can't find loadnextlevel() and I also did everything like create a event and my script is also correct . I Followed the brackeys tutotial

#

wait

queen adder
#

i mean i can understand what steps are used to make whatever
But translating it into code is hte harder part

like i know it uses chunks, i could define an int for chunks
i know it generates more chunks when the player gets to the edge/into the direction, could define an int for this aswell

But then how to actually generate more or let a tile be in a chunk etc. thats the hard part 😦

normal thicket
teal viper
# normal thicket

You should configure your !ide first. This is not valid code.
Also, double check with the tutorial. There's no way this code is the same as in the tutorial.

eternal falconBOT
normal thicket
teal viper
teal viper
normal thicket
#

Let's make a way to reach new levels!

● Download the Project Files: http://devassets.com/assets/how-to-make-a-video-game/

❤️ Donate: https://www.paypal.com/donate/?hosted_button_id=VCMM2PLRRX8GU

····················································································

This video is part of a mini-series on making your first game i...

▶ Play video
#

watch from 8:33

teal viper
normal thicket
#

ohh

teal viper
#

Or a few steps back:

normal thicket
teal viper
#

This is valid, but it's not the same as your code

normal thicket
#

thanks

teal viper
#

Pay more attention

normal thicket
queen adder
teal viper
shell herald
#

i might have overcomplicated my problem. is there a way to enable/disable only one Input action map in code? i dont want my player to use any input exept the pause action map when the game is paused

fringe plover
#

Is it good idea to change Scriptable Objects at runtime?
I know that sometimes yes, sometimes no, but rn idk.
I made SO for characters, and i wamted to do skins for them, can i add skins in SO trough script when game init? and dont touch it? Until pkayer relaunch game ofc.

#

like, having Dictionary<string, SkinClass> in SO

teal viper
fringe plover
#

like, when i create character, i get data from SO, not just an script

teal viper
fringe plover
#

Maybe when creating character, ask SkinManager for prefab instead of getting it from SO?

#

I still didnt started making skin system

craggy coyote
#

Hello, I am working on 2D game. I got some enemies and a player. I wrote a script to make the enemies follow the player, to make the player take damage and to display the health level in a health bar. But the enemies can't find the player Health script when they collide with the player. (I am instantiating the enemies when the game starts.) Can someone help pls?
Scripts,
Health Script: https://pastecode.io/s/kahq3pgi (attched to the player)
Damage Script: https://pastecode.io/s/gx2ftpmy (attched to the enemy asset)
Enemy Spawner Script: https://pastecode.io/s/4zz4c47r (attached to an empty game object)

teal viper
fringe plover
#

but i also dont want to flood editor with bunch of lists, so, id rather do everything in code

teal viper
teal viper
fringe plover
#

oh... i think i get it, then i mostly likely do like you said, make an skin manager to store everything, thanks for helping.

fringe plover
craggy coyote
#

but it doesn't effect the task I am tring to do right?

teal viper
#

I'd avoid doing that. It's what we call an inappropriate use case for singletons

signal tide
#

In my unity multiplayer project, I have character animations which work fine. But when I disable my character's body for my local player, everything works except I can't see the animation of the enemy player, it just slides around.
(Using photon and for disabling the character I made a public game object then referenced my character there)

summer stump
fringe plover
summer stump
fringe plover
#

Why?

slender nymph
#

what if you wanted two things to have health

summer stump
#

Why force an inappropriate use of static when it is unnecessary. It constrains you and often will cause worse issues down the line if you want to expand your code

shell herald
#

i am trying to disable just one action map, but now i dont even get an error in the unity console, it just crashes

fringe plover
#
  • im not doing multiplayer game
#

i used to have and script called "Core" that have references and methods related to all important stuff like game Saving and etc stuff, it has Static Instance. Is that bad?

summer stump
#

Well, something like a SaveManager DOES make sense as a singleton
Or even just a static class

slender nymph
fringe plover
slender nymph
#

you don't need a singleton for an object to be available across scenes

fringe plover
#

i kinda know

craggy coyote
summer stump
fringe plover
#

but is it better to use FindObjectOfTime?

fringe plover
#

why do i need that for game with 2 scenes

summer stump
summer stump
teal viper
fringe plover
#

i DO keep data in memory, in script that move between scenes

teal viper
#

Or even worse, your project becomes so messed up, that you can't continue without rewriting a big chunk of it. Simply because you chose the easy road.

summer stump
fringe plover
summer stump
teal viper
fringe plover
slender nymph
craggy coyote
#

Can anyone tell me how to access a script in another game object without accessing it using a public variable?

summer stump
signal tide
teal viper
signal tide
craggy coyote
fringe plover
#

alr, ill try to use Static Instance less..

summer stump
teal viper
summer stump
summer stump
craggy coyote
#

yes. I do.

summer stump
#

The goal is to find where the issue is.
Is OnCollisionEnter called? Is the tag on the object it is called for?

teal viper
eternal falconBOT
teal viper
craggy coyote
#

sory. my bad.

magic panther
#

What the function here is supposed to do is to recognize if any pieces are a different group than the rest. If there are any, we delete the current piece that's executing the function, and just before that we create a new piece for each group recognized. Problem is Unity crashes when roomManager runs the function.

SplitHandler function -> https://gdl.space/sazefuvero.cs (I asked gpt for comments to clarify what's going on, just in case)
Entire Piece class -> https://gdl.space/oxivikegam.cs
Entire RoomManager class -> https://gdl.space/xekefuhobi.cs

magic panther
slender nymph
#

crashed as in closed to desktop. or do you mean the editor froze

magic panther
magic panther
#

I'd check the console but nothing logs since it crashes immediatelly

slender nymph
#

that would be the editor freezing. which means you have an infinite loop somewhere in your code preventing the frame from ever ending

craggy coyote
magic panther
slender nymph
#

attach the debugger, enter play mode and cause the code to enter its infinite loop, then break all using the debugger and you'll be able to inspect what the main thread is doing

magic panther
#

wdym attach the debugger

slender nymph
magic panther
#

idk what attach means in this case

slender nymph
#

then you didn't bother clicking the link i sent so i'm not going to help you further

magic panther
#

I was typing before I clicked it 🧌

#

mine looks different tho, is this it?

craggy coyote
#

@slender nymph ||Kinematic Rigidbody Body Type set to Kinematic. Is Trigger is off.|| so this means if my rigidbody is keynematic the collider is off?

slender nymph
#

no

summer stump
#

It does not mean tbat.

#

However, with a kinematic rb, OnCollisionEnter will not be sent, unless the OTHER object has a dynamic rigidbody

slender nymph
magic panther
summer stump
magic panther
#

says attach but looks different from the example, is this what was supposed to happen?

magic panther
#

so now if there's an infinite loop we'll still be able to see it?

#

so now break all as boxfriend said

magic panther
#

I get this

#

after clicking view a doohickey appears on the bottom.

#

what do I do next

#

this isn't helping

#

what do I do with this

magic panther
slender nymph
# shell herald anyone?

what do you mean it crashes? is the editor freezing, is it crashing to desktop? or (more likely) is there an error in the console causing play mode to pause?

shell herald
slender nymph
#

so play mode is being paused?

shell herald
#

yes

teal viper
slender nymph
magic panther
#

yes, one second

#

if you need me to move right just say

shell herald
slender nymph
#

now just to be clear, i am referring to the pause of play mode, and not an in-game pause functionality. but you are disabling your inputs there

teal viper
shell herald
slender nymph
#

cause this to happen again then screenshot the entire unity window with both the game view and console windows visible before you unpause it

magic panther
shell herald
#

now i restarted my project and am now getting an error but its about baked global illumination, though i have no baking enabled at all

teal viper
slender nymph
shell herald
#

i cant anymore, now i just get this error

magic panther
#

that means something has the new created fragment in it's group

teal viper
eternal falconBOT
#
📝 Logs

Documentation

Editor logs

Windows: %LOCALAPPDATA%\Unity\Editor\Editor.log
MacOS: ~/Library/Logs/Unity/Editor.log
Linux: ~/.config/unity3d/Editor.log

Unity Hub

Windows: %UserProfile%\AppData\Roaming\UnityHub\logs
Mac: ~/Library/Application support/UnityHub/logs
Linux: ~/.config/UnityHub/logs

magic panther
#

I opened the file. What should I look for?

teal viper
#

The last logs and wether there are any errors.

#

Also, try commenting out the code that you added last and see if that fixes the freeze.

magic panther
teal viper
gaunt ice
#

crash (closed by your os) is not freeze (not responding)

magic panther
#

this is the bottom of the file

magic panther
gaunt ice
#

your case is more like freeze (you close it by task manager)

magic panther
#

exactly

#

I'll try to comment out last added parts

teal viper
magic panther
#

This is what I commented out. It's not freezing, but now it's not even breaking the walls, which is strange. I see only the regular fragments in the hierarchy and there are no other pieces in the room (not even clones created by that function)

#

I fixed the not breaking walls part by commenting out this line also

#

now hte SPlitHandler thing just logs all groups found within a piece and the group's fragments

shell herald
#

the error in the play mode seemed to be a weird unity bug where it wants me to bake global illumination even though all my lights are realtime, i somehow resolved that and now playmode works, however now i cant access my pause menu, is there any issues here?

slender nymph
#

what do you mean by you "can't access" your pause menu?

teal viper
shell herald
#

like the pause input doesnt register

slender nymph
#

am i supposed to know what input you are referring to?

shell herald
#

its this input, it worked before i added the first if statement in SetPausedStatus

magic panther
slender nymph
shell herald
#

wdym? isnt it enabled from the start?

slender nymph
#

that depends entirely on how you are using that input

teal viper
magic panther
shell herald
#

the only time i use it in a script is in this one, i just need it to access the pause menu while being able to disable the player map

magic panther
teal viper
gaunt ice
#

i dont see anything special in the Awake() of class Piece....

magic panther
teal viper
#

It doesn't have to be in awake. If the issue is due to infinite object instantiation, it could be in wherever.

magic panther
#

I'm backtracking what it could be

teal viper
magic panther
#

should I keep that instantiation part commented before I run this?

teal viper
#

No. Keep it in the state where it freezes

#

You can then look at the log file.

#

Another thing you can try is placing a breakpoint in the RoomManager LateUpdate after the freeze

magic panther
#

now something different happened

#

I heard the wall breaking noise, flash and saw the aprticles play like 30 times in one second before unity froze

#

(still bottom of the file)

teal viper
#

I don't see you printing what I suggested

magic panther
#

wait

magic panther
#

just got so laggy it's at like 0.01 FPS

teal viper
magic panther
#

ok

teal viper
dusty shell
#

my player sprite looks normal in scene view but it all choppy in game view, any idea why?

magic panther
teal viper
# magic panther

Just to be safe, I'd also add the current object name to the log.

magic panther
magic panther
teal viper
teal viper
magic panther
#

again, heard a bunch of noises and then unity froze

#

you meant unity, right?

#

I have to restart it now, it froze completely once again

#

damn why is this so problematic

#

wait no

#

it's just ultralagged

#

but I can't interact with anything in unity now

teal viper
gaunt ice
#

how many pieces and fragments in your world

magic panther
#

doc again

#

there's like 100 fragments

#

it seems

#

almost 100

fickle plume
#

@magic panther Create a thread, please.

magic panther
#

no problem mate

#

Piece splitting problem

topaz fractal
#

why doesnt my code allow me to move at crouchspeed while in crouch state

#

but it allows me to move at sprintspeed in sprint state?

slender nymph
#
  1. large blocks of !code should be posted using a bin site 👇
  2. if you are grounded and not sprinting your move speed is going to be assigned to walkSpeed because of your if/else if chain
eternal falconBOT
topaz fractal
#

what do you reccommend i do @slender nymph

slender nymph
#

Think real hard about your conditions and then look at your if/else chain that is completely separate from that first if statement

tidal valve
#

hi guys i am new to this server, and i wanted to know were to start with learning how to program. so uhh id love to know if you have any suggestions

slender nymph
#

There are some excellent beginner courses pinned in this channel

tidal valve
queen adder
#

I have a set of objects I need to switch between with numerical keys. I am unsure of how to do it other than something like this:

        if(key1) inventoryObject = 1
        if(key2) inventoryObject = 2
        if(key3) inventoryObject = 3

Any idea you can share?

willow scroll
#

The KeyCode is an enum, which can be converted to int

#

The KeyCode.Alpha0's integer is 48

#

Start a loop with i = 0 and check for the KeyCode being Alpha0 + i

#
for (int i = 0; i <= 9; i++)
{
    if (Input.GetKeyDown(KeyCode.Alpha0 + i))
    {
        // ...
    }
}
#
Enumerable.Range(0, 10)
    .Where(i => Input.GetKeyDown(KeyCode.Alpha0 + i))
    .ToList().ForEach(i =>
{
    // ...
});
#

So it's going to be

inventoryObject = Enumerable.Range(0, 10)
    .First(i => Input.GetKeyDown(KeyCode.Alpha0 + i));
topaz fractal
#

public class newPlayerScript : MonoBehaviour
{
    [SerializeField] Transform cameraT;
    Vector2 look;

    void Start()
    {
        
    }


    void Update()
    {
        //mouseLook with Vector2 look
        look.x += Input.GetAxis("Mouse X");
        look.y += Input.GetAxis("Mouse Y");

        cameraT.localRotation = Quaternion.Euler(-look.y, 0, 0);
        transform.localRotation = Quaternion.Euler(0, look.x, 0);
    }
}
``` why is this simple line of code not allowing my camera took look up and down, only left and right
turbid bridge
#

dont know if this is the right channel but does anyone know how i can stop a double image from showing on a object https://i.imgur.com/DhMRK4l.png there is only one image made but for some reason it shows 2 images on the object. if i dont use a image with a transparant back its fine but as soon as i make it transparent i see the image twice

topaz fractal
#

someone please help, i dont understand this, its so simple

willow breach
#

Hey I have a difficulty with Newtonsoft.Json JsonConvert.DeserializeObject<T>(File.ReadAllText(path)
I can serialize classes just fine when some props are customer enum ("bla": 1 serialized to MyEnum.First)
but if the prop is nullable custom enum I get string value of the enum instead of enum ("bla": 1 serialized to "First")

i tried to use StringEnumConverter and while debugging it did convert it to enum, but the final result of the the load function was strings

do anyone know how to handle this?

ivory bobcat
#

Your vertical changes with the mouse will only have an effect on whatever camera T is.

#

Other than that if it's got a rigid body component, check the constraints.

south dock
#

hey i want to make a script for a stamina bar and as long as i press the shift key the stamina will drop. However when i press the shift key it decresses once and not as long as i press it?

broken cargo
south dock
#

i have tried all of them

#

if (Input.GetKeyDown(KeyCode.LeftShift))
{
playerMoveSpeed *= playerSprintMutiplier;
isRunning = true;

 currentStamina -= runStamina * Time.deltaTime;
 
 if (currentStamina <= 0)
 {
     currentStamina = 0;
 }
 staminaBar.fillAmount = currentStamina / maxStamina;

}

#

maybe im an idiot and cant see the problem

broken cargo
south dock
#

ill try

#

thanks

south dock
#

thanks it works

willow scroll
#
if (currentStamina <= 0)
{
    currentStamina = 0;
}
currentStamina = Mathf.Max(currentStamina, 0f);
south dock
#

now it just crashs my unity

broken cargo
south dock
#

gives me an error that says overflow in memory allocator

broken cargo
south dock
willow scroll
#

You'll have to show the entire code, which may cause this

south dock
#

no its not your code as soon as i changed it from down to input.getkey and play unity

#

i havent even changed that part

willow scroll
#

So you'll have to change the other code

willow scroll
south dock
#

i changed it back so it wont crash anymore

broken cargo
south dock
#

how do i share the whole code?

willow scroll
#

"I changed it back so that it doesn't work, because I have no intention in trying to fix the part of the code, which is causing the right way to accomplish my objective to not work"

willow scroll
eternal falconBOT
south dock
willow scroll
south dock
#

what? im sorry i didnt understand

queen adder
#

meaning try paste it into one of the sites

south dock
#

what sites?

broken cargo
south dock
#

oh

#

better?

willow scroll
#

Please, use a site to paste your code

south dock
#

i did

willow scroll
willow scroll
south dock
#

do i send the link?

twilit sundial
#

is coroutines really the most common way to add intervals to stuff

twilit sundial
#

awesome thanks

willow scroll
broken cargo
south dock
#

ill try to change it

#

THANK YOU!!!! I LOVE YOU!

#

it has been driving me crazy!

burnt vapor
twilit sundial
#

yea im just starting

burnt vapor
#

Coroutines are an easy way to have intervals, but you can also use Tasks, or Unity Awaitables if you want somewhat asynchronous support

#

There's also timers, and the Invoke and InvokeRepeating method. These work much better as an interval over writing a Coroutine, for example

twilit sundial
#

ah yea

#

thanks

slate haven
#

collision detecting with Inactive object somehow:

    {

        if (collision.gameObject.tag == "Enemy" || collision.gameObject.tag == "Enemy2" || collision.gameObject.tag == "Enemy3" || collision.gameObject.tag == "Enemy4" ||
            collision.gameObject.tag == "Enemy5" || collision.gameObject.tag == "Enemy6" || collision.gameObject.tag == "Enemy7" || collision.gameObject.tag == "Enemy8" || collision.gameObject.tag == "Enemy9")
        {
            if (!hasShield)
            {
                if(collision.gameObject.activeInHierarchy) 
                {
                    hasCrashed = true;
                    crashCount++;
                    audioSource.PlayOneShot(carCollide);
                } 
               
            }

            else
            {
                StartCoroutine(ActivateShield());
            }
            
             op.DeactivateGameObject(collision.gameObject.tag, collision.gameObject);
            
            
        }
}```
ivory bobcat
slate haven
#

so whats happening?

ivory bobcat
#

It likely wasn't inactive since the beginning of the frame

slate haven
#

also sometimes when i collide with a car, collision happens but my player doesnt die, happens occasionaly

ivory bobcat
#

Folks would need more information to help you with the second issue. Your first is likely due to the other object not actually being inactive since the beginning of the frame.

slate haven
ivory bobcat
#

You should probably share the code, inspector images and whatnot for the player and the object that isn't behaving appropriately.

slate haven
broken cargo
#

around 7 seconds before the end you click on the active green car and it has no visuals. Odds are the car you hit was the same and became inactive when you hit it

slate haven
#

if it did hit it the 1st time, it becomes inactive as per rule

#

then become active only if the pool is empty

#

I also checked the car's order in layer which is perfect

broken cargo
slate haven
#

but still the same problem

#

every time its new car

broken cargo
#

make it active from the inspector and see if it will become visible, if not try to change some parameters to make it visible and find what is it exactly

slate haven
#

oh wait it was the sorting layer

#

i set it to 'player' and it got fixed

#

also if u look at 0:16 seconds, the collision was detected but the life didnt get affected, this issue is very rare

broken cargo
languid spire
#

Why do you have so many inactive cars on your track?

slate haven
slate haven
languid spire
slate haven
#

also what do u think about my game? does it play good? atleast from visual pov

#

this is my 2nd original game, yes imma beginner

slate haven
#

Yuppp

languid spire
#

Obviously the RigidBody2D is on your player, can you screenshot that

queen adder
#

In order to call GetTransformInfoExpectUpToDate, RendererUpdateManager.UpdateAll must be called first.
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

when i tried to change a tree from 16x16 to 16x32 size
doesnt work like that i guess?

swift crag
#

I've seen that one while working on a 2D project.

#

I don't think I ever worked out what was causing it.

languid spire
# slate haven Yuppp

btw

if (collision.gameObject.tag == "Enemy" || collision.gameObject.tag == "Enemy2" || collision.gameObject.tag == "Enemy3" || collision.gameObject.tag == "Enemy4" ||
            collision.gameObject.tag == "Enemy5" || collision.gameObject.tag == "Enemy6" || collision.gameObject.tag == "Enemy7" || collision.gameObject.tag == "Enemy8" || collision.gameObject.tag == "Enemy9")

can be replaced with

if (collision.gameObject.tag.subString(0,5) == "Enemy") {
}
languid spire
#

or even

if (collision.gameObject.tag.StartsWith("Enemy")) {
}
slate haven
#

Yes

languid spire
broken cargo
swift crag
#

A deactivated game object cannot experience collisions. All of its colliders are disabled.

#

On the other hand, a disabled Behaviour can receive collision and trigger messages

queen adder
#

i want to ask for your opinion since its haunting me

So i have watched a lot courses and learned the c# microsoft program, but i still cant imagine how to write a procedural generated world for my game. So i tried chatGPT, but i was told this is bad to use. And since i have not idea how to write that from scratch i would need to watch tutorials/resources then. But this is also "not done by myself" stuff. I feel like a coding loser lol.

#

chatgpt or tutorial feel like cheating