#💻┃code-beginner

1 messages · Page 33 of 1

short hazel
#

And for the error, just expose a getter for the property. Do not declare the field

tender stag
#

oh alright

#

yeah works

#

thanks you

short hazel
#

I'd rename SetDurability to something else, since it does way more than just setting the durability

#

Something like UpdateDurability

tender stag
#

whats wrong?

short hazel
#

Properties must be in PascalCase

#

Won't fix the error, but at least the naming conventions are applied

polar acorn
short hazel
#

Errors, these are fields in your class, not properties

tender stag
#

so like this?

short hazel
#

[field: SerializeField] public float Durability { get; set; } -- pretty much the same as in the interface decl

rich adder
#

so how do i know how you sset this up ?

#

provides no context then asks for help . A+ kid

#

then insult help

#

smart

#

w/e fuck this..

tender stag
#

i cant have a header

short hazel
#

Target the field too :)

tender stag
#

thanks so much

#

much cleaner now

rich adder
#

go drink a glass of milk kiddo

queen adder
#

can anyone dm i need help with starting to code simple player movement

broken hazel
#

I, uh, need a little help with - same

tender stag
#

what is bro yapping about

rich adder
#

Idk must be projecting

short hazel
#

God the discussion quality just dropped so low it underflowed

summer stump
#

<@&502884371011731486>

rich adder
#

its just sum little kid

north kiln
#

!mute 470339223401136149

eternal falconBOT
#

dynoSuccess ollywanted77 was muted.

short hazel
#

@queen adder + @broken hazel - Ask here. Read the #854851968446365696 for instructions on how to ask a proper question here. No DMs, conversations are always 100% here for everyone to see and chip in if they want

tender stag
#

yeah so one last thinggg

#

lmao

queen adder
#

!code

eternal falconBOT
#
Posting code

📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

tender stag
#

is there any way to default it to 100?

#

like durability and max durability

#

on default

rich adder
short hazel
#

Sure, after the accessors declaration

#

... { get; set; } = 100;

tender stag
#

yup works

#

properties are so cool

broken hazel
#

Sry

tender stag
#

i didnt know they were so useful

short hazel
#

Switch expressions? Compiles to a bunch of if statements

#

etc.

broken hazel
#

Can some help me with character controls? I've look some up before but they were only allowing me to look in one direction. I believe this is how I ask

tender stag
broken hazel
#

Um just to get a capsule to move in all directions

#

Idk how to put it

tender stag
#

dm me

swift crag
broken hazel
#

It won't let me DM you

tender stag
#

accept friend request

wintry quarry
#

Camera Rotation isnt clamped to Time.deltaTime
What on earth does this mean?

#

YOu have to show code

#

but yeah that was a really weird way of saying "my code is framerate dependent, help"

#

this is good and fine

#

there is no need for deltaTime here

#

mouse input is already framerate independent

#

adding deltaTime in this calculation would be erroneous

tender stag
#

how do i make a formula to calculate the amount i need to add to the break percentage?
durableItem.BreakPercentage += Random.Range(12.5f, 25f);

#

like for example my ak has 100 MaxDurability and the Durability can go between max and 0

#

like i want it to add more to the break percentage the more then item is broken

#

so the lower Durability the more to add to BreakPercentage

#

did this
durableItem.BreakPercentage += (durableItem.MaxDurability - durableItem.Durability) / durableItem.MaxDurability * 35;

eternal needle
#

this is python..

crisp token
cobalt granite
#

If I want to make a sphere grow over 2 seconds smoothly how do I go about that within a coroutine?

rich adder
modest dust
#
for (float t = 0; t < 2; t += Time.deltaTime)
{
   // Size Lerp here with progress being t / 2
   yield return null;
}```
rich adder
#

timer = 2f;
currentTime= 0;
while( currentTIme < timer){
//scale sphere
currentTime+= Time.deltaTime
yield return null;}

cobalt granite
#

Okay thank you, these helped a lot

rich adder
modest dust
#

I rarely ever use while loops

#

unless it's a boolean or something more complex

rich adder
modest dust
#

scary while loops 👻

#

basically a for loop, but you declare and update everything out of the () scope

#

well, you could update within () but that's just weird

#

Anyways, caesar out, time for some programming dreams

amber spruce
#

so i have it to my player can eat objects to get bigger but the camera doesnt get further away or anything so the player fills up the whole screen how do i fix this

rich adder
#

make it move on Z a bit

#

add offset if you use cinemachine

amber spruce
#

so im using cinemachine

#

how do i offset it

rich adder
amber spruce
#

i cant find one

static cedar
#

I use tupples to declare multiple stuff in a for loop too often. UnityChanPanicWork

amber spruce
rich adder
amber spruce
#

how do i change that via a script

swift crag
#

store a reference to the CinemachineCameraOffset and modify it

rich adder
#

yeah just store it

#

since ull change it often

amber spruce
#

what do i put for sumValue

#

do i change that at all

rich adder
amber spruce
#

yeah i gotta do a refresh tutorial lol

rich adder
amber spruce
#

no lol

#

not sure how to

#

also the var i assume thats my variable right

rich adder
#

forget the code right now

#

in playmode, change the offset in the inspector

#

on the component

amber spruce
#

yeah i did that

rich adder
#

ok so which Z value looks fine when you have big sphere?

amber spruce
#

well it will always get bigger

#

so it should just increase by a certain amount

rich adder
#

thats why its a variable

#

so you can change it every time you change size

old lance
#

hi so i recentley created an organization with my friend and i made a project how do i get him on it

rich adder
#

just make sure u store the reference so you don't get it everytime u change value

amber spruce
#

would this not work. just changing the offset plus the variable

rich adder
amber spruce
#

so like offset += var

#

i think thats the right syntax

rich adder
#

you can just add an offset + size of sphere

#

so you have a consistent value

amber spruce
#

oh ok that sounds way better

#

how would i do that though

amber spruce
unreal imp
#

How do I ensure that the script for my object does not affect his childrens except for one specific?

rich adder
amber spruce
#

where do i put that

rich adder
#

wherever you change your sphere size?

#

how does sphere grow?

teal viper
amber spruce
rich adder
#

um

#

you copied variables that u prob dont have

#

don't just blindly copy

amber spruce
#

which are variables?

rich adder
#

the ones that error says don't exist..

amber spruce
#

so for the first one should this be the variable

    public CinemachineVirtualCamera cinemachineOffset;
rich adder
#

no CinemachineVirtualCamera is not the right component

#

think back to which one you're trying to change..

amber spruce
#

oh

#
    public CinemachineCameraOffset cinemachineOffset;
#

that

rich adder
#

you probably want an additional parameter to adjust the offset

#

incase magnitude alone will create too much of prefix distance

#

[SerializeField] private float offset = 0.2f; // try different values, positive value = closer to sphere

cinemachineOffset.m_Offset = new Vector3(0, 0, -sphere.transform.localScale.magnitude + offset) ;

#

@amber spruce

amber spruce
#

so for some reason the more it gets bigger it makes it so you cant move the angle your looking at higher so you end up looking threough the ground

rich adder
#

you'd need to add a Cinemachine collider

#

mind you this isn't the way to do, just a way to do it. for Free Look it gets more tricky too

amber spruce
rich adder
#

*Extension

amber spruce
#

still ends up being like this

rich adder
amber spruce
#

my camera cant go further from that so i cant look straight

rich adder
#

play around with all 3 rigs

#

i just tested it on the default cam and it worked for m

amber spruce
#

weird

#

thats my collider

rich adder
rich adder
amber spruce
#

this??

rich adder
#

they determine your look angles per rig

amber spruce
#

should i change that

rich adder
amber spruce
#

aight

amber spruce
rich adder
#

as you change that you have to change the height/radius on rig

#

play with the values until its correct

amber spruce
#

so like i cant just keep looking up thats my problem

#

that changes the rotation doesnt stop me from going to high

rich adder
nova vortex
#

im tryig to build the facepunch.steamworks

#

and it just :(

#

anyone know how I fix this

amber spruce
#

i cant look any further up

#

normally its fine

#

but when i get big it aint

rich adder
#

yeah I think that will work better..

#

remove the FollowOffset

#

try this instead

        freelook.m_Orbits[0].m_Radius = sphere.transform.localScale.magnitude + offsetTop;
        freelook.m_Orbits[1].m_Radius = sphere.transform.localScale.magnitude + offsetMid;
        freelook.m_Orbits[2].m_Radius = sphere.transform.localScale.magnitude + offsetBottom;```
