#💻┃code-beginner

1 messages · Page 174 of 1

queen adder
#

Why it apears more than just the circle, the cookie image i am using does not have more that just that light circle, why is it replicating ?

clear seal
#

it no no works :(

short hazel
#

Of course, because of the issue I presented in the very same sentence

verbal dome
#

Warnings are there for a reason!

short hazel
# clear seal it no no works :(

It requires an extremely precise timing for it to work. Once the coroutine resumes you have around 16 milliseconds (assuming 60 FPS) to press the key. Too fast, and the coroutine hasn't resumed yet. Too slow, and the coroutine ended already.

clear seal
queen adder
clear seal
#

right?

short hazel
#

Very hard to code? What

clear seal
verbal dome
#

Change Wrap Mode to Clamp, then hit apply

clear seal
#

do i need to make it inside so i will be a part of the if?

queen adder
#

it worked

verbal dome
clear seal
#

of abt 1.25 sec

verbal dome
#

What

#

1800 canon?

clear seal
verbal dome
#

I see

#

Just having WaitForSeconds does not prevent other Shoot coroutines from starting

#

You could use a bool like isCoolingDown that you set to true when shooting. Set it to false after the Wait

#

And don't start a new Shoot coroutine if that bool is true

short hazel
#

Yeah, and you'd want to do this in the right order
KeyDown -> WAIT -> Shoot

verbal dome
#

Also the KeyCode.F check would make more sense in update

verbal dome
#

Like, the fuse

short hazel
#

Your code had KeyDown -> Shoot -> Wait
And putting it before the if would do Wait -> KeyDown -> Shoot

clear seal
#

hold on i wont be responing gotta do smth real quick

static bay
#

Filtering for triggers and anything else that "collects" gameobjects.

hybrid sundial
#
{
    // Start is called before the first frame update
    public Vector3 scaleChange;
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        transform.localScale. += scaleChange; 
        
    }
}```
#

why does this not work, im a complete beginner following the tutorials

rich adder
hybrid sundial
north kiln
#

Fix your IDE

hybrid sundial
hybrid sundial
north kiln
#

Ah, it's functioning

#

do you not see the .?

hybrid sundial
#

uh which .

north kiln
rich adder
#

shiteee

hybrid sundial
#

oh ffs

#

ty lmao

trail verge
#

Hi, is it possible to get the value of a variable from Script A and use it in Script B? I tried it this way
I wrote this in script A

public bool IsGrounded()
{
return m_Grounded;
}

And this in in Script B

public FoxController2D foxController;
if(foxController != null)
{
grounded = foxController.IsGrounded();
}

north kiln
#

And what's the issue? It seems odd you're checking for null, do you expect that value to ever be null?

clear seal
rich adder
#

no

clear seal
#

dang it

rich adder
#

they saying put a bool check before starting one

trail verge
teal viper
north kiln
#

checking for null was an advice from chatgpt
notlikethis

rich adder
#

not a good way to learn

clear seal
#

i tried using it

#

but no

#

worst idea you could have thinking about

clear seal
#

chat gpt is 💩 in coding

north kiln
#

well, it wouldn't do anything or error if it was null

#

remove the null check

#

and then make sure you check the console for exceptions when the code runs

trail verge
#

ok i´ll try it now

dusty silo
#

Is there a way for a script that is instantiating an object to add itself as a component to that object?

north kiln
verbal dome
#

You can't move a component to another object

#

But you can add a fresh one with AddComponent

dusty silo
#

It wouldn't be attached to anything, just an instance of a class

trail verge
north kiln
#

You mean, referencing the original component when you instance?

north kiln
green copper
#

why is touch.position set to several hundred thousand? when an item is not held, the position is calculated and placed normally, this is only for the drag visualization code

trail verge
polar acorn
trail verge
polar acorn
green copper
#

These two screenshots were taken while the object was being held, and the positions should be identical.

polar acorn
north kiln
vernal minnow
hybrid sundial
#

i have a question it might be super stupid for you guys, you know how we use update, wouldnt that mean if somebody has a better pc with more fps the gamer would make some things faster than intended?

green copper
polar acorn
eternal falconBOT
vernal minnow
#

public (scriptname) script;

polar acorn
teal viper
hybrid sundial
green copper
shy ruin
hybrid sundial
#

i dont understand, woukldnt the time since the last frame also vary based on pcs

north kiln
north kiln
shy ruin
green copper
north kiln
shy ruin
#

a person would 1000 fps would run faster than a person with 10 fps, you can use deltaTime to make them go the same

hybrid sundial
trail verge
shy ruin
#

Well, the time since last frame is basically the same on all computers

hybrid sundial
#

wouldnt it be faster if the pc is better

polar acorn
# trail verge i posted it

Follow the instructions on how to post the code properly, and show where you assign foxController, which was not in that code

north kiln
shy ruin
#

No cause there is less time between frames

#

Read the docs

teal viper
polar acorn
hybrid sundial
#

ohhhhhh

shy ruin
#

It all adds up

#

to be the same on both players

hybrid sundial
#

yeahh i get you since the better computer would have say 2k fps and the time would be 0.001 it would make the time ahhhhhh thats so smart

trail verge
#

!code

eternal falconBOT
polar acorn
trail verge
polar acorn
trail verge
polar acorn
north kiln
#

Go to one of the sites, paste in your code, click save, copy the URL

trail verge
polar acorn
north kiln
#

This code doesn't explain how you assign a value to the foxController variable

hybrid sundial
#

im gonna dream about time delta time today gn mindblownegg

polar acorn
#

Where do you tell this code which FoxController2D that variable holds

north kiln
trail verge
polar acorn
north kiln
#

stop mentioning the robot that autocompletes text

polar acorn
#

You aren't going to get very far by doing a fancy version of typing the word public and hitting the middle option on your phone keyboard until the program is finished

dusty silo
#

The instantiation part works, but the created object has neither a LineRenderer nor an EdgeCollider

        Instantiate(m);
        ec = m.AddComponent<EdgeCollider2D>();
        lr = m.AddComponent<LineRenderer>();```
north kiln
trail verge
dusty silo
polar acorn
polar acorn
green copper
#

The debug.log claims that the selected item's position is correct but the inspector shows it a hundred thousand units away and displaced by 1520 in the Z axis, the hierarchy is also visible in the editor screenshot.

polar acorn
#

relative to the parent

green copper
#

you can see in the inspector the parent hasn't changed, item(clone) is still a parent of grid1

polar acorn
#

And scales

green copper
#

Sale of canvas is 0.0003 for some reason, but it's screen space camera so I can't alter it?

#

scale of grid 1 is just 1 1 1

polar acorn
#

Change your log to this:

Debug.Log($"{rectTransformOfItem.gameObject.name} is at {rectTransformOfItem.position} world, {rectTransformOfItem.localPosition} local", rectTransformOfItem);
#

It'll give more info, and when you click once on the log it will highlight the object whose positions it printed

teal viper
green copper
#

Removed the code that generated the second item, it was irrelevant and distracting

polar acorn
# green copper

Yep, seems like that's what you're getting. You're setting it to the world position 370, 1673, 0, which translates to that in its parent's reference frame

#

Try this: Create a cube that is not a child of any object. Set its position to 370, 1673, 0 and compare where it is to the thing you've cloned

#

That is the position you're telling the object to go to

green copper
#

it's a little off, the white speck is the cube, the widget is the sprite

