#πŸ’»β”ƒcode-beginner

1 messages Β· Page 436 of 1

steep walrus
teal viper
# steep walrus

What do you see if you run

dotnet --list-sdks

In a console?

cinder crag
#

i would love to but im not sure how to do it with a list

mint remnant
steep walrus
#

also when i look in my apps through windows i see sdks that are x64

teal viper
# steep walrus

I'm not sure if these are installed or just installation files..?

#

Where are you seeing them?

steep walrus
hushed hinge
#

https://gdl.space/ekipahabob.cpp i am having a problem with this is that it's supposed to show how many muons with tag names "Muon1" "Muon2" and "Muon3" from different scenes there are while i am in the world select screen but it is not showing how many muons theere, how can i fix that since when i put some muons in there, it shows how many muons there are, but i want it to show how many muons there are in every scene?

cinder crag
#

So if I have a list of Transforms , how do I transform the RotateTowardsTarget method work with the list since rn the method works only for an enemy but I want it to rotate towards the first enemy that enters the radius

#

Or wait

#

I don't even think I need to do a list

#

Since I just want the turret to turn towards the first enemy that enters the radius and shoot at the enemy then when that enemy dies , the turret shoots the next enemy

#

Idk if that's a good way too do it icl

hushed hinge
cosmic dagger
tidal kiln
#

whats a muon

hushed hinge
#

those are muons

tidal kiln
#

when you need help you probably shouldnt use names that only exist in your game like that

#

makes it hard to follow

#

so you have some items in different scenes and you wanna display how many there are in total?

tidal kiln
#

if the state doesnt change you could do something like using a scriptableobject assigned to each level and store how many of your objects will be in the scene

#

now if you play the level and the amount remaining changes and you wanna reflect that in the other scene youll need to figure out some sort way of saving data because scriptable objects arent for saving changes

hushed hinge
tidal kiln
#

something like

public class SceneData : ScriptableObject 
{
    [field: SerializeField] public int MuonCount;
}
#

oh you should probably add [CreateAssetMenu(fileName = "SceneData", menuName = "ScriptableObjects/SceneData")] in there above the class definition

#

i mean i guess a simpler solution if the count is static is to just make a static class that holds that info and you can write it in code

hushed hinge
tidal kiln
cosmic dagger
tidal kiln
#

but to answer the question you could create a monobehaviour in the world select that references the SceneData class. if you go the scriptable object route you can add more data to it about that level like scene name or whatever

cosmic dagger
hushed hinge
hushed hinge
tidal kiln
solemn fractal
#

Hey guys, do I need to use getter and setters for all my variables inside player etc? or just the most important ones? If you are creating a game alone should I even care about this?

frosty hound
#

You don't have to, no. You only care if you care, it's not necessary.

teal viper
solemn fractal
frosty hound
#

They can be single lines

teal viper
rocky canyon
teal viper
rocky canyon
#

the person that will fk u over the most is ur past self

solemn fractal
#

hahaha, got it. Makes sense.

#

I will try to start using it in a new small project game I have.

tidal kiln
#

its 1 line

rocky canyon
#

yea, thats what Osteel mentioned

solemn fractal
#

I will do a research on that. Thank you

summer stump
#

Even when not using autoprops, it would be 2x bigger for ONLY the properties (one line for the propery and one for the backing field).
Meaning less than 2x.

ember tangle
#

I'm really really struggling with tracking down the cause of NullReferenceException.

#

is there an in editor way to see what is wrong with the script? Everything was working until I started moving the Start() functionality into a Setup() function called in order in a game manager script

#

now its just constantly tracking down NullReferenceExceptions

rocky canyon
#

find that line.. see what references u have.. and debug them to check if they're assigned

ember tangle
#

for this current iteration of the error, its caused a script passing itself into the state machine currentState.UpdateState(this);

tidal kiln
ember tangle
#

this worked perfectly before until I refactored the code to be setup in a manager script

tidal kiln
#

public int Something {get; set;}

#

thats all you need

rocky canyon
summer stump
tidal kiln
#

whats the big deal with an extra line per property

summer stump
tidal kiln
#

i mean i guess it doesnt matter its your choice

summer stump
#

I was pointing out that there is no possible way it would be 10x
Even without knowing about auto properties, it would be less than 2x max..

#

It seems you misread what I was said and took it to mean that it is a bad thing? I meant the exact opposite

tidal kiln
#

i thought you were the original guy

#

my bad

summer stump
#

No worries. It happens. That makes things more clear, cause I was confused haha

hushed hinge
#

i am having trouble in a thread

ember tangle
rocky canyon
#

tf?

ember tangle
#

well, it hangs forever, not crash

rocky canyon
#

lol, ive never heard that before sorry

#

whats the error in the console?

ember tangle
#

no errors, just 1 fps in the editor

#

I got it to stop playing at least.

molten dock
#

is the new input system worth learning

#

cant tell if it matters

rocky canyon
#

its slowly going to become the standard

rocky canyon
#

then u can learn the input system later

#

you can even have both in ur project..

summer stump
# molten dock is the new input system worth learning

If you plan on allowing mutli-input (like keyboards and controller and touch) then it simplifies things A LOT. If you are only using keyboard, it is still worth it, bit the Input class can still be preferable for its ease

sacred orbit
#

is there any way to center the players mouse on the screen?

rocky canyon
#

yes its Cursor.lockState = CursorLockMode.Locked;

molten dock
#

i know how to use input

#

nice that i can use both

#

i have been learning unity for about a year now is that still beginner status

rocky canyon
#

yes

#

probably approaching "general" type stuff

molten dock
#

ok cool cause i feel like a beginner

rocky canyon
#

im 3.5 years.. and i still am

dawn oracle
#