sour fulcrum
#

Dipping my toes into how Matrices work and stuff and think just some names are throwing me off

If I set an objects Gizmos.matrix to transform.localToWorldMatrix or transform.worldToLocalMatrix. Is that literally just the same of having it's origin be based on the objects local and world values straight up? the names of the properties had me wondering if theres anything else being added but I just need someone smarter than me to clarify ❤️

amber spruce
rich adder
#

CinemachineCameraOffset

#

this clips you through the floor

amber spruce
#

so that

rich adder
#

ye

amber spruce
#

what do i put for freelook and offsetbottom, mid, and top

azure zenith
#

Is it okay to use Destroy.() for collecting ammunition?

amber spruce
rich adder
#
        freelook.m_Orbits[0].m_Radius = sphere.transform.localScale.magnitude + offsetTop;
        freelook.m_Orbits[1].m_Radius = sphere.transform.localScale.magnitude + offsetMid;
        freelook.m_Orbits[2].m_Radius = sphere.transform.localScale.magnitude + offsetBottom;```
the order is reversed tho, i edited old msg
rich adder
azure zenith
#

Collecting any gameobjects

rich adder
#

as long as they're not stored in a list sure

#

destroying and instantiating comes at a cost, ideally you want to re-use the same objects with pooling

azure zenith
#

Interesting

#

Why would you want to use a list?

#

Is that when all the items are the same?

rich adder
#

like if you have collectables or something

azure zenith
#

Oh, okay

amber spruce
rich adder
amber spruce
#

you had me get rid of offset though

rich adder
#

the variables you just made dude

ashen ferry
#

is putting all events from all scripts in one dedicated mega events script anyone can run/subscribe a thing cause im boutta do it to eradicate some macaroni

amber spruce
#

changing them doesnt do anything'

rich adder
amber spruce
#

inspector

rich adder
amber spruce
#

gizmos??

#

i gotta go for tonight i will continue this in the morning

rich adder
livid jacinth
#

I'm getting an error and I'm not entirely sure why, maybe someone can point me into the right direction? I have a script added to a game object as a component, that script has an empty array in it. When I try to change the size of the array in the inspector, it completely removes the array and the ability to change the size of it and a wall of text comes up in the console starting with "NullReferenceException: SerializedObject of SerializedProperty has been Disposed."

#

I can put the rest of it in a pastebin if more is needed

livid jacinth
#

yes i am

#

Also, it may make a difference, I'm trying to edit it on a prefab, not in any scene

#

Hm, it seems to work if I open the prefab and not just click on it once in the project folder

rich adder
#

2022 is buggy af

#

i get spammed with those on 2022.3.3

#

try to update to latest patch if you're not on it

livid jacinth
#

I'm on 2022.3.10f.1

#

I'll have to double check but I think that's the latest one

rich adder
#

I think its 11 but for me it fixed those errors at least, hmm not sure maybe its a script?

livid jacinth
#

It's giving me references to other scripts like "UnityEditor.SerializedProperty.get_intValue () (at /Users/bokken/build/output/unity/unity/Editor/Mono/SerializedProperty.bindings.cs:996)"

and when I click on it to inspect it, it opens up and there's nothing in there

#

It was working fine until like 10 minutes ago

rich adder
#

try removing it

#

or restat unity / default layout

livid jacinth
#

I tried to change an array to be able to use nested arrays, when I declared the variable I used [][] instead of just [] and it went up in flames

rich adder
#

ohhh

livid jacinth
#

Then when I changed it back to just [], it's still giving me issues

#

I installed version control but I haven't done anything with it yet unfortunately

rich adder
#

but I don't know if it would blow up like that just changing it once array was serialized

livid jacinth
#

It removed the elements entirely and I figured "ok i guess it doesn't work like that", changed the script back and now it's doing this lmao

rich adder
#

just tried it and it doesn't blow up for me

livid jacinth
#

I may have to try changing the editor version then

hybrid karma
#

why when i set a float to "0.8f" it becomes "0.800000011920929"

livid jacinth
#

oh i forgot I also tried to do [ , ] as well thinking it would do the same thing

hybrid karma
#

right but how do i make it actually 0.8

sour fulcrum
#

you dont

livid jacinth
#

you could try using double instead of float

slender nymph
hybrid karma
#

0.800000011920929 is greater than 0.8

slender nymph
#

what are you actually trying to achieve

hybrid karma
#

when i compare the variable to 0.8f it says the variable is greater, i need it to not do that

slender nymph
#

let me guess, you're trying to use == with floats?

hybrid karma
#

yeah

livid jacinth
#

Math.Round(yourNumber, 1) will round it to the nearest tenth

slender nymph
#

yeah that's your problem. use Mathf.Approximately when comparing floats

livid jacinth
#

Also that

rich adder
hybrid karma
#

but why is a variable i set to 0.8f different to 0.8f

rich adder
#

because float point imprecision

#

you should look that up

rich adder
sour fulcrum
slender nymph
#

and the crumbs. those are parts of pieces
and the inaccuracies in floats are like the crumbs

polar acorn
#

Imagine you had 100 index cards to write every number between 1 and 1000. You can't give each card its own number, so you put some of the commonly used numbers on the cards and accept that if someone picks something else, they're gonna get "close enough"

hybrid karma
#

i have to rewrite my scripts because 0.8 =/= 0.8

polar acorn
#

If someone asks for 84 and your closest card is 85, if they handed someone their 85 and said "hey is this equal to 84?" the answer would be "no"

summer stump
#

Note that this is not about c# or unity or anything. It is inherent in computers

polar acorn
summer stump
polar acorn
#

just use Mathf.Approximately

rich adder
#
   public static bool Approximately(float a, float b)
        {
            return Abs(b - a) < Max(1E-06f * Max(Abs(a), Abs(b)), Epsilon * 8f);
        }```