clear seal
#
{
    public Transform bulletSpawnPoint;
    public GameObject bulletPrefab;
    public float bulletSpeed = 100;
    private bool IsCoolingDown = false;

    public AudioSource CanonShot;
    public ParticleSystem CanonMuzzleFlash;

    void Update()
    {
        if(IsCoolingDown == true)
        {
            StartCoroutine(IsCoolDown());
        }
    }

    void OnTriggerEnter(Collider Player)
    {
        if (Player.tag == "Player")
        {
            Debug.Log("canon shot");
            StartCoroutine(Shoot());
        }
    }

    IEnumerator Shoot()
    {
        
        if (Input.GetKeyDown(KeyCode.F))
        {
            IsCoolingDown = false;
            yield return new WaitForSeconds(1.25f);
            CanonShot.Play();
            CanonMuzzleFlash.Play();
            Vector3 shootD = (bulletSpawnPoint.forward + bulletSpawnPoint.up * 2).normalized;
            var bullet = Instantiate(bulletPrefab, bulletSpawnPoint.position, bulletSpawnPoint.rotation);
            bullet.GetComponent<Rigidbody>().AddForce(shootD * bulletSpeed, ForceMode.Impulse);
            Debug.Log("coroutine executed");
            IsCoolingDown = true;
        }
        
    }

    IEnumerator IsCoolDown()
    {
        yield return new WaitForSeconds(4f);
    }
}``` is good?
green copper
#

needed to zoom out a ton to get both in frame

polar acorn
green copper
clear seal
#

it'salway the same script there is nothing related to the subject

polar acorn
# green copper changed screenshot to include heirarchy

I was hoping the cube would demonstrate what I was trying to convey but I guess my math was off and my example backfired, so I'll just say what I was trying to get at

Your issue is you're using a screen position in pixels as a world position in meters. Your object is way off from where you think it is because the canvas is not an object that physically exists, it's basically a transparent film stuck to the inside of your camera

north kiln
# green copper changed screenshot to include heirarchy

This all makes complete sense to me. ScreenSpace - Camera is in the space of the camera (a little plane in world-space in front of the camera), and you're spawning something in world-space using Screen space coordinates

clear seal
#

there is nothing related to coroutines

polar acorn
#

If you are having this much trouble reading the discord reply chain I can see why you can't read the documentation

clear seal
polar acorn
green copper
green copper
swift crag
#

localPosition will be relative to whatever the item is parented to

clear seal
#

!docs

eternal falconBOT
green copper
swift crag
#

so this canvas is in Screen Space - Camera mode, correct?

swift crag
swift crag
#

So to fit the camera in front of your camera at a distance of 5 meters, it must be scaled down a lot

#

So a local position of, say, [300, 500, 0] translates to a very small amount of movement in world space, because the canvas has been scaled down a ton.

#

(I say 5 meters because that's the Plane Distance you've chosen)

swift crag
green copper
#

so to do this, I need to give the canvas directly to the script as a public variable? or is there a way to grab it without that?

swift crag
#

if you just want your grandparent, that's transform.parent.parent.

It sounds like you want to set the position of the object in the frame of reference of the canvas, though.

#

In that case I would either hand the component a reference to the Canvas or use GetComponentInParent<Canvas>() once

#
var canvas = GetComponentInParent<Canvas>();
transform.position = canvas.transform.TransformPoint(screenSpacePosition);

This would position your object on the plane of the canvas.

green copper
#

for clarification, the script running this code is on the camera, not the objects being moved

swift crag
#

then it'd be someObject.transform.position

#

same deal

green copper
swift crag
#

TransformPoint computes where in the world a local-space position is from a given Transform's point of view

#

This takes into account rotation, scale, and position

#
  • TransformDirection only cares about rotation
  • TransformVector cares about rotation and scale
  • TransformPoint cares about position, rotation, and scale
green copper
#

the position is still off

swift crag
#

remember that the local position of the object will not match the screen position

#

since its parent is not the canvas

green copper
#

right, so var canvas = selectedItem.GetComponentInParent<Image>().GetComponentInParent<Canvas>(); ?

#

wait, no

#

var canvas = selectedItem.parent.GetComponentInParent<Canvas>(); ?

swift crag
#

no, I'm telling you that selectedItem's local position should not match the screen position

#

unless it's parented directly to the canvas

#

or parented to something that's parented to the canvas and that has zero position, zero rotation, and one scale

green copper
#

Okay, I see now. I need to take the position, and subtract the transform of the grid, because currently the grid's transform and the item's are being added together?

swift crag
#

What are you trying to actually do here?

#

I don't know what your hierarchy looks like so I'm a bit in the dark

green copper
#

Item(Clone) is on a grid, and I need it to follow the pointer when it is being moved from one slot to another.

swift crag
#

"from one slot to another"?

green copper
#

it's a tarkov/resident evil inventory tetris type thing, the grid is an image with a tiled sprite applied. The actual storage and placing and removing is handled in another script and working fine, with position decided using the grid coordinates of the cell

swift crag
#

okay, so you're just trying to make the item stick to the pointer. got it.

green copper
#

exactly, yes

swift crag
#

you showed the console, but that doesn't really tell me if the item is positioned wrongly in the world

#

the Z position certainly looks right for a camera at the world origin (since the Plane Distance is exactly 5)

green copper
#

when I let go, the item does slot into the correct cell, it's just the floaty preview that is off

craggy oxide
#

is there any harm in just parenting things as a quick-fix rather than scripting
like parenting your camera to the player so it automatically follows it instead of creating a script that makes it follow
im not looking for answers to that specific example i just wanna know the pros and cons of doing so

swift crag
#

if you just need X to follow Y, parenting makes plenty of sense

wintry quarry
craggy oxide
#

heh yeah i gotta learn the documentation lol

#

i'm just starting out so the Unity-specific variables and stuff I'm not well-versed in

#

any super important Unity variables that you think i should know, some that could really help but i might not find out about easily?

swift crag
#

there aren't really variables. there are certainly lots of methods that unity calls on MonoBehaviours, though

#

consult the Messages section

craggy oxide
#

well you know what i mean right

#

not variables per se i guess methods then yeah

swift crag
craggy oxide
#

yknow, the stuff that isnt in basic C#

green copper
craggy oxide
#

woah-hoh theres a lot of these

swift crag
#

the canvas's origin is the center

#

that's why you're seeing exactly half a screen height and width's offset

green copper
#

oh that scans yeah

swift crag
#

hm, what's the smoothest way of doing that correctly..

green copper
#

is there a better fix than just postion.x - screenwidth / 2 ?
it feels janky but it would work

swift crag
#

the first thing that comes to mind is that, yeah

#

the second thing is to use Camera.main.ScreenToWorldPoint

#

you'd set the Z coordinate of the point to 5

#

because that's the distance of the canvas from the camera

#

This should do the trick for you.

#

Transform a screen space point to a position in world space that is on the plane of the given RectTransform.

#

Pass it the canvas's RectTransform

#

This has an out parameter. You can use it like this:

#
RectTransformUtility.ScreenPointToWorldPointInRectangle(canvasRect, screenPoint, Camera.main, out Vector3 worldPoint);
item.transform.position = worldPoint;
#

what a mouthful of a name

north kiln
#

Good name, explicit is good

craggy oxide
#

quick question, what does the majority of necessary unity code go towards specifically? camera movement? physics simulation?

cause like the scripts im seeing so far seem relatively simple yet they do a lot, player movement is only a couple lines of code, so where does the rest go typically

green copper
swift crag
#

Correct.

swift crag
#

I guess I could count how many lines of code my project has in various categories

craggy oxide
#

loll no need to do that dont worry its all good

#

im just curious about the contrast between the beginner scripting courses im taking, and the advanced coding that's at the end of the tunnel

#

maybe ill find out as i go along anyway

green copper
swift crag
#

oh, I didn't know if that actually existed :p

#

just cast the canvas's Transform to a RectTransform

swift crag
craggy oxide
#

wowie

#

is that in one game?

swift crag
#

this is being very generous, since that's included blank lines

craggy oxide
#

Loll okay fair enough you could probably halve it at the least

#

still, you must be making quite a big game to need that many UI lines

green copper
swift crag
#

I built a pretty elaborate system, so there are a lot of scripts in there

#

Games do a lot of things.

#

I have a lot of code for really boring stuff, like saving and loading your settings reliably

craggy oxide
#

ahh so is it more like, behind the scenes work rather than direct game inputs

#

is that where the bulk of the code goes

fluid fossil
#

my VSC seems to hate me and want to block all of my progress. Is there a reason why like 50% of the time I try to code it just refuses to understand what code in general is? Like why the hell is the if statement an error. If I put this stuff into a different class it works perfectly fine, it just seems to randomly hate certain class files for NO reason

craggy oxide
#

do you have a class and a method

craggy oxide
#

yeah wheres the namespace

fluid fossil
#

my bad prolly shoud've shown the entire class as well

#

without the error message hovering over it

craggy oxide
#

wha about the method

#

nah actually im a newbie im unqualified to speak on this

vernal minnow
#

Oh yeah

eternal needle
#

no, you dont need a namespace

vernal minnow
#

Start, update, something?

vernal minnow
swift crag
#

you can't just write code outside of a method

eternal needle
swift crag
#

that's not valid C#

fluid fossil
#

no you're right I did need an update function. im a complete idiot

#

no, I understand the basics I'm just entirely idiotic sometimes

craggy oxide
#

oh i was right! first person helped by me less go

shell bane
#

Good night. I'm a beginner in programming, and I'm trying to make a simple game of choices, for example:

"You are walking in the forest and you find two paths, the one on the right and the one on the left. Which one do you choose? 1 . right or 2. left"

I'm trying to do this with buttons and text box, then when I choose 1 it gives me one answer and 2 another. But I want to do a second part with choice and it's not working.

note: I asked chatGPT for help to do 90% of the code, since I'm still learning, and it has already given me a lot of code.

Can anyone help me?

eternal needle
eternal falconBOT
swift crag
#

that's going to give you a gigantic pile of AI-generated sludge that's basically unmaintainable

#

i would strongly advise looking up tutorials for text-based games

vernal minnow
shell bane
#

i was using if else

ripe shard
shell bane
#

no

covert glade
#

hello im a beginner in c# is there a good playlist or something i follow to learn it?

ripe shard
#

!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

Over 750 hours of free live and on-demand learning content for all levels of experience!

covert glade
#

thanks man

vernal minnow
# shell bane no

C# console can do a text based game pretty easily, or are you wanting visuals? (I'm assuming ya want on click, return variable if unity is being used mostly for the visual

shell bane
#

visual

ripe shard
# shell bane no

If you want to make a text adventure it would be easiest to do that as a commandline app

vernal minnow
#

He wants visuals

#

@shell bane have you used textmeshpro yet?

shell bane
#

yes

vernal minnow
#

And ya found put how to make buttons?

#

There should be some pretty good video tutorials on how to make functional in game buttons

shell bane
vernal minnow
#

Ooh, a text based rpg?

shell bane
#

yes

vernal minnow
#

Looks pretty nice

shell bane
#

thx

covert glade
vernal minnow
#

Are those flags the buttons?

#

Purple, red, and blue

shell bane
#

yes

vernal minnow
#

And +/- ig

shell bane
#

quest, inventory and map

shell bane
#

im from brazil

#

google tradutor is my savior

vernal minnow
#

Ouch, I was gonna recommend a video lol

#

How to create buttons in Unity? Let's have a look. We will create and script buttons in this Unity tutorial for beginners.

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

♥ Subscribe to Oxmond Tutorials:
https://bit.ly/SubscribeOxmondTutorials

● Get the FurBall character from the Unity Asset Store:
https:...

▶ Play video
#

Not sure if it will help since it's in English but it should give a walk through

shell bane
#

Usually no video shows exactly what I'm looking for

vernal minnow
#

Probably the case, but if you can get a button to show a debug log when ya click it, ya can pretty well make it do anything else after

#

If getting the click input is your issue

shell bane
#

My button is already following the story normally, but in the part of making the choice, it gets lost in the index and doesn't follow the story

vernal minnow
#

Ah

#

Do the button get covered or are they returning the wrong input?

shell bane
#

i dont know exactly

vernal minnow
#

Ah

timber tide
#

if you can translate the errors

shell bane
#

Question text isn't changing

eternal needle
#

im guessing thats an index error

#

given by the hard translation of index

covert glade
vernal minnow
#

That's not to bad, ya need some variables to set which text shows

covert glade
#

i know no c#

shell bane
#

dialogueIndex 12 is not immediately after a known choice point.
UnityEngine.Debug:LogError (object)

#

there is some points of choice

#

private readonly List<int> choicePoints = new List<int>{12, 14};

timber tide
#

yeah so index error

shell bane
#

index 12 is a point

#

the text is in the index 12

#

dialogueIndex: 12
UnityEngine.Debug:Log (object)

#

choicePoints: 12, 14
UnityEngine.Debug:Log (object)

eternal needle
timber tide
#

you're accessing an index of 12 probably with 2 indices

shell bane
#

I don't get it

covert glade
timber tide
#

you define 2 indicies, 12 and 14, but you're accessing the list as choicePoints[12] probably which is out of bounds

#

that's the only thing I can think the error means

#

otherwise need to see code

shell bane
#

private void SetupChoiceButtons()
{
Debug.Log("Configurando botões de escolha...");

        foreach (var button in choiceButtons)
        {
            button.onClick.RemoveAllListeners();
        }

        if (dialogueIndex == choicePoints[0])
        {
            choiceButtons[0].GetComponentInChildren<TextMeshProUGUI>().text = "Usar a pedra";
            choiceButtons[0].onClick.AddListener(() => OnChoiceMade(1));

            choiceButtons[1].GetComponentInChildren<TextMeshProUGUI>().text = "Usar a vara";
            choiceButtons[1].onClick.AddListener(() => OnChoiceMade(2));
        }
        else if (dialogueIndex == choicePoints[1])
        {
            choiceButtons[0].GetComponentInChildren<TextMeshProUGUI>().text = "Espada e escudo";
            choiceButtons[0].onClick.AddListener(() => OnChoiceMade(1));

            choiceButtons[1].GetComponentInChildren<TextMeshProUGUI>().text = "Arco e flecha";
            choiceButtons[1].onClick.AddListener(() => OnChoiceMade(2));

            choiceButtons[2].GetComponentInChildren<TextMeshProUGUI>().text = "Cajado e tomo";
            choiceButtons[2].onClick.AddListener(() => OnChoiceMade(3));
        }

        for (int i = 0; i < choiceButtons.Length; i++)
        {
            choiceButtons[i].gameObject.SetActive(dialogueIndex == choicePoints[0]? i < 2 : i < 3);
        }
    }
#

opss

timber tide
#

ok, so index 0 and 1 should work, right? But you have no choiceButtons[2]

eternal needle
# covert glade is it better to learn basic c# first

yes, if you want to learn properly and have the patience to wait to start game dev. We see people trying to learn c# and unity at the same time everyday. It is like trying to do advanced physics while not knowing what 1+1 is. They struggle way more than they should

covert glade
#

do yk any good basic c# channels tho?

timber tide
#

yeah, this is basic indexing stuff which can be simply an afternoon to learn instead of relying on chat gpt

shell bane
#

i made 4 buttons

#

they apper normally

timber tide
#

oh, it's dialogueIndex

#

where's that

#

ok, well, that does seem index fine

shell bane
timber tide
#

give me the line specifically

eternal needle
# covert glade do yk any good basic c# channels tho?

sorry, i dont look at any myself so cant really suggest there. i think w3schools is a decent start but it doesnt cover the real technical side of c#. Jamie king has a few good in depth c# videos but i forgot how advanced it is. He does explain clearly though

shell bane
#

is a index erro, but i dont know how to fix

#

i dont know the line

vernal minnow
#

I messed up by using only w3 lol

eternal needle
#

coding doesnt really change, so i dont know what u mean outdated

shell bane
timber tide
#

Honestly this is where breakpoints shine when it comes to debugging, but you can do it the old fashion way and just throw debug.logs everywhere and name them orderly

shell bane
#

i made this

#

but didnt help so well

#

This part was the closest I got because of debug.log

timber tide
#
choicePoints[1] + 1)```
teal viper
eternal falconBOT
nova igloo
#
GameObject pieceToTake = new GameObject();
pieceToTake = GetComponent<GameManager>().tilePrefab.transform.GetChild(0).gameObject;
pieceToTake.GetComponent<PieceManager>().SetPieceType(hit.collider.transform.GetChild(0).GetComponent<PieceManager>().GetPieceType());