yo why is this spawning 2 balls when i move the ball out of the trigger zone void OnTriggerExit(Collider other) { if (other.tag == "ball") { //ballCount--; //Debug.Log("Objects in trigger: " + ballCount); StartCoroutine(outzone(other)); } } IEnumerator outzone(Collider objToDestroy) { Destroy(objToDestroy.gameObject); yield return new WaitForSeconds(1); Instantiate(ball, ballSpawner1.position, ballSpawner1.rotation); } }

rocky canyon
#

put a debug in ur coroutine.. but im sure that'd run twice right?

dawn oracle
#

oh yea let me try that lol

#

ok yea its getting send thru twice.

#

im gonna try and disable the collider rq

ember tangle
rocky canyon
#

ohh was it trying to reference an object that wasn't set up yet?

#

that stuff can happen w/ singletons and stuff that set up in Awake().. if another script tries to grab it in its Awake().. there could be a race condition

#

Awake() set up self Start () set up others

ember tangle
#

It was an instantiated GameObject from a prefab that had all the scripts attached so I still dont understand

rocky canyon
#

but im glad u got it working

molten dock
#

!code

eternal falconBOT
molten dock
#

i am trying to do a load and save system

#

i get an error saying "object reference not sent to an instance of an object" on line 48 and 61

#

so it must have to do with foreach (IDataPersistence dataPersistenceObj in dataPersistenceObjects

#

i dont think that the IDataPersistence script should have this issue since its an interface and not a monobehaviour

#

the IDataPersistence script is this

#

`public interface IDataPersistence
{
void LoadData(GameData data);

void SaveData(ref GameData data);

}`

rocky canyon
molten dock
#

why does that work

rocky canyon
#

your very welcome..

rocky canyon
#

just think about the flow u have

#

it helps me to scratch out whats happening on a piece of paper when working on systems like a save system

molten dock
#

what sucks is that i am too clueless on the topic to not use a tutorial so then i get stumped when roadblocks like that come up

rocky canyon
#

i also use tons of comments

rocky canyon
#

specifics..

rocky canyon
#

then eventually.. you'll be able to code the same thing w/o any help.. besides googling functions and keywords

molten dock
#

that seems like a good method ill save that

rocky canyon
#

the comment part really helps

molten dock
#

when i learn how it works i will comment

rocky canyon
steep walrus
#

im continiously having this issue where my c# dev kit is targeting the wrong format .net sdk. instead of x64 its targeting x86 and i cant do anyting and I was wondering if anyone knows how to change what sdk is targeted

rocky canyon
#

weird.. ur not using a 32 bit machine are u?

#

should always be x64

steep walrus
#

im using a 64x i believe but possible an 86x is there a way to check?

rocky canyon
#

System Information -> System Type

steep walrus
#

x64-based PC

rocky canyon
#

mmhmm i knew u werent running a 32bit machine

#

thats what x86 is

#

old school

steep walrus
#

absolutely everything that comes up when i search .net in storage

rocky canyon
#

have u googled how to retarget sdk

steep walrus
#

some x86 some x64

rocky canyon
#

well they put both i think

steep walrus
rocky canyon
#

is it ur VSCode thats busted?

steep walrus
#

and i think i jut found something that says i can do it in global.json but idk where that is

steep walrus
#

thats the exact error message

steep walrus
rocky canyon
#

maybe ur just missing a step

#

idk im just reading around.. my .NET install was simple

steep walrus
#

i saw that thread but ig i glossed over hat

rocky canyon
#

i just went online and found the .NET 8 / 9 on their website and installed it

rocky canyon
#

id uninstall and reinstall the SDK

steep walrus
#

ill try that if uninstalling the extension through vs code doesnt work

#

yeah that didnt work

rocky canyon
#

@steep walrus tbh someone shoulda helped u fix this by now..

#

i just don't have the expertise to help.. other than just googling along-side u

steep walrus
#

nah youre all good its a complicated problem it seems i also am just trying to lean and its really unmotivating that i literally cant even start

#

i feel like also everything i google is like slightly different than my situation and there is a chance ive missed the solution cause im pretty confused

ember tangle
#

Why when instantiating from a prefab can no scripts attached to the prefab access each other using GetComponent<>()?

jagged socket
#

why the controls (text) are reblind but the player still moving with old movemeny?

#

he still moving with adw

rocky canyon
formal sable
#

Hey guys. How are you?

Can you help me with particles? I hung a script on an object that should protect from particles, but there just ignore me and collision. I'm used mesh collider for home

jagged socket
#

the movement won`t change either

rocky canyon
jagged socket
#

help please

formal sable
primal rivet
#

Can we make 3d object move in 2d tilemap?

rocky canyon
formal sable
rocky canyon
#

also gotta have good colliders on the objects (convex or primitive)

formal sable
# rocky canyon

ahahaha, I have now created new particles and they are working))

#

maybe problem with my current rain

twilit olive
#

what do you guys prefer for input systems? My personal preference is something like the new input system but i like events and binding them in code rather than the editor, I also rather not lookup action names using strings if i could help it. any recommendations?

#

getting a nice input setup has always been one of the roadbumps whenever i start a new project

formal sable
cosmic dagger
steep walrus
#

!ide

eternal falconBOT
primal rivet
twilit olive
boreal bramble
#

I have a problem with the unity editor UI where's the best place to get help?

#

I keep getting blank UI panels like this everywhere and need to reload them, or sometimes i can't expand the transform component. I've tried resetting the layout, didn't work

#

I'm sorry if I'm posting in the wrong place

#

unity version is up to date

fossil zephyr
#

How do I add +10 to the 'right' property? ```cs
loadingPanel.right += 10;

#

CS0019 Operator '+=' cannot be applied to operands of type 'Vector3' and 'int'

#

so i cant add integers onto vector properties

#

i was thinking of converting the vector property to an integer and then adding it back but i dont think it would work

fossil zephyr
ivory bobcat
#

So it isn't a Rect Transform?

fossil zephyr
#

When I click the "werk" button, I want the panel to slowly go up and then when complete add +1 money

ivory bobcat
#

Show where you've declared it

fossil zephyr
fossil zephyr
# ivory bobcat Show where you've declared it
using JetBrains.Annotations;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Security.Cryptography.X509Certificates;
using UnityEngine;
using UnityEngine.UI;

public class buttonScript : MonoBehaviour
{
    public RectTransform loadingPanel;
    public void Button()
    {
        loadingPanel.right += 10;
    }
}

ivory bobcat
#

So it's a Rect Transform

fossil zephyr
#

yeah

ivory bobcat
#

The right property likely isn't what you're seeing in the inspector but the specific axis relative to world space

ivory bobcat
fossil zephyr
#

and repeat that 100 times until its at my desired value?

ivory bobcat
#

Not sure why you'd do anything 100 times but if you're wanting to modify the properties of the rectangle (left, top, right, bottom, z) your wanted property would be the rect member.

fossil zephyr
#

so i will need to change the rect mutliple times

#

which i dont think is the most resource-efficient way

ivory bobcat
#

Whatever the case is, the right property is referring to your object's directional axis-right and not the right dimension of the rectangle. You'll need to modify the rect property if your intentions are to modify that "right" field shown in the Rect Transform component.

fossil zephyr
fossil zephyr
modest dust
#

You might want to use the offsetMin and offsetMax properties of RectTransform

fossil zephyr
#

i dont have a lot of experience with c# but i do with other languages

modest dust
#

Or an animation would be good too, probably

modest dust
fossil zephyr
#

idk if u can do it another way

modest dust
#

offsetMax is the upper right corner of the rect

#

offsetMax.x would be right

#

Play around with the values to see how it works

worthy tundra
#

i wanna instantiate an array of prefabs inside a circle but i dont really understand random.insideunitycircle, i didnt quite understand the documentation, help any1?

modest dust
#

Which part don't you understand

#

It just returns a random point on or inside a circle of radius 1

#

As if the circle center is at (0, 0)

#

If you want to change the radius and center position, then simply do:

Vector2 randPos = Random.insideUnitCircle * spawnerRange + spawnerPos;
worthy tundra
modest dust
#

First multiply by the range

#

Then "move" it

topaz ice
#

It says I'm using only float values that apparently... Can't be smaller than 1. or like can't have dots.

using System.Collections.Generic;
using UnityEngine;

public class Walking : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
        {
        if (Input.GetKey(KeyCode.A))
        transform.position = new Vector3(transform.position.x - 1, transform.position.y, transform.position.z);
        
    }
}```
#

How do I write with stuff smaller than 1

verbal dome
#

0.1 is a double. 0.1f is a float

topaz ice
#

OH.

#

thanks alot!

#

literally instant explanation

topaz mortar
#

code

#

!code

eternal falconBOT
topaz mortar
#

Anyone wanna help me refactor this monster? https://gdl.space/zalugonaqi.cs
I have 4 classes that extend Item, which are all created slightly differently.
My code is a huge mess right now and I find it very hard to restructure stuff like this.
On the plus side, it does work, so I don't hate leaving it like this, but I kinda do a little πŸ™‚

mint remnant
#

doesn't look all that huge to me, but I'd start by using the built in refactor method of Extract Method

copper python
#

jez tons of if statements. @topaz mortar have you ever heard of never nesting? For most people it really helps to keep your if statements more readable and clear

#

You might want to look into it, it's quite nice

loud mango
robust dew
#

here my character is a dynamic rb2D and the platform is static rb2D. When the platform is moving down, the player seem to be not "stand" on it, instead it keeps teleporting, how can i fix this or what is the keyword for this problem ?

cosmic dagger
twilit olive
#

yeah this seems pretty good so far

#

(surely i shant run into any issues later on from poor design choices)

lucid yew
#

what is the reason that there is no checkbox for the twitch script?

ivory bobcat
pallid nymph
#

Unity trying to be smart and failing πŸ˜„

cosmic dagger
lucid yew
#

aight thanks guys

ivory bobcat
#

You won't need that disable/enable checkbox if there isn't anything to disable/enable (callbacks that Unity would run)

pallid nymph
#

It's rare, but when it happens it's frustrating they tried to be smart about it instead of just giving you the checkbox always

ivory bobcat
fossil zephyr
loud mango
tranquil barn
#

Hello guys im new and trying to learn some unity basics any tutorial for a total beginner ?

topaz mortar
#
public static event Action<Equippable, int> UnEquipEquippable;```
Can you not overload events?
eternal needle
# loud mango https://discord.com/channels/489222168727519232/763495187787677697/1265581150701...

#πŸ“–β”ƒcode-of-conduct dont crosspost, saying that you dont wanna repost doesnt mean anything if you still do it anyways
Also you likely arent getting help because it is very vague and more of a beginner issue in the general channel. Try to narrow down the issue rather than just saying it doesnt work. You should have a general idea of what line of code isnt working. Add debugs to see whats specifically not working

eternal falconBOT
#

:teacher: Unity Learn β†—

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

eternal needle
stiff birch
#

You can also check the link from SteveSmith or the resources in the pinned message from vertx

cosmic dagger
topaz ice
#

Hey I'm moving to unity, And I'm making a system to walk and jump around.

And it just skips through some steps to do things.

Full script:

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

public class Walking : MonoBehaviour
{
    // Start is called before the first frame update

    float JumpHeight = 0f;

    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
        {
        if (Input.GetKey(KeyCode.A))
        transform.position = new Vector3(transform.position.x - 0.005f, transform.position.y, transform.position.z);

        if (Input.GetKey(KeyCode.D))
        transform.position = new Vector3(transform.position.x + 0.005f, transform.position.y, transform.position.z);

        if (Input.GetKey(KeyCode.W))
        transform.position = new Vector3(transform.position.x, transform.position.y, transform.position.z + 0.005f);

        if (Input.GetKey(KeyCode.S))
        transform.position = new Vector3(transform.position.x, transform.position.y, transform.position.z - 0.005f);

        if (Input.GetKey(KeyCode.Space))
        Debug.Log("Pressed space... probably");
            if (JumpHeight <= 0.8f)
                JumpHeight += 0.01f;
                transform.position = new Vector3(transform.position.x, transform.position.y + 0.01f, transform.position.z);
    }
}```

What I'm focusing on:

```        if (Input.GetKey(KeyCode.Space))
        Debug.Log("Pressed space... probably");
            if (JumpHeight <= 0.8f)
                JumpHeight += 0.01f;
                transform.position = new Vector3(transform.position.x, transform.position.y + 0.01f, transform.position.z);```

What it skips to:

```            if (JumpHeight <= 0.8f)
                JumpHeight += 0.01f;
                transform.position = new Vector3(transform.position.x, transform.position.y + 0.01f, transform.position.z);```

It doesn't show text until I press space, but does jump for some reason.
eternal needle
#

you need brackets, without the brackets its just doing the next line only within the if statement. C# doesnt care about how its indented

tranquil barn
languid spire
topaz ice
eternal needle
languid spire
topaz ice
#

until I put them there

eternal needle
#

indents dont affect anything, its purely for style/readability

eternal needle
#
if (Input.GetKey(KeyCode.Space))
{
  // whatever logic inside here
}

but you should likely do more c# basics if you havent learned this yet

long jacinth
#

script for weapon switch but it isnt switching

#

it randomly switches when i keep clicking

teal viper
cosmic dagger
#

that's a lot of GetComponents to do every physics frame . . .

long jacinth
long jacinth
cosmic dagger
long jacinth
#

ok

languid spire
eternal falconBOT
#

:teacher: Unity Learn β†—

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

long jacinth
languid spire
#

I'm pretty sure I've told you this before, but you need to debug your code to actually see what it is and is not doing

long jacinth
#

ok i will

jagged socket
#

Hello
I have a problem in input when i enter playmode the input names changes but the movement no
but when i change the inputs in the play mode it become fixed
how can i fix that?
help me?!

languid spire
jagged socket
fossil zephyr
#

does anyone have the slightest idea why my button wont work?

public class buttonScript : MonoBehaviour
{
    private static int money;
    public void Button()
    {
        Console.WriteLine("clicked");
        money += 1;
        Console.WriteLine(money);
    }

    public void Start()
    {
     money = GameObject.Find("money").GetComponent<money>().moneyInt;
    }
}

doesn't even print "clicked".

cosmic dagger
languid spire
#

To start with Console.WriteLine does not work in Unity. use Debug.Log

fossil zephyr
cosmic dagger
#

use Debug.Log instead . . .

fossil zephyr
#

im so used to using console.writeline smh

#

alright thanks ( @cosmic dagger @languid spire ) it works

#

problem was debug.log

cosmic dagger
topaz mortar
#

how do I stop play if it's stuck in an infinite loop?

long jacinth
#

after some debugging the problem is that it isnt detecting my E key input

#

should i worry abt this

ivory bobcat
topaz mortar
ivory bobcat
#

Once the code executes that line, it'll pause and you can safely stop the play session within the Unity Editor.

topaz mortar
#

Ah stopping the debug fixed it, thx πŸ™‚

jagged socket
#

okay
look @languid spire im using new input system and im using this to make a reblinding menu so the player can change his movement
and

#

i made this to change the inputs

#

but it doesn't work unless i change the action in the play mode
if i didn't change it in play mode it doesn't work

blazing estuary
#

anyone know why this error might be appearing

#

ive checked multiple times but there seems to be nothing wrong

#

this is the code where the error is taking me

languid spire
blazing estuary
#

what about the error though

#

the script isnt working

languid spire
#

you are doing 2 new() there are either of them Monobehaviours?

languid spire
blazing estuary
#

will do

fossil zephyr
#

why does public Money totalMoney; try to reference currentScript.totalMoney instead of Money.totalMoney

#

totalMoney is not a public variable of the current script. its a public variable of the Money script that I need to access

#

buttonScript is accessing totalMoney from money.cs/Money class

languid spire
vernal bone
#

you have to specify which variable you accessing, if it's not local

halcyon geyser
#

we'll need more info than just this vague screenshot

languid spire
#

just by giving a varaible the same name does not somehow magically link them together

wheat canopy
wheat canopy
wheat canopy
# halcyon geyser we'll need more info than just this vague screenshot
// buttonscript.cs
using JetBrains.Annotations;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;

public class ButtonScript : MonoBehaviour
{
    public Money totalMoney;
    public void Button()
    {
        Debug.Log("clicked");
        Debug.Log(totalMoney);
    }
}
// money.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Money : MonoBehaviour
{
    public int totalMoney = 11;
    public Text moneyText;

    private void Update()
    {
        //Debug.Log("updating");
        moneyText.text = "MONEY: " + totalMoney;
    }
}
languid spire
#

by using a reference to the instance of the money class you want to use

wheat canopy
languid spire
#

because thats not the way C# works

wheat canopy
vernal bone
hexed terrace
#

all you have to do atm is totalMoney.totalMoney

wheat canopy
hexed terrace
#

"didn't work" is too vague.

wheat canopy
languid spire
# wheat canopy what do i write instead

I'm not going to write your code for you but I would suggest you change
public Money totalMoney;
to
public Money money;
and set the reference in the Inspector
then you can do
money.totalMoney

hexed terrace
#

just get the error and update, no need to give a blow by blow update πŸ˜„

wheat canopy
#
public void Button()
{
    Debug.Log("clicked");
    Debug.Log(totalMoney.totalMoney);
}
``` prints `UnityEngine.Debug:Log (object)` which isnt the value
vernal bone
#

and you probably should learn some more OOP UnityChanThink

ivory bobcat
#
public TotalMoney money;//Reference from the inspector``````cs
moneyText.text = $"Money: {money.totalMoney}";```
wheat canopy
#

Β―_(ツ)_/Β―

hexed terrace
#

Do you know what OOP is?

wheat canopy
#

object oriented programming

#

yes

#

c# isnt my main lang

vernal bone
wheat canopy
languid spire
#

tbf OOP is bad for any system if you don't know wrf you are doing

eternal needle
#

If they didnt tell you why, dont listen to it.

vernal bone
ivory bobcat
wheat canopy
languid spire
hexed terrace
eternal needle
#

Also unity isnt related to that, you can create your classes however you want. Unity doesnt care

vernal bone
wheat canopy
languid spire
languid spire
wheat canopy
eternal needle
wheat canopy
bright siren
#

LUA is for smaller scripts - I don't think it a language for anything large which is where you need to break things down. But in C# you can have a static class or Singleton to maintain your core data if you really want

languid spire
# wheat canopy dont learn it. its useless

I have no intention to, although I do program in many non OOP languages and it is my experience that you eventually end up implementing a faux OOP within them to make sense of them

eternal needle
# wheat canopy and it worked

Or course itd work, this isnt a question of will it run. It's a question of how much will people hate working with u after seeing a 3000 line script named Game.cs

wheat canopy
#
//buttonscript.cs
public class ButtonScript : MonoBehaviour
{
    public Money money;
    public void Button()
    {
        Debug.Log("clicked");
        Debug.Log(money.totalMoney);
    }
}
``` still prints `(object)`. 
```cs
//money.cs
public class Money : MonoBehaviour
{
    public int totalMoney = 11;
    public Text moneyText;

    private void Update()
    {
        //Debug.Log("updating");
        moneyText.text = "MONEY: " + totalMoney;
    }
}
vernal bone
languid spire
#

screenshot the ButtonScript inspector

wheat canopy
#

less is more

#

certainly not the case with c#

eternal needle
#

Then the environment you worked in was backwards

wheat canopy
languid spire
wheat canopy
wheat canopy
#

do i have to reference stuff in the script properties??

#

guh

languid spire
#

no, that all looks fine

wheat canopy
vernal bone
languid spire
#

not according to your screenshot unless you have mutiple ButtonScript instances

ivory bobcat
#

You're likely referencing something else in the on click event and not the instance with the proper reference to money.

eternal needle
wheat canopy
wheat canopy
ivory bobcat
#

This isn't really a coding issue anymore but rather an issue with using the Editor Inspector in regards to referencing. Make sure you drag the correct scene objects into each reference field/slot.

neon fractal
wheat canopy
#
public class ButtonScript : MonoBehaviour
{
    public Money money;
    public void Button()
    {
        Debug.Log("clicked");
        Debug.Log(money.totalMoney);
    }
}
neon fractal
wheat canopy
ivory bobcat
#

Which object did you drag into that On Click listener field?

languid spire
ivory bobcat
#

Did you simply drag the script from the asset fold or the scene object with the component script?

wheat canopy
#

yeah

vernal bone
ivory bobcat
#

Drag the scene object with the component script.

wheat canopy
languid spire
# wheat canopy yeah

man, you really need to take some time and learn the basics of Unity otherwise your life is gonna be a world of pain

languid spire
eternal falconBOT
#

:teacher: Unity Learn β†—

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

neon fractal
ivory bobcat
wheat canopy
#

button, game manager, money display, button script, money script

ivory bobcat
wheat canopy
#

still prints object

languid spire
#

man, look at the line abnove ffs

#

object is just where it is coming from. it's working fine

wheat canopy
languid spire
#

yes it is

wheat canopy
#

the value is defined as 10 which unity acknowledges in properties

languid spire
#

wtf do you thing the 10 is ?

wheat canopy
languid spire
#

it is printing 10

wheat canopy
#

its printing object

hexed terrace
languid spire
#

no, it is printing 10 which is coming from a Unity Object

hexed terrace
#

put ya glasses on

wheat canopy
#

wtf

#

unity console is peak chat

ivory bobcat
vernal bone
hexed terrace
#

your lack of attention, you clearly understand 'clicked' is being logged out.. then completely ignored the 10

wheat canopy
hexed terrace
#

Yes

#

I use Editor Console Pro, it's much better than the default IMO. But look on the asset store at the millions of available ones.

topaz mortar
#

I have Weapon : Equippable : Item and Armor : Equippable : Item
Does this not work for Weapon and Armor?
GetComponentInChildren<Equippable>();

languid spire
#

why is Equipable in your chain twice?

topaz mortar
hexed terrace
#

Do you mean you have ?

Weapon : Equippable
Armor : Equippable
Eqiuppable : Item

topaz mortar
#

yes

ivory bobcat
#

I think he meant equippable inherits Item and both weapon/armor inherits equippable.

topaz mortar
#

seems a bit besides the point

hexed terrace
#

It matters, because we're trying to understand what you actually have, you wrote it in a weird way

#

I would expect the get component to work

languid spire
#

you probably want

Weapon weapon = GetComponentInChildren<Equippable>() as Weapon;
ivory bobcat
#

If it did not work, you should explain so else just try it out and ask why it isn't working whilst providing more info (if it doesn't).

topaz mortar
#

hmm yeah it works, guess I have a logic error somewhere then

neon fractal
# ivory bobcat

if u need

using UnityEngine;

namespace Clicker
{
    public class ButtonInput : MonoBehaviour
    {
        [SerializeField] private Bank _bank;
        [SerializeField] private int _moneyPerClick = 1;

        public void PressButton()
        {
            if (_bank != null) _bank.AddMoney(_moneyPerClick);
        }
    }
}
using UnityEngine;
using TMPro;

namespace Clicker
{
    public class Bank : MonoBehaviour
    {
        [SerializeField] private int _money;
        [SerializeField] private TMP_Text _moneyDisplay;

        public void AddMoney(int moneyPerClick)
        {
            _money += moneyPerClick;
            _moneyDisplay.text = $"M: {_money}";
        }
    }
}
gaunt ledge
#

okay, I need a bit of help people,

#

I'm doing a tower defence game but the pathfinding of the enemies keep putting them on lines

#

and having a wave of killer insects on a straight line is quite... weird

#

do you guys have any idea to how to make them spread?

#

while moving to the target position

ivory bobcat
#

You may want to provide your current code (basically what you've tried) and an illustration if possible.

gaunt ledge
#

I mean, the code is basicaly, get the current navmesh pathfinder => go to the next position on the waypoint array

hexed terrace
#

!code

eternal falconBOT
hexed terrace
#

☝️ that's how to share code

gaunt ledge
#

the comments are in portuguese but I belive it's quite simple to understand what I'm doing

hexed terrace
#

You're probably giving them all the exact same destinations, rather than having a buffer around the node position

#

and spawning them all on the exact same point

ivory bobcat
gaunt ledge
gaunt ledge
#

adding a random value with a specific seed for pathoffset

#

gonna try that

hexed terrace
gaunt ledge
#

I don't have many ways of changing this part of the code, maybe making them go into diferent positions on the end destination, but the end destination must be tha same for all of them

hexed terrace
gaunt ledge
#

with some exeptions, my problem is the path that they make, I already know they gonna have the same path becouse of this, so I need to find a way for them to create some variations

hexed terrace
#

instead of giving them all the exact same positions to head to (and then wondering why they're in a straight line!).. add a random value to the x,z of the pos.

gaunt ledge
#

my idea was something similar, every time they get to a way point, while they are at a certain distance, instead of going directly there, they go to a offset based on a random number

hexed terrace
#

If you do that, they will still end up getting into a straight line and then diverging. Seems an odd way to do it... just work out the offset before setting their next target position

languid spire
gaunt ledge
#

hmmmm, that is a interesting position, but don't this endup being the same thing I'm trying to do now, but with specific waypoints instead of a random offsetpos?

languid spire
#

not really, no, you are much less likely to get a procession effect

#

depends how you define your waypoint positions

faint sluice
#

hello, im trying to create a script where all of my game objects will be visible inside camera no matter how far they are by changing camera's orthographic size. that functionality is working but i cant figure out how to add margin to this feature so i can avoid gameobjects hiding behind UI and be visible inside an area i want them to.
for example i want to add a 50 pixel margin from the edge of the screen. but this margin isnt consistent and keeps decreasing as objects go further away. help pls
https://hastebin.com/share/dumogahuqe.csharp

gaunt ledge
#

okay, the random pos offset worked, thank you guys for the help

hexed terrace
#

what's this got to do with code?

azure zodiac
#

I honestly dont know where to ask about layers

hexed terrace
#

not in a code channel 🀣

azure zodiac
#

sure thing, thanks

knotty tangle
#

How do I get a clone's Parent?

#

I want to destroy the object, but the clone is a rigidbody

#
public Rigidbody ball;
Rigidbody clone;

if (Input.GetMouseButtonDown(0)) {
    if (mouseclick == true) {
        clone = Instantiate(ball, transform.position, transform.rotation);
        clone.velocity = transform.TransformDirection(Vector3.forward * 50);
        clone.name = "tiro";
    }
}

Destroy(clone, 2f);
#

I want to destroy this clone's object, how do I do it?

slender nymph
#

you need to destroy its gameObject not the Rigidbody component

knotty tangle
vestal adder
#

transform.parent mby

slender nymph
#

read my message very carefully, i've given you a hint. then go look at the documentation for the Rigidbody component and see what members it inherits

slender nymph
vestal adder
#

he wants to know how to get the clones parent so i assumed theres a parent

slender nymph
#

they are misunderstanding the hierarchy. we can clearly see that no parent has been assigned in the code they showed.

vestal adder
#

okay

slender nymph
tawdry rock
#

How can i reach these two values through code?

tawdry rock
#

ambientIntensity and reflectionIntensity property?

cosmic quail
#

why did u edit ur message lol

tawdry rock
#

i edited before reading ur reply, sorry

#

so those are cool but still how do i get to the rendersettings in code?

cosmic quail
verbal dome
obtuse sluice
#

ight

#

ty

tawdry rock
topaz ice
#

Apparently if I use .FindWithTag(""), MonoBehaviour doesn't let it happen?

using System.Collections.Generic;
using UnityEngine;



public class CameraMovement : MonoBehaviour
{
    public GameObject CamFollower = GameObject.FindWithTag("CamFollower");

    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        transform.position = CamFollower.transform.position;
    }
}```
rich adder
topaz ice
rich adder
#

when you initialize a field

#

that gets created normally when a class gets new()

#

unity takes care of this on its own, so you cannot run MB method there

slender nymph
#

the error message literally tells you how you can resolve this error too

topaz ice
slender nymph
#

it said you cannot call it where it currently is, and gave you two options where you can call that method from

topaz ice
#

Oh I just need to put it in start?

rich adder
#

just to be clear, only the assignment.Not the whole line

topaz ice
#

I just put it in start and removed Public

#

and it worked

rich adder
#

nooo

topaz ice
#

oh wait..

rich adder
#

now its local..

topaz ice
#

oh ;-;

rich adder
#

define it outside the method, assign it inside the method

#

do you know what assignment is ?

topaz ice
slender nymph
rich adder
topaz ice
#

Like I said I don't, And then tried something extra (guessed)

rich adder
#

well this isn't a guessing game lol

#

its precise science

#

things mean things

#

= is symbol for assignment

topaz ice
topaz ice
slender nymph
#

well then i won't be helping you any further. good luck

topaz ice
#

Instead of asking y'all everytime I don't know a thing about c#

slender nymph
rich adder
#

also even if you solve this, this wont give you a good camera follow anyway.
You should just use Cinemachine here for easy camera follow πŸ€·β€β™‚οΈ

river halo
#

I was making a 2D platform game, I wrote a code to open the relevant scene when you press the levels, but it doesn't work, can you help? Error: 'Level1' couldn't be loaded because it has not been added to the build settings or the AssetBundle has not been loaded.
To add a scene to the build settings use the menu File->Build Settings...
UnityEngine.SceneManagement.SceneManager:LoadScene (string)
LevelMenu:OpenLevel (int) (at Assets/Scripts/LevelMenu.cs:12)
UnityEngine.EventSystems.EventSystem:Update () And even though I adjusted the building settings, I have this problem.

cosmic dagger
river halo
rich adder
#

where is the -

cosmic dagger
#

that's not correct . . .

rich adder
#

right now your level shows up as Level0 for example

cosmic dagger
#

"Level" + levelId; would be Level1 . . .

pine furnace
#

first photo the player1 has an rb2d component and the second one only has a box collider

#

why the collision detection works only when i use the dynamic rb2d

rich adder
pine furnace
#

not even the kinematic one

pine furnace
rich adder
cosmic dagger
rich adder
#

if you're using physics queries you mind as well use rigidbody

cosmic dagger
pine furnace
#

i tried to use a kinematic rigidbody and still doesn t print nothing in the debug menu when it collides

#

why

rich adder
#

i just told you why

pine furnace
#

nahhhh

#

and triggers work

rich adder
#

Triggers are not collisions

wintry quarry
pine furnace
#

ok thx

#

i tried to make the game in raylib till i needed collisions and i got lazy

rich adder
#

just stick to dynamic rigidbody and use .velocity

pine furnace
#

and i have another question

rich adder
#

easiest way to do collisions and paddle of your game

pine furnace
#

i tried to make a platformer and made a dynamic rigidbody but my jump didn t work

rich adder
#

probably using velocity and overriding AddForce

#

just a guess though

wintry quarry
#

That's not a question that's a statement

pine furnace
#

yessssss

cosmic dagger
pine furnace
#

i was using velocity to move left right and add force to jump

rich adder
#

when you set velocity just exclude the y

#

and addforce will work

#

.velocity = new (myMovingHorizontal, rigidbody.velocity.y)

pine furnace
#

i did it like this

#

let me find the file

wintry quarry
#

for 2D you can do myRb.linearVelocityX = myMovingHorizontal;

wintry quarry
# pine furnace

velocity should not have fixedDeltaTime multiplied into it btw

#

also your code is trying to read input in FixedUpdate which is wrong

#

input must be read in Update

primal trench
#

heyyy really dumb question
if i create a new list
new List<whatever>();
^
what goes there?

queen adder
#

do unity projects save to the cloud?

pine furnace
cosmic dagger
# pine furnace

reading input (like that) in FixedUpdate will skip (miss) those frames . . .

wintry quarry
primal trench
pine furnace
#

when do i use time.deltatime and time.fixeddeltatime

wintry quarry
pine furnace
#

it is confusing bc without this everything works fine on my computer

wintry quarry
#

velocity is already per-second

pine furnace
#

where can i find if something is perframe or persecond?

wintry quarry
#

it's not something you "find"

#

it's about understanding conceptually what your code is doing and what your variables mean

rich adder
pine furnace
#

i reintalled

#

vs

#

bc i was getting a lot of warning from unity

rich adder
#

yes but it needs to be configured

#

follow !vs

pine furnace
#

this one is configured

rich adder
#

ahh there we go

polar acorn
river halo
pine furnace
#

thanks for the help

cosmic dagger
#

@river halo do you have it?

rich adder
#

strings are very much sensitive to casing, spacing, and ofc missing characters lol
"I am a string"
Is not the same as "i am a string" etc.

lethal bolt
#

This should work rigth? but this happends?

wintry quarry
cosmic dagger
river halo
#

I added 3 levels level-1 level-2 level-3 Do I need to add these to my code?

rich adder
cosmic dagger
stuck palm
#

can you have base and inherited methods?

#

like classes?

rich adder
#

yea

cosmic dagger
dry pumice
#

can someone help me real quick, i want to make it so my player cant move/has limited movement mid air https://pastebin.com/syiKcBqx, im not much of a coder and need a lil help

rich adder
lethal bolt
cosmic dagger
river halo
#

How should I find the output?

#

I'm a little new

rich adder
dry pumice
rich adder
cosmic dagger
# river halo How should I find the output?

you should be able to tell already. you're adding the word Level plus the value of levelId. if you know what value levelId is, then you just combine them together. E.g., if levelId = 1, then the output is Level1

now, if that is true, you said, you added level-1 to the build settings, correct? is level-1 the same as Level1?

river halo
#

I pressed level 1 and it said 1

rich adder
#

is that the same as Level-1 ?

river halo
#

I understand

cosmic dagger
river halo
#

thank you very much for your help

#

I understand the problem

cosmic dagger
#

as navarone mentioned earlier, every single character and its case in a string must match for it to be equal . . .

warm condor
#

Hey guys, so my player has a boxcollider2d and is able to to movement like walk, run, slide, and crouch. The problem I'm having is that when there are platforms that the player can crouch/slide under and then stand up, the two box colliders clip into each other, which results in the sliding glitch throughout the whole game until I reset the game. Now I know that I can prevent this by detecting if there is something above the player's head, but that is something that I will be getting into later. What I want to know is if there is a way for the engine to not keep this glitch after getting out of the box collider clipping so that way, if there ever is this type of glitch in the future, at least it wouldn't keep that glitch through out the whole game.

cosmic quail
pine furnace
#

the left paddle is not moving

#

do u see any flaw

lethal bolt
#

that makes it not able to stand up

wintry quarry
rich adder
slender nymph
# pine furnace the left paddle is not moving

GetKeyDown is only true for the first frame you press the button. and since you set vertical to 0 every frame, you overwrite that value you assign. also you move the same direction no matter which button you press

#

look into using GetAxisRaw instead of querying each key individually. it even includes the 0 value when neither key is held

rich adder
#

btw you can just do
float verticalSpeed
...
verticalSpeed = Input.GetAxisRaw("Vertical")

warm condor
# lethal bolt You can cast a raycast

ohh ok, idk what raycast is, but ill look into that. I just wanted to know if there is a way I can get out of this glitch instead of having it the entire game if I ever get it somehow.

pine furnace
rich adder
#

alrighty

pine furnace
#

bc i have 2 player and to player 1 to assign w and s and to player 2 to assign up and down arrows

#

so i don t make 2 scripts

slender nymph
#

you could just make two separate axes

lethal bolt
pine furnace
rich adder
warm condor
wintry quarry
#

easier than.. what?

spark tulip
#

Question: Is it normal to create a service for methods like set, get, update, clear, and other operations related to a single item, such as a car? I want to retrieve data from the save system (SaveLoadSystem) on request for each car, meaning getting the same class but with different data. Additionally, there are other data about currency that I placed in a different service dedicated to currency data exchange. These services are unrelated to data saving. Is an interface implemented that collects all the data from the services and then saves it in a specified form or type? I thought about generalizing everything, but is this necessary (or is it needed)? Is it better to have one interface for each service required in the application as needed? Hmmm...

summer stump
warm condor
ionic zephyr
#

hi guys, how is this type of inventory created? the one that has buttons that switch to each category of the inventory? Is it made with actual Unity Buttons or is there a UI Element that I dont know?

slender nymph
#

that's just a tab view where each view just filters the items shown to a specific type

ionic zephyr
slender nymph
#

a view with tabs to switch between different views

#

and infact, that doesn't even need tabs. just buttons that literally just filter what is being displayed

ionic zephyr
#

depending on the Button you click In

slender nymph
#

well that's what a tab view would be. but again, this doesn't even need to be one. it just needs to filter which items are displayed

muted narwhal
#

It is filtering what displayed, not opening tabs

ionic zephyr
#

oh, okay I see, my intention was to use different tabs, so I get it now

muted narwhal
#

You basically can assign a specific type to every item and then display β€˜em in the inventory depending on the active filter, if you want that

marble hemlock
#

does anyone have a suggested video that helps with creating first person movement and mostly gets straight to the point?

slender nymph
#

"the point" of tutorials are to teach you how and why you do certain things. if you are just looking for a video that just gives you the code to copy then good luck πŸ‘

queen adder
marble hemlock
#

ill just watch a bunch and see what overlaps until something clicks in my brain

rocky canyon
#

the click method.. it works.. results may vary

rocky canyon
rocky canyon
edgy vine
#

I am creating a 2D sandbox game within Unity using Alteruna for multiplayer. I have a script that uses a sprite renderer to render everyone elses curser on peoples screen so they can see. Currently though all cursors from other clients all go to the main client mouse position. How would I keep the mouse position different from everyone elses then sync the positon?
TLDR: How to do client sided move sprite onto mouse position then sync using Alteruna?

marble hemlock
#

i mostly remember my way around the UI and such but lots of things just sorta disappeared over the past year or so

rocky canyon
#

happens..

vernal ocean
#

hey, whenever i try to create New Project i get this error, is there anything i can do?

languid spire
#

check the hub !logs

eternal falconBOT
#
πŸ“ Logs

Documentation

Editor logs

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

Unity Hub

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

#
πŸ“ Logs

Documentation

Editor logs

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

Unity Hub

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

rich adder
vernal ocean
#

thanks ill do my best ❀️

echo ruin
#
    void Start()
    {
        Debug.Log("Start");
    }

    void Update()
    {
        if (Input.GetKey(KeyCode.T)) 
        {
            Debug.Log("T has been pressed.");
        }
    }```
Does anybody know why the Start debug runs but the Update one doesn't?
rich adder
polar acorn
echo ruin
#

Yes

#

I tried to change the key as well

languid spire
#

Or you're not pressing the T key, or the old input system is not enabled or... or...or...

polar acorn
#

Show a screenshot of this object's inspector while the game is running

marble hemlock
#

ive ended up spending far too much time in blender now 😭

#

i mean im not good at it, prob cuz im not actually watching any tutorials but
i mean now i kinda get how map building works so πŸ‘

rich adder
#

but what does this have to do with coding questions?

marble hemlock
#

fascinating question

#

well uh i dont have an answer

rocky canyon
echo ruin
#

It also works when I remove the if statement

rocky canyon
#

then its ur input.. do you have the old input system enabled

echo ruin
#

I don't even know what the old input system is

rocky canyon
#

lol.. that means its probably still turned on

rocky canyon
#

edit -> project settings -> player -> other settings -> active input handling

echo ruin
#

It was set to old

rocky canyon
#

then ur inputs should be registering πŸ€”

#

the Input. class is the old

echo ruin
#

I changed from old input to Both and now it works

vital tangle
#

Hi

#

I have a trouble with json

rocky canyon
unborn rampart
#

anyone that has an idea on how to code guis?

#

im a fast learner ig

rich adder
rich adder
vital tangle
#

You see i have a json string which is serialized

and instead of deserializing the string back to a object? class type

i am deserializing it back to JObject

Now my goal is to change the key name of every keyvaluepair<string, object?> inside the jobject i got

#

i dont know how to do that?

#

google aint documented about this

#

if i use a foreach loop like this

#
        {

            //if (kvp.Value is JObject)
            {

            }
        }```

I can only loop and read the keys
#

not write them

unborn rampart
languid spire
#

Can't do that thew keys are immutable

vital tangle
#

not documented

languid spire
vital tangle
#

i failed
cuz i lack the complete knowledge of how json works

rich adder
#

json is nothing special

#

its only a kvp with special text formatting

vital tangle
#
    {
        List<KeyValuePair<string, object?>> ks = new List<KeyValuePair<string, object?>>();
        ks.Add(new KeyValuePair<string, object?>("paint", "this"));
        jobj.ReplaceAll(ks);
        string jsn = JsonConvert.SerializeObject(jobj, Formatting.Indented);

        return jsn;
    }```
vital tangle
#

just like how websites highlight their codes

vital tangle
#

so i am kinda out of ideas how to achieve the result

wintry quarry
languid spire
#

you do realize that this
ks.Add(new KeyValuePair<string, object?>("paint", "this"));
is nonsense

vital tangle
#

yea sadly

rich adder
#
 JObject paintedJobj = new JObject();
        foreach (var property in jobj.Properties())
        {
            string paintedKey = $"<span style=\"color: red;\">{property.Name}</span>";
            paintedJobj.Add(new JProperty(paintedKey, property.Value));
        }
``` try it but might not work
#

use spans for html

wintry quarry
#

Is the goal here just to display formatted json with color coding on a web page or something

#

I think the correct approach is probably not to use JObject but instead write a custom NamingStrategy:

https://www.newtonsoft.com/json/help/html/T_Newtonsoft_Json_Serialization_NamingStrategy.htm and then you add your custom formatting in ResolvePropertyName: https://www.newtonsoft.com/json/help/html/M_Newtonsoft_Json_Serialization_NamingStrategy_ResolvePropertyName.htm

This example shows how to use a special naming strategy with JsonConvert:
https://www.newtonsoft.com/json/help/html/NamingStrategyCamelCase.htm

silver lagoon
#

I have an object which is a prefab that has an instance in the scene editor. If I delete the prefab, will the instance be deleted too?

wintry quarry
vital tangle
#

see this visual studio
how it highlights the json

the whole json is like a JObject and has key value pairs

one the first 2 are keyvaluepairs<string, int?>

the 3rd one is a keyvaluepair<string, JObject?>

and the last one is from the 3rd key value pair JObject which has only one keyvaluepair<string,string?>

i just want to somewhat achieve the same color highlight

by added this arround the string key
<color=#FFFFFF>Key</color=#FFFFFF>

wintry quarry
vital tangle
#

sorry for the delay

wintry quarry
vital tangle
silver lagoon
wintry quarry
silver lagoon
#

Thank you

stark girder
#

I want to change items in hand with mouse wheel or numbers on keyboard but the mouse keeps overwriting the numerical inputs

languid spire
#

well it will, think about what happens if NO key is pressed

primal trench
#

how do i change the index of an array item?

languid spire
#

you move the item to a different location in the array

primal trench
languid spire
#

what like
int[] a
a[2] = a[0]
i.e. copy index 0 to index 2

primal trench
languid spire
#

no

rich adder
#

arrays cannot remove elements

#

they are fixed sizes / length.
Also no way assigning would remove ANY element

wintry quarry
stark girder
wintry quarry
#

else happens no matter what

#

you only want it to happen when there's mouse scroll input

stark girder
rich adder
#

I recall someone using keycode int cast inside an array to make this easier than a giant if else chain

wintry quarry
stark girder
wintry quarry
#

e.g.

for( int i = 0; i < 9; i++) {
  KeyCode k = (KeyCode)((int)KeyCode.Alpha1 + i);
  if (Input.GetKeyDown(k)) INVindex = i;
}```
#

This is much better than 8-9 if statements^

rich adder
#

I have to save this cause I keep forgetting it πŸ˜›

wintry quarry
#

Ok it needs to be this to compile (also fixed above):

KeyCode k = (KeyCode)((int)KeyCode.Alpha1 + i);```
vital tangle
#

hey suppose i have something that takes arguement as object?

#

how do i specify its object type

slender nymph
#

can you elaborate? because it sounds like you want a method parameter and for that you just . . . use the type you want for the parameter

vital tangle
#
        foreach (var kvp in jobj)
        {
            KeyValuePair<string, JToken?> keyValue = new KeyValuePair<string, JToken?>("<color=00FF08>" + kvp.Key + "<color=00FF08>", kvp.Value);
            obj.Add(keyValue);
        }
#

now the arguement it takes is this JObject.Add(object?)

slender nymph
#

ah so this is a continuation of a previous conversation that i don't feel like going through to understand what you are doing or why

vital tangle
#

and i am giving it JObject.Add(KeyValuePair<string, JToken?>)

slender nymph
#

because i simply don't want to. someone else who is more familiar with whatever you are doing or who wants to read through that previous conversation can help you

vital tangle
#

ok

#

I did it

vital tangle
paper plaza
#

where do i ask for help for lighting problems?

fickle stump
#

Is there a way to 'block' a gameobject from beeing pressed until an animation is finished? nowayHmmm

#

i mean blocking as in the player cant click it again

tidal kiln
#

disable it

wintry quarry
fickle stump
#

if i disable it doesnt it get unloaded basically?

tidal kiln
#

no

#

if you set the gameobject to inactive it does

#

disable the script

wintry quarry
#

we don't even know if there's a script involved yet

fickle stump
tidal kiln
#

component

fickle stump
#

wait one sec

wintry quarry
#

yes I want the honest answer of course

#

because it's the only way to answer your question

fickle stump
#

what was the command for the linking code?

wintry quarry
#

!code

eternal falconBOT
fickle stump
#

ah mb

tidal kiln
#

its all scripts/components, even unity built in buttons. you just set whatever handles the click component.enabled = false

fickle stump
tidal kiln
#

oh wait my bad

#

default button is something else

fickle stump
#

so i disable the script?

wintry quarry
#

or use a StateMachineBehaviour

fickle stump
#

i see

tidal kiln
fickle stump
#

basically im gonna check if an animation is playing, if not, it goes into the if (animator != null) and lets me play it

graceful walrus
#

Hello, I am making a third person controller an I want to enable and disable an input action for the mouse delta, whenever the Cursor.lockState changes from Locked. The problem is that there is no event for this change of state. How can I achieve this?

tidal kiln
#
var clip = animator.GetCurrentAnimatorClipInfo(0);
var seconds = clip[0].clip.length;
yield return new WaitForSeconds(seconds);
fickle stump
#

i dont think i ever worked with a coroutine

#

i'm still super noob

tidal kiln
#

time to start. they are really helpful

fickle stump
#

wil ltry

#

ty

burnt vapor
#

This is either overcomplication or you are too lazy to make actual classes, in which case I suggest you just stick to classes and serialize those

#

If it's neither and this object actually has multiple types then I suggest you split them. JObject should not be used like this

graceful walrus
#

Is there not a way to check this before the input is processed? Maybe in the binding's processor?

burnt vapor
#

Event also goes in the manager

vital tangle
#
    {
        JObject obj = new JObject();
        foreach (var kvp in jobj)
        {
            obj.Add("<color=#FF8800>" + kvp.Key + "</color=#FF8800>", kvp.Value);

            if (kvp.Value is JObject)
            {
                JObject nObj = (JObject)kvp.Value;
                string strn = paintKeys(nObj);

                JObject mObj = JsonConvert.DeserializeObject<JObject>(strn);

                obj["<color=#FF8800>" + kvp.Key + "</color=#FF8800>"] = mObj;
                Debug.Log("it reached here");
            }
        }
        string str = JsonConvert.SerializeObject(obj, Formatting.Indented);
        return obj.ToString(Formatting.Indented);
    }```
#

but i am still having one last trouble

burnt vapor
#

You fixed it but I still see multiple instances of JObject

vital tangle
#

you see i am checking here if the value is again a JObject

#

if (kvp.Value is JObject)

#

how can i know if the Value is an array

burnt vapor
#

Why is this taking a JObject to begin with? Where is this code from?

burnt vapor
#

Either way it doesn't matter, your code always expects the same things so you should deserialize the JObject into a readable class before you do anything else in the method

#

Right now you are practically parsing and considering it's not varying data it makes no sense

vital tangle
burnt vapor
#

So is the point to just modify the keys of a bunch of key value pairs?

#

You should still be able to do what I said. It would save you having to constantly deserialize/serialize code

#

If the point is specific to a key then you should probably also just use an interface so that it can be abstracted to any key-value pair

vital tangle
#

so i had to cast

hushed hinge
glad rune
#

i am making flappy bird how would i immobolize the player gravity included without stopping time

wintry quarry
glad rune
#

the thing navarone said i meant that

vital tangle
#

whenever i use this foreach loop
the cast doesnt work

#

                foreach (JToken ajt in array.Children<JToken>())```
#

i thought that JArray just contains child JTokens which could be parsed into JObject

pallid nymph
#

so check what's the actual type of kvp.Value and adjust code to properly handle

#

also, can't you parse into a proper typed object instead?

vital tangle
pallid nymph
#

not sure that's how you should do it... but haven't thought about it

vital tangle
# pallid nymph so check what's the actual type of kvp.Value and adjust code to properly handle

here is the complete code

    {
        JObject obj = new JObject();
        foreach (var kvp in jobj)
        {
            if (kvp.Value is JObject)
            {
                JObject nObj = (JObject)kvp.Value;
                string strn = paintKeys(nObj);

                JObject mObj = JsonConvert.DeserializeObject<JObject>(strn);

                obj["<color=#FF8800>" + kvp.Key + "</color=#FF8800>"] = mObj;
                Debug.Log("it reached here");
            }
            if(kvp.Value is JValue)
            {
                obj.Add("<color=#FF8800>" + kvp.Key + "</color=#FF8800>", kvp.Value);
            }
            if(kvp.Value is JArray)
            {
                JArray array = (JArray)kvp.Value;

                JArray narray = new JArray();

                for(int i = 0; i < array.Count; i++)
                {
                    Debug.Log(array[i].Type);

                    //JObject aobj = (JObject)ajt;
                    //string astr = paintKeys(aobj);
                    //JObject naobj = JsonConvert.DeserializeObject<JObject>(astr);
                    //narray.Add(naobj);
                }
            }
        }
        string str = JsonConvert.SerializeObject(obj, Formatting.Indented);
        return obj.ToString(Formatting.Indented);
    }```
hushed hinge
vital tangle
pallid nymph
#

where exactly does it fail actually? on which line?

vital tangle
#

only for JArray

#
            {
                JArray array = (JArray)kvp.Value;

                JArray narray = new JArray();

                for(int i = 0; i < array.Count; i++)
                {
                    Debug.Log(array[i].Type);

                    //JObject aobj = (JObject)ajt;
                    //string astr = paintKeys(aobj);
                    //JObject naobj = JsonConvert.DeserializeObject<JObject>(astr);
                    //narray.Add(naobj);
                }
            }```
#

i cant seem to parse it correctly

pallid nymph
#

exact line

vital tangle
#

take it here where i cast the JToken

pallid nymph
#

like, what's the problem... because the cast can't be, as you've already made sure that kvp.Value is indeed a JArray

vital tangle
#

JObject aobj = (JObject)ajt;

vital tangle
pallid nymph
#

but it may not be a JObject... it bould be a value or array, no?

vital tangle
#

yea i debugged its type

#

its quite tricky

#

cause it shows twice that its type is a Object

#

and 99 times its an int

#

and i cant figure out how it works

#

the component of the array

#

not the array itself

#

the component like array[i] in loop

pallid nymph
#

what's the type of array[i]? I assume it's JSomething that's parent of all the array and other ones, no?

vital tangle
#

wait let me give example

rich adder
#

large code should be shared via links

tranquil hollow
#

the particle dosent turn off when Im in the air, can somebody help me?

tranquil hollow
tranquil hollow
tranquil hollow
pallid nymph
# vital tangle its a simple JArray

the array is JArray, array[i] is JToken, which could be one of several things... so you need to handle those, maybe you need to call the function recursively, or just deal with the JToken somehow, no idea

rich adder
vital tangle
#

now take this as example

  "Cages": {
    "Array": [
      {
        "Dogs": 2,
        "Cats": 4
      },

      {
        "Dogs": 6,
        "Cats": 1
      }
  }
}```
#

its an array

vital tangle
#

the whole thing is a JObject
You parse the JObject and get key and values

i check if the value is simple text or is another JObject

#

i can do that pretty easily

#

but what Array does is that it has an array of JObject

#

like JObject[]

#

but when i try to cast it

pallid nymph
#

it has JToken[]

vital tangle
#

it doesnt work

rich adder
pallid nymph
#

which can be JObject, JArray, JWhateverElse

vital tangle
#

yea

tranquil hollow
vital tangle
#

but mostly its JObject

#

the Json i am trying
it should be JObject

pallid nymph
#

and if it's not - it throws an exception

vital tangle
#

but it still fails

vital tangle
pallid nymph
#

it fails, because it's not JObject

#

there are no maybes πŸ˜„

rich adder
steel stirrup
rich adder
#

kinematic will freeze the whole rigidbody not just gravity, is that what you want?

glad rune
#

yeah