🙂 behind the scenes the magic
hybrid karma
#

whats the thing for <= and >=

polar acorn
sour fulcrum
#

if firstValue is greater than secondValue or firstValue is equal to secondValue

#

it's two checks built into one for convenience 😄

hybrid karma
#

no for floats

summer stump
slender nymph
hybrid karma
#

what

rich adder
#

thats what you would use when you dont use Math.Approx

#

> < <= >=

summer stump
# hybrid karma what

Floating point imprecisions means they won't be exactly equal 🤷‍♂️

But less than and greater than can be easily checked. Why would there be anything else?

hybrid karma
#

but if i do var <= 0.8 and var is 0.800000011920929 it will say its greater instead of equal

hybrid karma
#

so what is the <= version of approximately

summer stump
slender nymph
polar acorn
#

Don't expect equals to be equals

#

But less than works fine

north kiln
#

Perhaps start a thread too

sour fulcrum
#

theres no easy way to use Gizmos.DrawCube in a function outside of OnDrawGizmos or OnDrawGizmosSelected right

north kiln
#

Nope

sour fulcrum
#

pain

north kiln
sour fulcrum
#

Ooo I might peep this then

#

Actually if you have a sec, I don't really know how to articulate my issue without a massive text dump but tl;dr I'm trying to rotate a gizmos to reflect my transforms rotation but when I set the gizmos matrix to my transforms localmatrix the drawing im trying to do is wrong because my positions im using already have the transform.localPosition baked in so its getting added twice.

currently i wanted to try and make a custom DrawCube function that basicially -='s my position so it like offsets it correctly but on the drawcube function side so i dont have to change my position directly

#

if that makes any lick of sense

north kiln
#

You should set it to the transform's matrix and then work locally, so the position of the object is at Vector3.zero

sour fulcrum
#

I'm trying to do most stuff locally but I do need to consider world stuff for the game mechanic i'm trying to pull off aswell

I have a 3d tile matrix that I have "synced" to it's transform position but I want the parent of that object to be able to move and rotate aswell

livid jacinth
#

lmao I tried changing it to the new version of the editor and it's still happening

ashen ferry
#

is class holding all the events anyone can run and subscribe to a thing lol

sour fulcrum
#

I have this cute little 3d matrix here that stores all my tiles but this is going to end up being a cube like this so I can rotate and move the Planet's object that's in the center and have each face-child and their respective 3d matrix adjust correctly

#

forgive my terrible perspective drawing skills

queen adder
#

how to unselect object in eventsystem?

#

nvm it have its method

topaz mortar
dim wharf
#

Is there any way for the Execute() to know who did the method call without putting my object as a parameter? Want to make things look generic

dim wharf
#

considering the observer pattern

wheat hull
dim wharf
#

yes

wheat hull
#

and you want the action to have the information of which object did the call

dim wharf
#

yes

wheat hull
#

yeah im pretty sure the only way to do that is by passing the object as a parameter, but I dont see that being a problem in any way.

dim wharf
#

Maybe you're right. I was simply obssessing on trying to make it look clean

wheat hull
#

yeah i get what you mean, although what exactly are you trying to do ?

#

why do you need the action to know which class called it

dim wharf
#

the playerClass has an int damage and the UnitAction im currently executing is a Strike(target)

#

I just want it to look like player.doAction(new Strike(target))

#

simply adding the player to the parameter makes things much simpler tho lol

wheat hull
#

but where is the action ?

eternal needle
wheat hull
#

is that in a separate class ?

dim wharf
#

it looks something like this

wheat hull
#

Im trying to understand why you need to know which class called the action

dim wharf
#

yes it is in a separete class

#

and tested it like this

#

the book I'm following (that teaches about the command pattern) passes the doer of the action as well. I guess I'll just surrender and do that as well

wheat hull
#

if you really need to know where the action is being called then sure, but I dont know if this is the best way in general to approach what you are doing.

light moss
#

I want to make the Enemy Jump every 2 seconds however the enemy GameObject isn't doing that. What is wrong with my code?

teal viper
summer stump
light moss
#

Yeah I have. I think an issue might be with my Waypoint Follower script. I think that may interfere with this script

summer stump
#

If you are setting velocity in it, it will override the jump

light moss
#

This is my Waypoint Follower script I have for my Enemy. I do not see how this can interfere with the Enemy Jump Script

#

Even when I disable the Waypoint Follower, the Jump script still does not work

summer stump
#

You are directly setting the transform in this script. Which is kinda like teleporting

#

which would probably interfere. But it doesn't affect velocity (teleporting doesn't impart velocity), so I dunno

#

Generally you don't wanna mix rigidbody and transform based movement.

#

It can work, but you gotta be careful.

topaz mortar
young warren
#

Because it went behind the camera I assume

topaz mortar
#

oh, didn't know that could happen

light moss
#

I'm an idiot. I forgot to add the Rigidbody2d Component

summer stump
#

Ha, I was just about to say, "Wait, do you have a Rigidbod- wait where'd the video go?"

#

Good job getting it on your own though

teal viper
eternal needle
light moss
#

This is my first Unity game so I have a lot to learn. I will check console more often thank you

distant mesa
#

is there a way to put Pose variables together? like Pose + Pose to merge the values?

sour fulcrum
#

your example is just how it works yeah

#

myValue = myValue + myOtherValue

adds your othervalue to your value, a shorter way of doing it is

myValue += myOtherValue

or if you want a new combination value

myCombinedValue = myValue + myOtherValue

distant mesa
#

i keep getting this error tho

teal viper
#

What type is it?

distant mesa
#

im new to this so i dont fully understand it

teal viper
distant mesa
#

hmm okay

sour fulcrum
#

When a parent transform has rotation and a child transform changes its world rotation and world position to reflect that change, what is it actually doing calculation wise?

gaunt ice
#

apply the same transformation matrix to all children

sour fulcrum
#

I don't understand what you mean by this

teal viper
# sour fulcrum I don't understand what you mean by this

Position+rotation+scale are represented as a matrix internally. You can do some matrix math to rotate/move/scale objects. When a parent transform is changed, it's transformation matrix is recalculated and applied to all the children.
Or something like that.

sour fulcrum
#

Do you know what i'd want to look into if I want to do that myself?

#

I have a 3d array of positions and I want to apply my transforms values to them like each of them were children

gaunt ice
#

you can learn the math but strongly suggest you dont recode the math yourself, you can learn how to use matrix4x4 etc

sour fulcrum
#

Oh yeah I have no desire to be like a super wizard nerd in this regard, my goal is just to re-create the end result

#

advice on utilising whats already there via matrix functions would be more than ideal

sour fulcrum
#