I run this each time I click the mouse button, I then add the pieceToTake into a list.
When I click though, all objects in the list get effected by line 3 anyway
How do I make it so each pieceToTake object is a seperate object?

shell bane
#

the first one is [0]

vernal minnow
#

Wouldn't cs choicePoints[0] + 1) be the second?

shell bane
#

if (dialogueIndex == choicePoints[0] + 1)
{ .......

else if (dialogueIndex == choicePoints[1] + 1)
{

#

first part is [0]

#

second part of the history is [1]

#

history or story?

vernal minnow
#

So what's the +1 do?

#

Or does it just change it as the story goes?

eternal needle
shell bane
#

i dont know, i get help with chatGPT

#

gpt

vernal minnow
#

That may be part of the problem ngl

nova igloo
eternal needle
#

based on your code, it literally cannot have a GameManager component at that time

nova igloo
#
GameObject pieceToTake = new GameObject();
pieceToTake = this.GetComponent<GameManager>().tilePrefab.transform.GetChild(0).gameObject;
pieceToTake.GetComponent<PieceManager>().SetPieceType(hit.collider.transform.GetChild(0).GetComponent<PieceManager>().GetPieceType());
eternal needle
#

oh

shell bane
#

The expression dialogueIndex == choicePoints[0] + 1 is used to check if the current dialogue index (dialogueIndex) is exactly one point after the first choice point recorded in the choicePoints list.

Here's what each part means:

  • dialogueIndex: This variable represents the current index in the dialogue flow. You can think of it as the current position in the narrative or conversation being displayed to the player.

  • choicePoints: This is a list that contains the indices of dialogues where the player needs to make a choice. Each element in the choicePoints list represents a point in the narrative where the flow can change based on the player's choice.

  • choicePoints[0]: This expression accesses the first element (or first choice point) in the choicePoints list. Since the index of an array or list starts from 0, choicePoints[0] is the first choice point added to the list.

  • + 1: Adding 1 to the value of choicePoints[0] means we are referring to the index immediately after the first choice point.

Therefore, the comparison dialogueIndex == choicePoints[0] + 1 is used to check if the current dialogue is the moment right after the player has made a choice at the first decision point. This is useful for determining when to insert the consequences of a choice or to continue the narrative in a specific way based on the choice made earlier.

This logic allows the game to respond to the player's actions by adjusting the dialogue or narrative based on the choices made, ensuring that the following dialogue or events are relevant to the decision made by the player at the choice point.

#

+ 1: Adding 1 to the value of choicePoints[0] means we are referring to the index immediately after the first choice point.

eternal needle
nova igloo
#

Okay, I think a better way of wording it is how can i add pieceToTake to my list by reference instead of value.

eternal needle
#

based on what you described initially, it sounds like you are affecting some value on a prefab

nova igloo
#
GetComponent<GameManager>().takenBlackPieces.Add(pieceToTake);
#

this is right now

#

but when i do

pieceToTake.GetComponent<PieceManager>().SetPieceType(hit.collider.transform.GetChild(0).GetComponent<PieceManager>().GetPieceType());

it changes every object in the list

shell bane
#

yes

eternal needle
#

yea dont paste gpt text. if you cant describe it yourself then step away from what you're currently doing and go learn properly

#

no one wants to talk to someone, so they can talk to gpt, so it can talk to you, and you can paste it back

shell bane
eternal needle
#

yes i said initially that you likely arent gonna get help for gpt

timber tide
#

Start debugging more with logs if that's not the issue.

#

you'll figure it out yourself instead of asking

eternal needle
vernal minnow
#

Honestly running a debug at each task should help

shell bane
vernal minnow
#

You tested gtp?

shell bane
#

i have like, 11 debug.logs

vernal minnow
#

I put dubugs on anything that I'm testing ngl

shell bane
#

whats is ngl?

vernal minnow
#

(Everything if I'm being honest)

vernal minnow
shell bane
#

ok

#

Thank you for your attention

woeful lagoon
#

Hey yall, can anyone help me with some networking shenanigains

nova igloo
woeful lagoon
eternal needle
#

seems like thats a method under visual scripting

nova igloo
#

i was just using intellisense and found cloning, but this is the only one that worked

eternal needle
#

its better when you show more context, its easier to help when i know what values actually are.
you definitely shouldnt use a random method if you arent sure about what it does. try and figure out what the actual issue is

nova igloo
#

I had tried a load of different things before that too: just an empty game object, obviously had no PieceManager. A piece manager directly, but didn't have Mesh renderer required by it etc, any way i tired before, i either got all objects in my list changing when adding one, or object reference not set to an instance of object (refering to mesh renderer)

eternal needle
#

🤷‍♂️ this is all too vague tbh for me to even say more. What is changing specifically? i still dont even know what value you are referring to. And that last thing you mentioned is just a null error, something is null when it shouldnt be.

woeful lagoon
#

Any ideas to fix it?

queen adder
#

is there a way to check if a rigidBody.MovePosition will bump something along the path? Rather than physicscast?

timber tide
#

isn't that like a straight line of movement

#

raycast seems like the best idea there

#

or physicscast like you said

queen adder
#

my colider is weirdly shaped 🥹

timber tide
#

what does that mean

#

physiccasts just dupes your collider every few units to check

queen adder
#

lemitry\

timber tide
#

or maybe it resizes the collider in the direction

#

no clue on its implementation, but it behaves like spherecast

queen adder
#

is that better than .Cast?

#

i dont have it anyways UnityChanOops

teal viper
#

2d?

wintry quarry
wintry quarry
queen adder
wintry quarry
#

I thought you were asking about 3D. You didn't mention which

queen adder
#

i didnt blushie

#

i actually have it in 3d at least

queen adder
#

how to make black box not trigger both of red and yellow's OnColliderEnter2D when it goes up?

#

like just choose one (preferably if it can smartly select the better (more visually overlapped))

buoyant knot
#

layers

buoyant knot
#

you can set collision matrix, or use layer overrides

#

using layers is the super efficient way if you have a fuckload of irrelevant collisions, because this will automatically filter out collisions that aren’t supposed to be relevant

#

because if two layers don’t interact, their objects do not generate OnCollisionEnter/etc when they overlap

queen adder
#

i want either, just not both

cunning rapids
#

Guys, my game view doesn't lock my cursor or makes it invisible when in maximized mode. I've had this problem for like 2 days already. It wokrs on Focused just fine

queen adder
cunning rapids
#

It happens to every new BiRP game I make

rich adder
queen adder
#

hmm... like the player holds the query?

cunning rapids
#

But there's a snowball's chance in hell the problem is with the RP (obviously). Is there something worng with my editor? i'm using 2022.3.19f1

queen adder
#

that's actually a good idea

queen adder
#

what's rp? render pipeline?

cunning rapids
#

Yes

#

RP isn't responsible for the lock state of the cursor

#

I think it's somethig with my editor

queen adder
#

the cursor doesnt lock even if you click the game screen?

cunning rapids
#

I can provide with code if it's of any help but I doubt it's a problem with my script

cunning rapids
#

It only works on Focused

#

For some reason

#

Maximized? not so much

queen adder
#

what's Focused?

cunning rapids
#

I Logged both the lockedState and visibility of the cursor and it says it looks good but the scene says otherwise

cunning rapids
#

Far right

queen adder
#

me is dont have that blushie

cunning rapids
#

The movement code

#

And:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerLook : MonoBehaviour
{
    [SerializeField] private float sensX = 100f;
    [SerializeField] private float sensY = 100f;

    [SerializeField] Transform cam = null;
    [SerializeField] Transform orientation = null;

    float mouseX;
    float mouseY;

    float multiplier = 0.01f;

    float xRotation;
    float yRotation;

    private void Start()
    {
        Cursor.lockState = CursorLockMode.Locked;
        Cursor.visible = false;
    }

    private void Update()
    {
        Debug.Log(Cursor.lockState);
        Debug.Log(Cursor.visible);
        mouseX = Input.GetAxisRaw("Mouse X");
        mouseY = Input.GetAxisRaw("Mouse Y");
         
        yRotation += mouseX * sensX * multiplier;
        xRotation -= mouseY * sensY * multiplier;

        xRotation = Mathf.Clamp(xRotation, -90f, 90f);

        cam.transform.rotation = Quaternion.Euler(xRotation, yRotation, 0);
        orientation.transform.rotation = Quaternion.Euler(0, yRotation, 0);
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MoveCamera : MonoBehaviour
{
    [SerializeField] Transform cameraPosition = null;

    void Update()
    {
        transform.position = cameraPosition.position;
    }
}

Both camera-responsible scripts

#

Again tho, I don't think the problem has anything to do with the scripts

cunning rapids
#

It's very useful for debugging

#

You can see what happens behind the scenes

rich adder
#

or you know..put the gameview side by side of scene view UnityChanLOL

cunning rapids
#

Why do that when you have focused mode

queen adder
#

can you try the rightclick, then maximize

#

dont do that Play maximized

cunning rapids
#

sure

#

Give me a sec

#

Where do I right click?

queen adder
#

I mean, play it while in focused mode, then only then youll do the rightclick then max

rich adder
queen adder
#

the GAME word

queen adder
#

nothing of this?

cunning rapids
#

Not that I know of

#

I think it's a problem on Unity's end

#

Something with the Editor or smth

#

I can maybe port it to 2019

#

I'm more used to it anyway

#

I just wanted to try 2022

edgy fox
#
GameObject addedHolder = Instantiate(holder, holderPosition, holder.transform.rotation, transform);

int removeIndex = addedHolder.name.IndexOf("(");
int toRemove = addedHolder.name.Length - removeIndex;
addedHolder.name.Remove(removeIndex, toRemove);//instantiating objects appends "(Clone)" to name, I don't like that here.
addedHolder.name += $" ({j+1},{i+1})";```

am I using `String.Remove` wrong? Nothing is being removed from `addedHolder`'s name
cunning rapids
#

Yes

#

The String.Remove method does not modify the original string but instead returns a new string with the specified characters removed

edgy fox
#

ah ok

#

did String.Replace("(Clone)","") instead

cunning rapids
#

Give me a second

edgy fox
#

works liek a charm

#

nah

#

I got it

north kiln
#

strings are immutable

cunning rapids
edgy fox
#

not a (Clone) in sight

queen adder
#

You can simply do

gameObject.name = gameObject.name.Replace("(Clone)", "");

anyways, if gameobject names affects you game, you doing something wrong

edgy fox
queen adder
#

i mean, their purpose is to make debugging easier though

edgy fox
#

I know, and removing the (Clone) makes debugging easier

queen adder
#

easy to figure out who is fking something

north kiln
#
var instance = Instantiate(source);
instance.name = source.name;
edgy fox
#

they're already renamed to have relative subcoords

north kiln
#

I wish you could turn off the Clone stuff 😄

queen adder
#

that better

edgy fox
#

yeah have a bool Clone???? in the instantiate

queen adder
#

I dont hate the (Clone).. though, I hate those numbers that appear when you duplicate something in editor

edgy fox
#

Clone is useful sometimes but when you're instantiating a prefab theres not really any purpose

edgy fox
#

just wrote a whole script that worked second try

queen adder
edgy fox
#

twas quite basic but stilll schocked I didn't add a comically stupid error halfway throughj

zinc grove
#

Online chess game

queen adder
rich adder
cunning rapids
#

Not worth changing some mumbo jumbo just to get rid of numbers on Instances

amber spruce
#
private void FixedUpdate()
{
    m_Rigidbody2D.velocityX = moveAmount.x * m_Speed;
    animator.SetFloat("Speed", Mathf.Abs(currentSpeed.x * m_Speed));
    if (Mathf.Abs(currentSpeed.x * m_Speed) > 0)
    {
        Footsteps.enabled = true;
    }
    else { Footsteps.enabled = false; }
}
public void Move1(InputAction.CallbackContext ctx)
{
    Vector2 inputVector = ctx.ReadValue<Vector2>();
    moveAmount = ctx.ReadValue<Vector2>();
    currentSpeed = ctx.ReadValue<Vector2>();
    float currentspeed1 = currentSpeed.x;
    animator.SetFloat("Speed", Mathf.Abs(currentspeed1));
    if (currentspeed1 > 0 && !m_FacingRight)
    {
        Flip();
    }
    else if (currentspeed1 < 0 && m_FacingRight)
    {
        Flip();
    }
}

thats my code for movement any idea why the player is like blurry ish when they move

#

the gif doesnt show it all that good

faint osprey
#

if i instantiate 2 of the same objects that have the same script if one bool changes on one object will it change on the other

charred spoke
faint osprey
charred spoke
#

Then it will not. Generally every instance of a object keeps its own variables that cane be different. The exception are static variables that are shared between instances.

faint osprey
rich adder
#

it spawns whatever default was in script initializer of field

gaunt ice
#

script is a text file (so i wont name the class as XXScript)
instead when you drag the script of the object it creates a component (ie an instance in main memory)
when you copy the object the new component is initialized by field initializer/awake/start/other stuffs

charred spoke
#

Actually his question got me reading a bit. I believe that Instantiate will copy over the stste of the bool from the first instance along with any other serialisable fields. If the component does not init the bool by itself in start awake etc it will share the state of the other instance

charred spoke
#

Or so I think…. In 15 years of doing unity I dont believe I have used Instsntiate on already existing clones…

rich adder
charred spoke
rich adder
charred spoke
#

This is however my current assumption someone needs to test this

wicked bolt
#

no

rich adder
wicked bolt
#

I only have one script

#

thats the only thing the console gives me

#
using System.Collections.Generic;
using UnityEngine;

public class gridManager : MonoBehaviour
{
    public Sprite sprite;
    public float [,] grid;
    public int columns, rows, vertical, horizontal;
    // Start is called before the first frame update
    void Start()
    {
        vertical = (int)Camera.main.orthographicSize;
        horizontal = vertical * Screen.width / Screen.height;
        columns = horizontal * 2;
        rows = vertical * 2;

        grid = new float[columns, rows];
        for (int i = 0; i < columns; i++)
        {
            for (int j = 0; j < rows; j++)
            {
                grid[i,j] = Random.Range(0.0f, 1.0f);
                spawnTile(i, j, grid[i,j]);
            }
        }
    }

    private void spawnTile(int x, int y, float value)
    {
        GameObject g = new GameObject("X:"+x+" Y:"+y);
        g.transform.position = new Vector3(x -(horizontal - 0.5f), y -(vertical - 0.5f));
        var s = g.AddComponent<SpriteRenderer>();
        s.sprite = sprite;
        s.color = new Color(value, value, value);
    }
}
#

Oh

#

huh

#

I see the issue

#

I replaced vertical and horizontal with numbers for rows and columns

gaunt ice
#

1920*1080>10^3*10^3=10^6 gameobjects

wicked bolt
#

but not transform.position

wicked bolt
#

it was originally 5x that

#

which ate my whole 32gb ram

charred spoke
wicked bolt
#

Ooh thanks, Ill save that

rich adder
#

just tested it

#

if Instantiate uses the modified clone and not prefab it copes its values not uses the Initializers

charred spoke
rich adder
#

Yeah I never actually cloned a spawned prefab before , but yeah it does copies values apparently, interesting TIL

charred spoke
#

Well this deep copy mechanism is the reason Instantiate is considered slow. It does it for prefabs but there really isnt a reason for it not to do it for anything it clones

#

Wont be much of a “clone” really

rich adder
#

double edge sword, on the other hand is kinda handy knowing it can deep copy like that

gaunt ice
#

left: private field, right: public field

charred spoke
#

Obviously a private field is not serialised in the first place

gaunt ice
#

yes, depend if the fields can be serialized to read the value

charred spoke
#

Nor can Instantiate get to it in any way

charred spoke
#

If you have a custom Type that is not serializable it wont get copied as well

wicked bolt
#

thats certainly not inside the camera

#

and certainly isnt acting as intended

wicked bolt
#

Should only be filling the camera with a grid of squared

gaunt ice
#

you cant simply use some coordinate in screen space in your world space

quick pollen
#

Hey! Quick question, how could I make a charactercontroller get a quick burst of speed that kind of de-accelerates really fast?

#

I want to have a type of jump where you get a lot of sideways momentum depending on which way you start jumping

wicked bolt
charred spoke
#

Detect input that you are dashing, add some big dash velocity to your existing velocity. Handle some sort of drag to slow down.

quick pollen
charred spoke
#

Yes

quick pollen
#

okay

#

how could I add a drag then

#

I tried and it always ended up being weird

#

i tried using a lerp function i think

charred spoke
#

Well the simplest drag is just a force acting in the opposite direction of your movement

quick pollen
#

well that would mess up the charactercontroller movement

charred spoke
#

Why would it ?

quick pollen
#

if I tried having multiple Move() calls happen in update

#

it'd make it jitter

#

one tells it to go left

#

another tells it to go right

charred spoke
#

Sure just use one move call

#

Add and subtract to the same velocity vector

#

And at the end tell the cc to move with it

quick pollen
#

this is kinda what I have btw

charred spoke
#

Thy to refactor your code to have a single move it will make it much easier to add things then

quick pollen
charred spoke
#

The CC just wants a vector to move in. Everything like input gravity dash air friction pushback from a explosion can be stuck into that one single vector

quick pollen
#

well technically there's vertical and horizontal being different

charred spoke
quick pollen
quick pollen
#

but how can I add like the horizontal and vertical movement together then?

#

just a +?

charred spoke
#

Yep

#

Well a good idea is to add up your input vectors, normalize it and then apply it to the velocity by some move speed

quick pollen
#

here I come ig

quick pollen
#

i did this but it looks hella unclean

#

I probably want some formulas

#

I can also probably add these up to be like half the length

charred spoke
#

Just add them up in a variable before hand ?

#

You also dont need the else gravity

#

I mean you do want it but you can offload that logic before

quick pollen
#

but yeah I get what u mean

#

this should work better right @charred spoke

        Vector3 horMoveDirection = transform.rotation * new Vector3(Input.GetAxisRaw("Horizontal"), 0f, 0f).normalized * Time.deltaTime * vertSpeed;
        Vector3 vertMoveDirection = transform.rotation * new Vector3(0f, 0f, Input.GetAxis("Vertical")).normalized * Time.deltaTime * horSpeed;
        _controller.Move(horMoveDirection + vertMoveDirection + _gravPull * Time.deltaTime);```
#

tho i might want to initialize the vectors in the file

#

not every update

charred spoke
#

Again im telling you to sum up everything inside a single Velocity variable and pass that onto the move

charred spoke
#

It should work exactly the same as before, its just going to be easier for you to add changes to the velocity

quick pollen
#

ah right I get it

quick pollen
#

shouldn't I initialize it in the header?

charred spoke
#

Its perfectly fine

#

Putting small structs like a Vector3 on the stack is not a perf issue

alpine zephyr
#

Very very new to Unity so apologies if my terminology is incorrect but in a script I'm trying to access the "Speed" part of the Surface Effector 2D Component so I can tune it with Keybinds, but I'm not exactly sure how since it's in the drop down menu of "Force". According to both VS Code and Unity the Surface Effector 2D doesn't contain the definition "Speed". Here's what I tried:

        SurfaceEffector2D.Speed(slowedSpeed);```
And: 
```float slowedSpeed = Input.GetAxisRaw ("Vertical") * slowSpeed *Time.deltaTime;
        SurfaceEffector2D.Force.Speed(slowedSpeed);```
keen dew
#

also you need an instance of the component with GetComponent for example

#

and I doubt the speed should be multiplied by deltaTime

alpine zephyr
#

Oh yeah now that I think about it, deltaTime doesn't seem needed in this case. I'll do some research on how to GetComponent. Thank you so much!

vast vessel
#

hey guys, im getting a weird error saying that "combined mesh" doesn't have read/write enabled, heres the thing:
the mesh that im trying to read data from, is a probuilder mesh on a game object named Cube, as you can see in the console;
and when i open the pro builder mesh in the inspector, it says it has read/write enabled.

so what's the issue?
ive had 3 other pro builder meshes give me the same error, but all the other probuilder meshes, and normal mesh renderers are fine

code reading the mesh : https://hastebin.skyra.pw/lihesicolo.csharp

#

where HandleImpact() is called, and the error /\

cunning rapids
#

When trying out a new retro-style for my game this returnss for some reason

#

I can move around and do other things an the camera clearly works

#

But it still returns this

#

I'm using a custom raw image texture for the pixelation effect

dusty mango
#

!vscode Can anyone help me connect my unity to vscode?

#

For my macbook

cunning rapids
#

Why isn't my (right) camera inspector isn't as big as the other one?

eternal falconBOT
dusty mango
languid spire
dusty mango
#

dang

frank flare
#

So I want my player to instantly get some small speed when it starts to move. But how do I do it?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Control : MonoBehaviour
{
    private Rigidbody rb;
    private float SpeedAdd = 200f;
    private float SpeedMax = 60f;
    
    // Start is called before the first frame update
    void MoveLeft()
    {
        rb.AddForce(-transform.right * 200f);
        
        if (Mathf.Abs(rb.velocity.x) < 5f)
        {
            rb.velocity = new Vector3(rb.velocity.x * -1.2f, rb.velocity.y, rb.velocity.z);
            Debug.Log($"The current velocity: {rb.velocity.x}");
        }
    }

    void MoveRight()
    {
        rb.AddForce(transform.right * 200f);
    }

    void Jump()
    {
        rb.AddForce(transform.up * 1000f);
    }

    void NotMoving_SlowDown()
    {
        rb.velocity = new Vector3(rb.velocity.x * 0.88f, rb.velocity.y, rb.velocity.z);
        Debug.Log($"Not pressing D. Current in right velocity: {rb.velocity.x}, making closer to 0...");
    }

    void Start()
    {
        rb = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void FixedUpdate()
    {
        if (Input.GetKey(KeyCode.A))
        {
            MoveLeft();
        }

        if (Input.GetKey(KeyCode.D))
        {
            MoveRight();
        }
        if (!Input.GetKey(KeyCode.A) & !Input.GetKey(KeyCode.D))
        {
            //rb.velocity = new Vector3(0, 0, 0);
            NotMoving_SlowDown();
        }
        if (Input.GetKey(KeyCode.Space))
            Jump();
        Debug.Log(rb.velocity);
    }
}

#

I think I tried all logical ways I could make it

vast vessel
cunning rapids
#
rb.AddForce(-transform.right * SpeedAdd);
north kiln
vast vessel
cunning rapids
north kiln
#

The mesh produced by static batching is not marked as readable

cunning rapids
#

I'm following a tutorial

gaunt ice
#

not code question
this is urp camera, the inspector is different

cunning rapids
#

That's odd

#

I remember specifically that I could've stacked camera in the SRP

frank flare
cunning rapids
#
private bool isMoving = false;
frank flare
#

so the game will be smooth

cunning rapids
#
        if (!isMoving)
        {
            rb.velocity = new Vector3(-SpeedAdd, rb.velocity.y, rb.velocity.z);
            isMoving = true; 
        }
        else
        {
            rb.AddForce(transform.right * SpeedAdd);
        }

Adding logic like this can help

cunning rapids
frank flare
#

maybe making it closer to the 0, 0, 0 velocity in case if the direction it's moving is right better?

#

something like that

#
rb.velocity = new Vector3(rb.velocity.x * 0.88f, rb.velocity.y, rb.velocity.z);
cunning rapids
#

probably

#

Up to your standards

wicked bolt
#

How can I get Debug.Log to show atleast like 2 decimal points from math equations?

#

Do I need to do the math before as a float them add the float to the log? Or can I do it all with the Debug.Log line?

languid spire
wicked bolt
languid spire
#

yep, that will break for sure

wicked bolt
#

aspectRatio.ToString("N2")?

twilit dirge
#

I'm trying to think about the best way to go about implementing dialogue into my game. I've done calculations and the amount of dialogue in the game in its entirety is probably going to be roughly around 15,000 pieces. I've seen some places which say to use scriptable objects for storing text, but given the absolute size of the dialogue I need, I feel like a text based approach would be better.

#

Though, I'm not entirely certain how to go about this. I certainly don't want to search through the files every single time a piece of dialogue needs to be summoned. But I also don't know if it's common practice / best to load that much dialogue in at runtime through dictionaries or lists of some sort and leave it just sitting there in memory

#

Any tips? / common practice ways to go about this?

timber tide
#

I've seen popular assets making one with visual scripting, one of which I got from humble bundle so that's an option, but otherwise I'd do SOs with a dialogue binary tree

twilit dirge
#

SOs with a dialogue binary tree?

timber tide
#

or any type of node based data struct

languid spire
#

presuming aspectRatio is a float

timber tide
#

Disco Elysium uses it I heard

twilit dirge
#

Seems like a waste of money. I just want to see approaches of how I would efficiently retrieve the dialogue I need

#

there isn't going to be much dialogue choices in the game anyway

#

not to that extent

languid spire
timber tide
#

if it's just not choice based then just giving every npc some dialogue by inserting an SO into them seems viable enough

languid spire
#

problem with that approach is that all the text will be loaded at startup

twilit dirge
#

Well, all my characters are randomly generated with personality types, and each one has like 500 lines of dialogue

scarlet skiff
#

is there a way to only play the last part on an animation depending on what hte last animation was?

charred spoke
#

Its also free

charred spoke
wicked bolt
#

Can I change the name of a prefab as its instantiated?

languid spire
eternal needle
wicked bolt
#

right

#
    {
        GameObject g = new GameObject("X:"+x+" Y:"+y);
        g.transform.position = new Vector3(x -(horizontal - 0.5f), y -(vertical - 0.5f));``` is what I had
#

but im tryna make it load a prefab instead

#

then get its name

wicked bolt
frank flare
#

When I press a or d then unpress d and press a it seem to make a bigger force. Why?

if (rb.velocity.x > 0)
        {
            rb.AddForce(-transform.right * 800f);
        }
        else if (Mathf.Abs(rb.velocity.x) < 10f)
        {
            rb.AddForce(-transform.right * 650f);
            Debug.Log($"a The current velocity: {rb.velocity.x}");
        }
        else if (Mathf.Abs(rb.velocity.x) < 40f)
        {
            rb.AddForce(-transform.right * 800f);
            Debug.Log($"b The current velocity: {rb.velocity.x}");
        }
eternal needle
wicked bolt
#

Sorry, should have been more specific

#

tryna make a 2d grid

#
{
    public Sprite sprite;
    public float [,] grid;
    public int columns, rows, vertical, horizontal;
    public bool render;
    // Start is called before the first frame update
    void Start()
    {
        render = false;
        Debug.Log("Screen Width : " + Screen.width);
        vertical = (int)Camera.main.orthographicSize;
        horizontal = vertical * Screen.width / Screen.height;
        columns = horizontal * 2;
        rows = vertical * 2;

        grid = new float[columns, rows];
    }

    void Update()
    {
        for (int i = 0; i < columns; i++)
        {
            for (int j = 0; j < rows; j++)
            {
                while (render == true)
                {
                spawnTile(i, j, grid[i,j]);
                bool render = false;
                }
            }
        }
    }

    private void spawnTile(int x, int y, float value)
    {
        GameObject g = new GameObject("X:"+x+" Y:"+y);
        g.transform.position = new Vector3(x -(horizontal - 0.5f), y -(vertical - 0.5f));
        var s = g.AddComponent<SpriteRenderer>();
        s.sprite = sprite;
        s.color = new Color(value, value, value);            
        

    }
}``` this is the version that makes a new gameobject for each grid tile
#
{
    public Sprite sprite;
    public GameObject g;
    public float [,] grid;
    public bool render;
    public int columns, rows, vertical, horizontal, size;
    public float aspectRatio;

    void Start()
    {
        //Debug.Log Shit
        Debug.Log("Fetching screen dimensions...");
        Debug.Log("Screen resolution : " + Screen.width + "x" + Screen.height);
        aspectRatio = (Screen.width / Screen.height);
        Debug.Log("Aspect ratio : " + aspectRatio);

        //Mathy Shit
        vertical = (int)Camera.main.orthographicSize;
        horizontal = vertical * Screen.width / Screen.height;
        columns = horizontal * size;
        rows = vertical * size;
        grid = new float[columns, rows];
        for (int i = 0; i < columns; i++)
        {
            for (int j = 0; j < rows; j++)
            {
                spawnTile(i, j, grid[i,j]);
            }
        }

    }

    private void spawnTile(int x, int y, float value)
    {
        GameObject g = g("X:"+x+" Y:"+y);
        g.transform.position = new Vector3(x -(horizontal - 0.5f), y -(vertical - 0.5f));
        if (render == true)        
        {
            var s = g.AddComponent<SpriteRenderer>();        
            s.sprite = sprite;
            s.color = new Color(value, value, value);
        }
    }
}``` This ones the one im tryna have use prefabs
#

Oh, those are a little large

#

my bad

rocky lava
#

im trying to code, but i have this issue, im sorry if this is an incredibly dumb question but i genuinely dont know what im doing wrong

frank flare
languid spire
rugged aspen
#

Does anyone know how I can deserialize a JSON file?
I do not want to deserialize it to an object, I just want to get some values out of the file

rocky lava
languid spire
rugged aspen
languid spire
#

you could read the file as a string and do string searches on it

eternal needle
eternal falconBOT
languid spire
#

so parse it yourself in effect

rugged aspen
#

is there nothing native in Unity, like the json package in Python for example? I know there is System.Text.Json but it isn't part of Unity

eternal needle
languid spire
#

you said you did not want to deserialize to an object

rugged aspen
rugged aspen
eternal needle
#

Just get the full object, grab the values you want and ignore the rest.

languid spire
#

then you have no choice

#

you cannot part deserialize json

wicked bolt
eternal needle
#

String search here is your only other option, and it is a terrible option to do.

eternal needle
wicked bolt
#

though has since been slightly tweaked per bawsi's suggestion

languid spire
#

but you've changed it and made a mistake

rugged aspen
#

Do you guys know if I can include Newtonsoft.JSON? Cause I saw that Unity supports that

#

is it a package I can include from the PackageManager?

rocky lava
#

am i not able to somehow drag the text into the score text script? the person whose tutorial im following does it without any issues

languid spire
#

yes, but that will not address your original question

languid spire
rocky lava
modest dust
rugged aspen
#

I just installed Newtonsoft.Json and I think I'll use that
but thank you anyways

wicked bolt
#

Well

#

thats 1 step foward

#

for some reason

#

its only created 2 tho

#

ones huge

#

the other doesnt seem to render anything

#

Oh

#

the other has no sprite renderer

#

setting the sprites pixels per unit lower just made it bigger?

#

It only has issues when I set render to true

#
UnityEngine.GameObject:AddComponent<UnityEngine.SpriteRenderer> ()
gridManagerAlt:spawnTile (int,int,single) (at Assets/gridManagerAlt.cs:45)
gridManagerAlt:Start () (at Assets/gridManagerAlt.cs:33)
#
gridManagerAlt.spawnTile (System.Int32 x, System.Int32 y, System.Single value) (at Assets/gridManagerAlt.cs:46)
gridManagerAlt.Start () (at Assets/gridManagerAlt.cs:33)```
#

Only makes one clone

languid spire
#

again post your latest code

wicked bolt
#

private void spawnTile(int x, int y, float value)
{
GameObject g10 = Instantiate(g);
g.transform.position = new Vector3(x -(horizontal - 0.5f), y -(vertical - 0.5f));
if (render == true)
{
var s = g.AddComponent<SpriteRenderer>();
s.sprite = sprite;
s.color = new Color(value, value, value);
}
}
}

languid spire
#

now read it, your errors are obvious

#

remember g10 is now a new copy of g

wicked bolt
#

Do I have to give it a new name everytime spawnTile is run?

#

no that wouldnt make sense

languid spire
#

no, but look at the objects you are trying to change

wicked bolt
#

ah

languid spire
#

look at this
GameObject g10 = Instantiate(g);
g.transform.position = new Vector3(x -(horizontal - 0.5f), y -(vertical - 0.5f));
Do you want to move the NEW GO or the Original?

wicked bolt
#

the new

languid spire
#

so do that

wicked bolt
#

original is never loaded

wicked bolt
languid spire
#

no it doesn't

wicked bolt
#

render == true

#

render == false

quick pollen
#

Is there a way to make it so an input starts being set to 0 on a condition?

languid spire
#

you are missing the point
GameObject g10 = Instantiate(g);
g.transform.position = new Vector3(x -(horizontal - 0.5f), y -(vertical - 0.5f));
changes the position of the original
you need
GameObject g10 = Instantiate(g);
g10.transform.position = new Vector3(x -(horizontal - 0.5f), y -(vertical - 0.5f));
to change the position of the new object
and the same is true of you add component

quick pollen
#

runModifierVert = _runModifier * Input.GetAxis("Running") * Input.GetAxis("Vertical") * baseSpeed * (stamina > 0? 1 : 0);
I have this method here for making the player accelerate and deaccelerate gradually if they hold down or release the "Running" button but I want it to gradually decrease as if the key was released if the stamina hits 0

#

rn * (stamina > 0? 1 : 0) just instantly stops movement

languid spire
#

what is the result of anything when you multiply by zero?

languid spire
#

wrong

wicked bolt
#

Thats

#

progress

#

Renders normally again

#

though I cant for the life of me guess why it wont line up with the Camera

#

And its

#

waaaay bigger than the camera

craggy oxide
#

IEnumerator LerpFunction(Color endValue, float duration)
{
float time = 0;
Color startValue = materialToChange.color;
while (time < duration)
{
materialToChange.color = Color.Lerp(startValue, endValue, time / duration);
time += Time.deltaTime;
yield return null;
}
materialToChange.color = endValue;
}

I'm confused about this code (it's apparently a successful Color.Lerp)
How does the Color.Lerp know which 2nd colour to lerp with, if its defined afterwards?

#

the "endValue" variable isn't defined until the end in "materialToChange.color = endValue;"
no?

modest dust
#

What

#

endValue is passed as a parameter into LerpFunction

#

it is defined from the very beginning

craggy oxide
#

yeah but its only defined as a color

#

is there a default color or smth

#

its not given any values like Color.White or even RGB floats

modest dust
#

Do you know how functions work?

#
void DoStuff(Color color)
{
  ...
}

...
Color myColor = new Color(0.5f, 0.5f, 1f, 1f);
DoStuff(myColor);
craggy oxide
#

yeah but its defined as materialToChange.color = endValue; at the end

#

in your code example you gave it value at the end, thats what i expected

#

its not given any value in the code i sent except for materialToChange.color

#

which is just the Color.Lerp that already uses oit

modest dust
#

endValue is being assigned the moment you call the function from elsewhere

languid spire
craggy oxide
#

ohh wait i think i see now

#

so materialToChange.color = endValue; means that materialToChange.color is a Color

#

still though, i don't understand the Color.Lerp

#

if endValue is defined as a Color and nothing else

#

wouldnt the Color.Lerp be (materialToChange.color, Color, Time.deltaTime);

#

or am i wrong

languid spire
#

very wrong

craggy oxide
#

alright walk me through how it works

craggy oxide
#

bro no

#

ive already read that

#

it didnt explain anything to me thats why im here

modest dust
#

Read it again

craggy oxide
#

i understand how Color.Lerp in general works i just dont get this specific example because the things dont have values (from my perspective)

languid spire
#

why do you think that?

craggy oxide
#

it says Color.Lerp(startValue, endValue, time/duration);

gaunt ice
#

for each color channel, the return value=
start.channel *(1-t) +end.channel *t

craggy oxide
modest dust
#

They literally are defined as a Color

gaunt ice
#

color has three floats (or four if you needs a)

modest dust
#

You don't pass the type into a function if that's what you mean, just the variable name

languid spire
#

Look at this

Color startValue = materialToChange.color;
        while (time < duration)
        {
            materialToChange.color = Color.Lerp(startValue, endValue, time / duration);
            time += Time.deltaTime;
            yield return null;
        }

The start value is the original materialToChange.color Color
The end value (i.e. the Color to go to) is passed IN as a parameter of the method
it's that simple

craggy oxide
#

IEnumerator LerpFunction(Color endValue, float duration) // Defining endValue and duration

Color startValue = materialToChange.color; // Defining startValue

float time = 0; // Defining time

materialToChange.color = Color.Lerp(startValue, endValue, time / duration); // The Lerp

hows this work if startValue isnt given actual value yet and neither is endValue (besides being called a color)

#

sorry didnt read your thing i was writing this

#

ill read it now

#

ohhh right yeah

#

okay so that has value then

#

still don't get endValue tho

languid spire
#

how do you call this method?

north kiln
#

It's passed when you call the method. That's how method parameters work.

modest dust
#

Dear lord, please go through a C# course

craggy oxide
north kiln
#

No.

craggy oxide
#

so... when you call the function.. it gains value?

gaunt ice
#
public void method(int x){}
method(10);
```so what is the value of x in the method
craggy oxide
#

10?

#

ooooooooooooooohh

#

so endValue is defined IN the method calling

north kiln
craggy oxide
#

ive already done that lmao

#

don't say do it again

#

i think i get it now anyway

modest dust
#

Do it again

north kiln
#

Then, pay more attention, because damn this is the second tutorial

craggy oxide
#

so when the LerpFunction is called

#

it'll say like...

#

LerpFunction(Color.White, 5f)

#

defining the duration and endValue?

rocky lava
#

it says it's not assigned, but it clearly is? or am i dumb

craggy oxide
#

im actually way ahead

#

im on the Lerp course

north kiln
rocky lava
north kiln
eternal falconBOT
rocky lava
#

ok hold on

north kiln
#

And neither of those are searching the scene

rocky lava
modest dust
# craggy oxide i do take courses its just i'm an idiot sometimes lol

Go through a pure C# course first, since your problems are related to how basic programming works.
Make sure you understand everything more or less and then start with Unity, otherwise you're gonna have a massive amount of basic issues not even related to Unity along the way.

scarlet skiff
#

does this not play the end of the animation, like the last frame?

craggy oxide
#

cmon man i just made a mistake im a lil forgetful

#

fair enough its a simple mistake but i know C#

#

...relatively

#

....the basics

frosty hound
#

You all humour this, don't get upset when you're stuck explaining the basics.

modest dust
craggy oxide
#

thank you for the help

#

and advice

modest dust
craggy oxide
#

yeah thats fair

trail heart
craggy oxide
#

what are the main uses for Destroy

rare basin
#

to destroy gameobjects

#

or components

craggy oxide
#

like why would you want to destroy GameObjects though

#

what are the common uses

rare basin
#

what even is this question xd

craggy oxide
#

bro what even are your answers ngl

#

im just asking what Destroy is commonly used for, like in what context or scenario its useful

rare basin
#

you kill a enemy, what happens then?

craggy oxide
#

so its used to clean up unnecessary objects?

rare basin
#

it's removeing a GameObject, component or asset

#

imagine having hack&slash game

#

where you have 200 enemies, shoot projectiles

#

why would you keep alive(dead) enemy/used bullet particles objects on the scene

craggy oxide
#

i dunno, detail?

rare basin
#

(unless we're talking about object pooling but im simplyfing)

craggy oxide
#

keep the corpses there

#

alright so its used for cleaning up unnecessary objects

#

cool

#

any other uses?

rare basin
#

you can just google it in 10 seconds

craggy oxide
#

or you could have answered in 5

#

screw it

rare basin
#

im respecting my time, won't be your "google" 😛

dapper egret
rare basin
#

that's what i said later

abstract silo
#

Anyone know how to work with AR?

dapper egret
rare basin
abstract silo
rare basin
#

then dont cross-post

queen adder
#

Is there an OnValidate that also happens when a child object count was increased? For a CircularLayoutGroup that I made

timber tide
#

Sounds tricky, but maybe some subscription model you can set up

queen adder
#

that's nasty ig

timber tide
#

it would mostly be the object you're adding sending a callback to the parent

timber tide
#

instead of the parent continuously checking for new children

#

could be some interface unity has but idk

queen adder
#

unless that sprite was like supposed to be 4k

queen adder
slender nymph
#

why not just inherit from unity's LayoutGroup if you want the class to behave like one?