I've looked at this a few times over the last day or so and while I understand there are things I would want to use there. I don't have the math comprehension to put it together

gaunt ice
#

you may get started with 2d and 3d vector and transformation math first

next hound
#

hey i am having problems when opening a script of a sprite

#

any fix?

teal viper
#

!vs

eternal falconBOT
#
Visual Studio guide

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

Visual Studio (Installed via Unity Hub)
Visual Studio (Installed manually)

next hound
#

how

burnt vapor
next hound
#

ok

hollow orbit
#

hey, followed a tutorial for a basic enemy ai, but it gets stuck on the edges of platforms. is there a simple fix for this?

#

maybe not edges of platforms specifically, but the edges of the mesh

teal viper
hollow orbit
#

what do you need

gaunt ice
#

tutorial, script, what part the script fails

light moss
#

For some reason my Enemy Way Pointer Destroyer Script does not have a Checkboxto disable it. How can I fix that?

slender nymph
#

that means it has no unity messages that only run when it is enabled

#

in other words, disabling it will do literally nothing

light moss
#

But it would in my case

gaunt ice
#

maybe it is requried by other component

light moss
#

It will prevent the enemy from freezing

slender nymph
#

how

#

are you checking that the component is enabled anywhere?

light moss
#

This is the script

slender nymph
#

okay so disabling that will do literally nothing at all

light moss
#

When I remove the component the enemy does not die which is what I want. However I would prefer that to be in a enable/disable checkbox in case I want to add it back

slender nymph
#

nothing in this component is affected by whether it is enabled or not

hollow orbit
# gaunt ice tutorial, script, what part the script fails

https://www.youtube.com/watch?v=UjkSFoLxesw&ab_channel=Dave%2FGameDevelopment
everything set up like in the video except i have a lot of elevation changes. could i be that the enemy gets stuck when it tries to go somewhere that's a different elevation but cant figure out how to get there?

FULL 3D ENEMY AI in 6 MINUTES! || Unity Tutorial:
Today I made a quick tutorial about Enemy Ai in Unity, if you have any questions just write a comment, I'll try to answer as many as I can :D

Also, don't forget to subscribe and like if you enjoyed the video! :D
See you next time.

Links:
➤ NavMesh Components: https://github.com/Unity-Technologi...

▶ Play video
ruby python
#

!code

eternal falconBOT
#
Posting code

📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

ruby python
#

Hi all,

Sooooo, I'm trying to build a pretty simple vehicle controller and at the moment I'm a little stuck on suspension stuff. I have an Empty which is the suspension 'target' that I'm trying to raycast to the ground and then move the target to the hit.point, problem I'm facing is that the target object needs to be a child of the main vehicle body, but when it is, the raycast doesn't move the object. (if I unparent it, it works fine), I'm a little confused as to why the script isn't 'overriding' the position.

Can anyone see where I'm going wrong please?

public class SuspensionTargetVPosition : MonoBehaviour
{

    [SerializeField] Transform targetWheel;
    [SerializeField] float targetHeight;


    // Update is called once per frame
    void Update()
    {
        RaycastHit hit;

        if (Physics.Raycast(transform.position, transform.TransformDirection(-Vector3.up), out hit))
        {
            Debug.Log("I hit Something");
            Vector3 groundIntersectPosition = hit.point;
            transform.position = groundIntersectPosition;
        }
    }
}
sour fulcrum
#

Is there a suggested way to stop jitter in a character controller when it get's moved by other code and/or parent transform changes?

royal ledge
#

I have encountered a bit of a structuring problem, let's see if i can explain it so it makes sense. My player has a script called "PlayerGun". If the player runs into a gun he picks it up and the guns data get copied into that script and then that script handles shooting/rotation etc. Pretty simple. Now i have encountered a problem where my guns has been getting more complicated and i feel like my script holds unecessary methods for things they don't use. For example i now have guns that create bullets that check for collision and guns that create raycasts that check for collision. So I could split up the logic into abstract classes (PlayerGun -- PlayerGun_Bullets -- PlayerGun_Raycast). But then i would have to hot-swap between components on the player, depending on what type of gun they pick up. Probably need a script on the player that handles that hot swapping too. Is this a feasible thing to do?

spare umbra
#

I have a dashing code and it workes fine

#

However when I put the player at origin and dash it sometimes goes 3.2 units and sometimes 4.8

teal viper
spare umbra
#

Ignore the debug log

teal viper
spare umbra
teal viper
# spare umbra it's same

If it's the same, then the problem might be with you relying on time instead of fixed updates count within that time period. Might want to yield yield the next fixed update(or a few in a loop).

spare umbra
#

Might want to yield yield the next fixed update(or a few in a loop).

#

What do you mean by that? Can you explain it a bit?

spare umbra
azure zenith
#

I am unable to drag and drop an AudioSource clip into another gameobject, any idea as to why?

teal viper
teal viper
spare umbra
teal viper
#

The issue is because you're trying to control the duration with time.

chrome scarab
#

[SerializeField] what does this mean?

teal viper
#

Maybe if you wait for the fixed update at the very beginning of the coroutine it might work, but if you ask me, that's still unreliable.@spare umbra

teal viper
chrome scarab
teal viper
#

It will. Just adding the attribute would serialize it. Just like a public field.

#

Assuming the object that the field belongs to is serialized as well.

chrome scarab
teal viper
#

Depends on what you're using in your save system.

winter shore
#

Hello, can someone tell me what is wrong on the underlined code and how to fix it ?

chrome scarab
winter shore
chrome scarab
#

use IsActive or Active

teal viper
chrome scarab
#

!this.Flashlight.IsActive
or
!this.Flashlight.Active

teal viper
chrome scarab
winter shore
#

It says it's an obsolete way of saying it. But works nevermind.

chrome scarab
#

!this.Flashlight.activeSelf

#

or

#

!this.Flashlight.activeInHierarchy

chrome scarab
winter shore
#

And what is the code to state if that a gameobject is unactive ?

winter shore
#

Alr

chrome scarab
# winter shore Alr

But I advise you to put a light on your flashlight object and make that light active. not the object itself.

#

Because if you close the object itself, you cannot use the object itself to open it back.

winter shore
#

So I could just deactivate the light itself ?

#

From its component ?

chrome scarab
#

If you disable the gemobject, you cannot use the scripts inside the gameobject to reactivate it. If you try to use it you will get an error.

winter shore
#

And how come you could still reactive the game object with everything with it too, right ?

#

That's an option, I tried for other gameobjects and it worked.

chrome scarab
sour fulcrum
chrome scarab
teal viper
#

Disabled objects still exist. They're not destroyed. So you shouldn't get a null reference on an existing reference.

#

If you try to find it with one of the find functions, you might not be able to, this getting null. But that's a different case.

chrome scarab
chrome scarab
#

Maybe my engine version is outdated, I'm not sure.

winter shore
#

Basically, what I want is to toggle a gameobject, which is a flashlight. I would like to be able to toggle it on and off with the same key button.

teal viper
teal viper
gaunt ice
#

call method on script on a disable object is completely fine

chrome scarab
modest dust
#

Once a gameobject is disabled all it's components are also disabled

#

so no Update, LateUpdate, Awake, etc

#

but calling manually from other active scripts still works just fine

chrome scarab
#

If you connect this script to flashlight and disable flashlight, shouldn't that script not work?

modest dust
#

Unity just won't call the methods that it normally would

#

But you can still call them externally from other scripts

chrome scarab
#

But the friend wants to activate it again from the same script file.

chrome scarab
candid oyster
#

Hey guys I wrote this very bad code thats very long. I think that I can make this shorter just by using a 2 dimensional list. Is that correct? If so, how would I go about making a 2d list. If someone could send a link to a guide or a good doc page, I would by thankful. Thanks!

candid oyster
gaunt ice
#

do you know A+1=B?

chrome scarab
gaunt ice
#

so given an coordinate [A-Z][0-9], you can get wasd direction by adding vector2.up, right etc

languid spire
candid oyster
#

Thanks

#

Ill look into these options

gaunt ice
#

btw i will not represent coordinate in forms of string

#

string is inmutable and create lots of garbage, instead try

struct{
  char row;
  char column;
}
```total 4 bytes
candid oyster
#

what does struct{} do?

burnt vapor
#

Same thing as a class but as a value type instead of a reference type. If you don't know what it is big chance you don't need it since this mostly falls under improving performance. I don't understand why it's being posted in a beginner channel to begin with.

chrome scarab
candid oyster
#

this got overwhelming

burnt vapor
candid oyster
#

is a 2d array like a 2d list?

burnt vapor
#

So it's a matter of determing the x and y position

candid oyster
#

when i searched up 2d list I saw a lot of "arrays"

burnt vapor
candid oyster
#

alr, Ill just look into arrays then

#

I think that it will be the easiest for me

burnt vapor
#

I'd say see what an array is first

#

Then perhaps look up c# Lists, and then the difference between the two (spoiler: a List is a "resizeable" array)

candid oyster
#

yes, Ill look into it

#

ty

chrome scarab
burnt vapor
#

Judging by the question, they have already grasped the basics. It doesn't hurt to point somebody in the right direction, especially since they're keen on learnng.

chrome scarab
#

Shouldn't he learn other things too?

burnt vapor
#

I suggest you advice them and not me

chrome scarab
#

It will be much more useful if him learn at least loops, methods and structures.

candid oyster
#

Guys no need to argue

chrome scarab
candid oyster
#

thanks for the help

chrome scarab
timber tide
candid oyster
#

Yeah, someone mentioned switched and dictionarys

#

Ill start learning about these

#

Never used them before

#

rn im looking into arrays tho

timber tide
#

Dictionary a little more intermediate, so look into a switch first, also look into using else/else if

candid oyster
#

I know how else/else if works :)

timber tide
#

Ah, ok just making sure your use case is correct since you're checking all values there

candid oyster
#

but thanks

timber tide
#

regardless if you found the value you want

candid oyster
#

yes, you are right

timber tide
#

you'd usually want your code to fall through once you find what you're looking for ;)

burnt vapor
candid oyster
#

okaay..

burnt vapor
#

These require a key and considering you're working with a 2d grid, nothing succeeds anything here

#

That's why I personally think you should use a 2d array, but see what suits you best

candid oyster
#

Im looking into arrays rn

#

im doing the W3 schools tutorial

static cedar
timber tide
#

looks exactly like my first tetris game I made in c++

static cedar
#

Also the 2D array is the right answer here.

#

I suggest using it as a Vector2Int rather than just two ints and then just myArray[vector2Int.x, vector2int.y].

burnt vapor
timber tide
#

2D array works but then you have to also check for wrapping around the indices, actually that's only relevant if you use a 1D array as a 2D array. I forget, need coffee.

static cedar
#

Also C.

teal viper
#

Also assembly

static cedar
gaunt ice
#

that why i said 'A'+1=='B'

somber wren
#

Hello guys, i just have this little part of code. But the hitpoint is always with Y = 0.5 i cant figure out why..

#

my plane ground is at 0, 0, 0

burnt vapor
timber tide
#

It's part of the learning process for them

somber wren
#

this is my code xd

#

i dont modifiy the hit point, and it always do Y = 0.5

#

This a typical hitpoint

gaunt ice
#

i remember plane has no height? or you use something that has "height" eg box collider?

somber wren
#

the only thing i have on my moving player is a rigibody, and the plane has juste a mesh collider

#

My ground vs my spider

slender sinew
#

look at the collider in the scene view

static cedar
# burnt vapor Hence the 2d array

Not even necessary I think.
This looks like a 4x4 box.
Just get 5 Vector2Int and do this mathematically.

Then check if any of the structs have a value of X or Y value is 0 or 5 which is unused or just invalid.

Idk why he needs it in the form of LetterNumber coordinates string but hopefully, that's not even necessary or just convert it into that after.

somber wren
#

might have checked that box to test something, wait

#

thank you! i didnt know !!

candid oyster
#

I intended to change it anyways

gaunt ice
#

show your inspector first

thick goblet
#

I have a strange issue where my player which is a cube cannot completely freeze it's transform.position.x so when I begin moving it lets say right and he freezes on the 3rd lane he starts jittering quickly left and right by a few decimals instead of remaining 0, I want the transform to stay at 0 after each freezemovement(). What's the problem? Here is the lane movement script I made: https://hatebin.com/lkvswnoqey I might have a conflicting movement left and movement right condition

timber tide
#

I don't use RB much but usually you want to use its own methods to do stuff like freeze rotations or add constraints

#

something like that? I know you can freeze rotation on the rb in the inspector itself.

static cedar
#

I think it's under the rotations tab to lock RB rotation to a certain axis.

#

There's also another field which has static in it, it might be a dropdown, which means it can't move at all.

slate badge
#

how can i write this without getting the "Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement" error.

#

because if I do allowjumping --; it says that the value cannot be null

gaunt ice
#

what is allowing jump

#

bool?

slate badge
#

a float

static cedar
#

-=

slate badge
static cedar
#

I'm assuming u want to subtract allowJunping by 1.

slate badge
#

yes

static cedar
sour fulcrum
gaunt ice
#

=- is not -=

#

thers is no =- operator

static cedar
#

=- isn't valid right? UnityChanThink

#

Real.

sour fulcrum
#

thank god for IDE's 🙏

static cedar
#

** and // should be a thing, it basically does nothing.

wintry quarry
static cedar
#

Btw, I know basic math operations follow PEMDAS but where does modulo operator fall into?

timber tide
#

probably same as MD

#

i forget

north kiln
#

just google "C# operator precedence"

static cedar
#

Seems legit.

timber tide
#

PEMDAS is just our own ruleset

#

you can always make your own and telll everyone else they are wrong

sour fulcrum
#

i put brackets around everything just incase

#

never trust anybody including yourself

static cedar
#

You're trusting the brackets tho.

sour fulcrum
#

they are tall and secure math walls and they are all i have left

static cedar
echo owl
#

Hi, I'm trying to make a sprite like the youtube video but when I click on chat bubble and try to make 2d object > sprite it shows more options than it does in the youtube video, any suggestions as to why?

gaunt ice
#

because your editorversion is newer

slate badge
#

can anyone explain what's wrong with this?

buoyant knot
#

i don’t see an issue.

#

but it does depend on other things

slate badge
buoyant knot
#

like if layer mask/collision matrix doesn’t send a collision callback

gaunt ice
#

this is trigger

north kiln
#

Go through the physics messages troubleshooting resource in the pins

buoyant knot
#

or if rigidbody isn’t configured properly

gaunt ice
#

i dont think your ground is trigger that you can pass through so you need collision

buoyant knot
#

it depends on how everything is configured.

#

it could be a trigger ground check hitbox, with solid ground collider

#

it’s hard to know without more info tbh

buoyant knot
#

i personally use oncollision so I can check normals etc, but I understand some people actually use a separate hitbox to look for ground

#

OnTriggerEnter only activates if you have a collider set to IsTrigger

#

OnCollision activates if both colliders are NOT set to IsTrigger

#

triggers are not solid, and never send force

royal ledge
#

https://gyazo.com/073b0f90f560f76920cd96df6843acd1
I've had this issue that sort have been on the back of my mind, Looking at other games in unity their bullet collision is perfect,
However, when my bullet hits the wall, the prefab for the explosion is a tad bit inside the wall. The prefab spawns in the middle of the bullet so technically it should be outside of the wall if the collision was perfect. The collision check is basically:

private void OnTriggerStay2D(Collider2D coll){
  Instantiate(explosionPrefab,transform.position,transform.rotation);
  Destroy(gameObject);
}

Things that i have tried.

  • Set Bullet rigidbody to continous,interpolation and never sleep
  • Reduced the physics time step to 0.01

I do not know what else i can do to improve it, any input is appreciated

buoyant knot
#

you can’t walk on a trigger

gaunt ice
#

yes you may have an additional hitbox to check, but in case no, use on collision enter (or attach a trigger collider hitbox on it)
the ground usually not a triggered collider

slate badge
buoyant knot
#

anyway, the code is not the issue, depending on exactly how your collider is set up

#

your code is good IF you have a trigger collider under your player checking for ground

#

that method is kind of sus, tho, because it can lead to shitty ground detection on the edges

#

if both are solid, that code will not work

#

for ground detection, there are several methods, which you can find on youtube

slate badge
#

alr thanks

#

would raycasting be a better method?

gaunt ice
#

compuational time less than overlap but you may get wrong result

ornate sparrow
#

I have 1000 objects and 1 prefab, I want to take the prefab and replace all the objects with this prefab

so that there is a blue prefab on stage

How can I do that?

buoyant knot
#

you use code to instantiate the prefab on those objects’ spots, and destroy the other objects

ornate sparrow
buoyant knot
#

I would probably make a component that allows a given object to replace itself

#

responsible for getting together the information of what to replace and all that

#

like position, scale, rotation for the new object. any parameters for the new object

#

then one singleton that has references to all hangars, and can tell them all to swap

#

or rather, a singleton that invokes an event, all hangars have that monobehaviour subscribe to that event, so when the event is triggered, they all swap

#

make sense?

royal osprey
#

Hello guys, interesting
I coded a scripts what has CrossFade functions
like CrossFade State_Changer/death and i have a rare bug
what if CrossFade State_Changer/death (one of this) started and then another... it's just buggy and like 1 in another....
or CrossFade death started but he doesn't change his animations....

ornate sparrow
candid oyster
#

it works

#

and its better then what I had before

#

so Ill leave it like this

dawn sparrow
#

Why does my IDE say the else is redundant when I uncomment the commented return line?

wintry quarry
#

since there's a return in the if, the else is not necessary since control will not continue after the return

#

it's basically an implied else

dawn sparrow
#

Ahhhhh

#

Thank you, I was pretty confused

wintry quarry
#

since you're returning data no matter what

dawn sparrow
#

true, no need for two returns

#

I'll do that

burnt vapor
spare umbra
#

I have this dashing code on my PlayerMovement script.

#

And I'm calling it from my PlayerInput script just like that

#

But when I dash player sometimes goes 3.2 and sometimes 4.8 units

#

Weird... How can I fix it?

#

I can't say it's framerate dependent because there is only 2 numbers as I said

static cedar
wintry quarry
slender path
#

anyone know how to delay a function from happening?

teal viper
slender path
#

how do i make a delay

frosty hound
#

Use a coroutine

teal viper
#

A timer in update, a coroutine, async await, etc...

spare umbra
frosty hound
#

"How do I make a coroutine"

Use code

"How do I code"

slender path
#

it is the invoke thing right

teal viper
wintry quarry
spare umbra
wintry quarry
#

Is it intentional that direction will NOT be reset/set to 0 when you release the keys?

spare umbra
wintry quarry
#

also where does dashSpeed come from?

spare umbra
wintry quarry
#

If that's never changing then it goes back to my first suggestion:

You are using WaitForSeconds which is not going to wait a constant number of physics updates

wintry quarry
#

It's a suggestion of the source of the error.

spare umbra
#

So what should I do?

wintry quarry
# spare umbra So what should I do?

if you want to wait a constant number of physics updates you should do this:

int numberOfPhysicsFrames = Mathf.CeilToInt(dashDuration / Time.fixedDeltaTime);
for (int i = 0; i < numberOfPhysicsFrames; i++) yield return new WaitForFixedUpdate();```
^replace the WaitForSeconds with this
#

you can do CeilToInt or FloorToInt, depending on if you want 0.05 to become 0.06 or 0.04 (since your fixed timestep is probably 0.02)

spare umbra
#

I saw literally 3 tutorials doing the same code for Dashing.

#

Your code is working!

#

Bro

#

The way you approach the problem..

#

*professional ✨ *

slate badge
#

Would anybody know how when reactivating a gameobject (gameobject.setactive(true) to be at the same location as the player? Because when the game object is unactive, it's position is locked

spare umbra
#

So this code is getting the number of Physics frames during the dashDuration time. And Calling the WaitForFixedUpdate() function numberOfPhysicsFrames time

#

Am I right? @wintry quarry

wintry quarry
#

This ensures that the velocity you assigned to your body is applied for the same exact amount of physics simulation time every time.

nocturne delta
#

so im working on a game that is based on laser and reflections and all
and i am trying to detect collision for one of my objects tagged "flower"
heres the detection code : public class CollisionDetection : MonoBehaviour
{

private void OnTriggerEnter(Collider other)
{
    if (other.CompareTag("Flower"))
    {
        Debug.Log("Laser hit a flower!");
    }
}

its pretty simple and i think its correct
but it doesnt detect it no matter what i do
any tips?

wintry quarry
slate badge
#

When a game object is unactive, are it's variables static? For example can you still move it when it's unactive?

nocturne delta
wintry quarry
#

you will need to add those things for this code to work

#

(you can use a kinematic rigidbody btw)

#

no its not its attached to a laser pointer
Also OnTriggerEnter only works when attached to one of the two objects in the collision

#

Since this is a "laser" puzzle or something why are you trying to use OnTriggerEnter?

#

Wouldn't a raycast be more appropriate?

nocturne delta
wintry quarry
#

It doesn't seem like you have anything remotely close to the setup required for OnTriggerEnter

nocturne delta
wintry quarry
#

as I explained you don't have anything close to what is required for OnTriggerEnter to work

#

I also don't see any black objects

nocturne delta
nocturne delta
wintry quarry
#

OnCollisionEnter is ALSO very inappropriate for what you're trying to do

#

you should be using raycasts

nocturne delta
#

so how should i modify the collision detector script?

wintry quarry
#

throw it in the trash

nocturne delta
#

and?

wintry quarry
#

make a script that shoots a raycast and interacts with any objects the raycast hits

nocturne delta
# wintry quarry make a script that shoots a raycast and interacts with any objects the raycast h...

as i said i have laserbeam script which uses ray cast i dont know if its related or not

public class LaserBeam
{
Vector3 pos, dir;
GameObject laserObj;
LineRenderer laser;
List<Vector2> laserIndices = new List<Vector2>();

public LaserBeam(Vector2 pos, Vector2 dir, Material material)
{
    this.laser = new LineRenderer();
    this.laserObj = new GameObject();
    this.laserObj.name = "Laser Beam";
    this.pos = pos;
    this.dir = dir;

    this.laser = this.laserObj.AddComponent(typeof(LineRenderer)) as LineRenderer;
    this.laser.startWidth = 0.1f;
    this.laser.endWidth = 0.1f;
    this.laser.material = material;
    this.laser.startColor = Color.white;
    this.laser.endColor = Color.yellow;

    CastRay(pos, dir, laser);
    
}
void CastRay(Vector2 pos, Vector2 dir, LineRenderer laser)
{
    laserIndices.Add(pos);

    Ray ray = new Ray(pos, dir);
    RaycastHit hit;

    if (Physics.Raycast(ray, out hit, 30, 1))
    {
        CheckHit(hit , dir , laser);
    }
    else
    {
        laserIndices.Add(ray.GetPoint(30));
        UpdateLaser();
    }

}
void UpdateLaser()
{
    int count = 0;
    laser.positionCount = laserIndices.Count;

    foreach (Vector2 idx in laserIndices)
    {
        laser.SetPosition(count, idx);
        count++;
    }

}
void CheckHit(RaycastHit hitInfo, Vector2 direction, LineRenderer laser)
{
    if (hitInfo.collider.gameObject.tag == "Mirror")
    {
        Vector3 pos = hitInfo.point;
        Vector3 dir = Vector2.Reflect(direction, hitInfo.normal);

        CastRay(pos, dir, laser);
    }
    else
    {
        laserIndices.Add(hitInfo.point);
        UpdateLaser();

       
    }
}

}

#

do you think i should use if (hitInfo.collider.gameObject.tag == "Flower" or something like that?

eternal falconBOT
#
Posting code

📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

wintry quarry
nocturne delta
wintry quarry
#

Notice how you're already doing this to check for mirrors:
if (hitInfo.collider.gameObject.tag == "Mirror")

#

the flower would just be a different case

slate badge
#

When a game object is unactive, are it's variables static? For example can you still move it when it's unactive?

wintry quarry
polar acorn
nocturne delta
wintry quarry
#

And yes "static" has a specific meaning in C# that has nothing to do with whether they can be changed or not

polar acorn
#

static variables are not "variables that don't change", they're variables that belong to a class instead of an instance. You're thinking of "readonly", and no, variables don't become readonly when an object is disabled

slate badge
wintry quarry
dawn sparrow
#

I'm attempting to write a function that'll print a tuple of unknown length and content types, but I don't know how to specify that with syntax

wintry quarry
dawn sparrow
#

no way

#

Yeah that's what I was getting before

#

I want to see the individual values in the tuple

wintry quarry
timber tide
#

Can't you foreach over it

wintry quarry
#

this is a Tuple of length 1 explicitly

timber tide
#

Oh yeah Tuple<T> would be a single entry does that even work

dawn sparrow
#

How do i specify unknown length then?

dawn sparrow
#

Alright I'll look into that

#

Thanks

#

So I've written my function but now I can't pass my (int, int) tuple into an ITuple param
Not seeing information on the difference between the two or if I can convert a tuple to ituple

#

Wait, one sec

#

Ahh nevermind I just wasnt reading the error properly

wintry quarry
#

yeah you've got an array there

#

the tuple itself should fit fine

#

I recommend using a StringBuilder rather than string concatenation btw. The performance will be much better

dawn sparrow
#

Yup, works now, I was just being blind lol

dawn sparrow
#

maybe i should do it anyway tho

wintry quarry
#

eh not a big deal

hollow zephyr
#

Type mismatch when trying to add a projectile spawn point to a scriptable object

dawn sparrow
#

Pretty sure editor will show "Type mismatch" for a scriptable object initialized during runtime

#

Think that applies to gameobjects as well but not sure

rich adder
#

@hollow zephyr are you trying to add a scene object into a Prefab or SO ?

rich adder
#

yea u can't do that

hollow zephyr
#

oh i see

#

Is there a pattern that I should be using to accomplish what I am trying to accomplish?

rich adder
#

have the spawn point on the same script that uses the SO for data

hollow zephyr
#

The issue would be that not every spell has a spawn point

stiff stump
#
GameObject tracer = Instantiate(_trail, barrel, transform.rotation);

Rigidbody2D rigidbody = tracer.GetComponent<Rigidbody2D>();
rigidbody.AddRelativeForce(tracer.transform.forward * _bulletspeed);

anyone one have any ideas why this wont move the gameobject it just stays still when it gets Instantiated the bulletspeed is 10

wintry quarry
#

in 2D that doesn't exist

#

so basically you're doing AddRelativeForce(new Vector2(0, 0))

rich adder
wintry quarry
#

try transform.right or transform.up

hollow zephyr
royal osprey
#

can anyone help?
https://hastebin.com/share/diqocarese.csharp
I getting an a error on
if (EnemyUnit.unit_type == 1 && ground = true)
and idk why

wintry quarry
royal osprey
#

The left-hand side of an assignment must be a variable, property or indexer

wintry quarry
#

that sets ground to true

#

use == for comparison

rich adder
#

or directly reference the transform

royal osprey
#

uh, stupid moment

#

thanks you

gaunt ice
#

your code is doing (some bool&&some bool)=some bool, but the result of && operator is unassignable, so the compiler give you this error

fallen snow
#

Hi! sorry I am a beginner and I am studying video game art and design in college. We've been using the unity playground asset set for some prototyping just to get used to unity and stuff. Thing is I am brand new to C# and have 0 experience. I would like some help with a script

fallen snow
#

omg I'm too adhd that's all overwhelming.

#

I'll just copy the format people above use for asking for help

candid oyster
#

Hey, how do I fill a 2 dimensional array with game objects?

#

a normal array works normaly, I see it in my inspector and I can fill it up

#

but my 2 dimensional one doesnt even show up

rich adder
#

yeah unity doesnt serialize multi dementional/2d array

candid oyster
modest dust
candid oyster
#

alright, thank

#

s

fallen snow
#

super simple question: how do I group things in the hierarchy

#

?

frosty hound
#

Depends what you mean by group.

#

This isn't a coding question either.

fallen snow
#

dreading omg

rich adder
#

also you would use a gameobject to nest into to create a "group"

frosty hound
#

Everything in the hierarchy has a parent. If you put something inside of another object as a child of it, it will be attached to it.

#

Then you can collapse the parent object

fallen snow
#

I guess I'll just go the long way and create an empty game object and but everything inside my little group as a child

polar acorn
#

how else would you group things

fallen snow
#

I mean on 3D modeling software you can use ctrl+G and it just groups things together and makes a folder. was just assuming unity had same functionality

polar acorn
modest dust
#

Isn't an empty gameobject basically a folder

frosty hound
#

You can move a bunch of objects into a new parent by multiselecting them and creating an empty from the right click menu

rich adder
modest dust
#

Yeah

modest dust
#

I suppose you could get a package to make "header" folder but it's still a gameobject

candid oyster
modest dust
#

better than nothing tho

candid oyster
#

I dont really understand them

rich adder
slender path
#

I am trying to get the point on the mesh but when it tries to get the point of the mesh on a different one that is not the middle one it then says nope

#

Anyone know how to fix this?

modest dust
rich adder
#

@candid oyster also you'd have to add [Serializable] above it to see it in the inspector

rich adder
rotund hull
#

how can i make a background that is infinite so where ever the camera goes the background is still there

candid oyster
#

alright, thanks

modest dust
polar acorn
#

Or just use a skybox

modest dust
#

^

rotund hull
#

well i still want the backgrond to move bc its space

#

it is 2d

modest dust
rich adder
# candid oyster alright, thanks

something like this should work

public class Awesome : MonoBehaviour
{
    public GameObjectArray[] GameObjects;
}

[Serializable]
public struct GameObjectArray
{
    public GameObject[] objects;
}```
modest dust
slender path
#

I am trying to get the point on the mesh but when it tries to get the point of the mesh on a different one that is not the middle one it then says nope
Anyone know how to fix this?

modest dust
# rotund hull ?

Have an empty GO with the background attached to it, move the empty one alongside the camera and do whatever you want with the background itself

candid oyster
#

?

modest dust
#

or just spawn/despawn backgrounds as you move

candid oyster
#

I thought that thats how to make it 2 dimensional

rich adder
candid oyster
#

okay Ill try to mess around with it for a bit too hopefully understand it

rotund hull
modest dust
#

have a grid-like background system and track the camera position

#

spawn backgrounds in the camera range and despawn when they get out of range

rotund hull
candid oyster
rich adder
#

just declare it outside the Mono class

candid oyster
#

its giving me an error that it doesnt understand the [serialized]

rich adder
#

at top

candid oyster
candid oyster
#

alr

rotund hull
gaunt ice
#

in c# you have two ways to create 2d (or multi dimensional) array: [,] and [][] (list of lists is just a wrapper of second one), unity wont serialize first one but with some trick it can serialize second one

rich adder
# candid oyster alr

otherwise if you really wanted to create a [,] and see it inside the inspector , you'd have to make a custom inspector/property drawer

candid oyster
#

okay

#

I got a really wierd error

#

"Unsupported type vector"

rich adder
#

show whole error

candid oyster
#

thats litteraly it

polar acorn
#

Look at the actual error

rich adder
#

you expand the console and look more details

polar acorn
#

not just the first line

gaunt ice
#

try restart editor

candid oyster
#

oh

#

wierd

#

I just pressed start

#

and its gone

rotund hull
#

how can i make a background the is infinte so where every the camera is the background is there

rotund hull
fallen snow
#

Hey! actual coding question this time.

// The key to press to create the objects/projectiles
private KeyCode keyToPress = KeyCode.Space;
how do I make it so instead of a key being pressed, it's just constantly shooting.

#

private ?? ?? = true;

polar acorn
gaunt ice
#

it is just a variable, nothing to do to make you continously shooting

polar acorn
#

instead of where you define which key does it

candid oyster
rich adder
eternal falconBOT
#
Posting code

📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

polar acorn
#

it is basically an array of arrays

fallen snow
#

oh so maybe I can make a variable bool which I can bind to where it actually shoots

polar acorn
#

Which is not technically 2D, but close enough that can still be serialized

candid oyster
#

ohh

rich adder
candid oyster
#

so lets say I want to have a 4x4 2d array

#

so it basicly makes 4, arrays each habing 4 slots

polar acorn
fallen snow
#

I literally started coding yesterday 😭 plz

rich adder
cosmic plover
#

If you just started coding just stick to easy stuff for a while.

rich adder
#

!vs

eternal falconBOT
#
Visual Studio guide

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

Visual Studio (Installed via Unity Hub)
Visual Studio (Installed manually)

fallen snow
rich adder
#

your code editor

candid oyster
cosmic plover
#

You add the arrays to it through code in a loop. Or at least that's how I do it.

polar acorn
candid oyster
#

wait a moment...

timber tide
#

Technically you can make a 2D array out of a single array but it's a bit more mathy

#

using the 2D array data structure makes it a bit easier though

candid oyster
#

now its working, thanks

candid oyster
timber tide
#

Yeah, unity doesnt like those

stiff stump
#

Im having an issue with trail renderers and sorting layers
so i have my gameobject over the top of a tilemap which the sprite its self is visable but the trail renderer isnt visiable while over the tilemap
they are both on default layer and the trail renderer is a layer above the tilemap but still not visable

cosmic plover
gaunt ice
#

there is no multi dimensional array in computer memory

timber tide
#

you can have as many dimensions as possible in a 1D array, but it's up to you to handle the navigation of it all.

#

but yeah in memory it's just a straight line down ;)

cosmic plover
#

@timber tide Yeah but then why use bools when you could just use ints? Why use anything that makes it easier?

fossil tree
#

hi, little question how i can show and hide my canva in code????

gaunt ice
#

setactive

fossil tree
rich adder
fossil tree
rich adder
#

if type is Canvas you use .enabled

#

if you use GameObject type, then use SetActive

fossil tree
#

oh ok its a canvas for me

polar acorn
rich adder
polar acorn
#

You can do math to get the 1D index given the X,Y coordinates

fossil tree
#

i need make someting like that ?

Canvas canvas = canvas.GetComponent<Canvas>();
            canvas.enabled = !canvas.enabled;
            canvas.enabled = true;```
rotund hull
polar acorn
#

Just use the variable you already have

fossil tree
candid oyster
#

how do I access the arrays now?
For example before in my 2d array I just did:

Array[Value1,Value2];
modest dust