#💻┃code-beginner

1 messages · Page 40 of 1

warm lichen
#

yes basically

swift crag
#

assuming you are using Unity UI, you want a Vertical Layout Group

swift crag
#

jinx

silk night
#

this might be what you want

#

damnit xD

swift crag
#

probably alongside a Scroll Rect

warm lichen
#

thanks guys

lilac crow
#

got fixed , thank you for your time! THANK YOU! 😘😘🌹🌹🌹🌹🌹🙏🙏🙏🙏
a simple solution but annoying problem for noob like me 😅😅

swift crag
#

Hm, but that doesn't mean we've fixed it yet

#

So that made you move really fast?

lilac crow
#

i changed it to 20f and got fast

swift crag
#

It seems weird that a speed of 12 was no faster than a speed of 6

#

Here's a hail mary: do you have "Apply Root Motion" checked on the Animator?

#

I am wondering if your walking animation included root motion that was making the animated object move forwards.

#

That could make you appear to move faster than you should while walking

lilac crow
#

is posible that animation speed is problem?

swift crag
#

Animation speed should have nothing to do with movement.

#

But if "Apply Root Motion" is checked and only the walking animation has root motion, that could cause this weirdness

#

It would also make you appear to spin around really fast when turning.

lilac crow
#

i download both from mixamo , but ill check it with root motion

swift crag
#

unless the animated object was the root of your character, in which case it'd just speed you up

#

Mixamo animations can definitely have root motion.

#

so:

  • uncheck "apply root motion"
  • set the run speed back to 12
  • see how it feels now
lilac crow
#

sure

swift crag
#

Root motion lets you move a character directly with animations. It can give you very realistic movement -- you aren't trying to match the animation to your own fixed move speed.

#

super useful for things like dodge rolls, too

random ether
#

I updated the script to this. The player has the right tag, and it has a box collider and Rigid body. The object with the collision logic also has a box collider with trigger on and a rigid body. A script as simple as this has never not worked for me. I have no clue whats wrong

swift crag
#

But if you aren't intending to use it, you can get surprised

lilac crow
swift crag
#

So running is now twice as fast as running?

random ether
#

wait i fixed it

lilac crow
swift crag
#

Ha, so that was it!

#

If you look at the animation clips, the walk cycle should make the preview model actually walk forwards

#

whilst the run cycle should not

lilac crow
swift crag
#

You can either turn off root motion entirely, or you can check the "Bake..." options on the animation clip

#

Even when using root motion, I don't want my idle animation to make a character slowly slide around

#

so I check all the boxes

#

link's "got an item" animation has a very very tiny bit of root motion

#

he slowly slides away

swift crag
#

that's the key thing

#

if an office chair is the object, then root motion is rolling the chair around

#

non root motion is getting up and walking around your room

lilac crow
swift crag
#

So you want the character's back to always face the camera?

#

one option would be to just rotate the character, and have the camera stay behind the player

swift crag
#

Tilting the camera down would make you fall over

#
Vector3 forward = Camera.main.transform.forward;
forward = Vector3.ProjectOnPlane(forward, Vector3.up);
transform.forward = forward;
#

This will get rid of the up-and-down part of the vector

#

also, to make your character move in the right direction, since I bet you're wondering about that...

#
transform.TransformDirection(movementVector);
lilac crow
swift crag
#

This will convert movementVector from local space to world space

#

So if you hold W, the character moves in their forward direction

swift crag
#

the camera just follows behind

lilac crow
#

so how should i make that possible .
with character control component?

swift crag
#

The CharacterController doesn't really care abour rotation

#

So you'd just be rotating the player separately

#

I would suggest storing a float

#

That float will be the angle the character is facing.

#

use your X-axis input to add to the angle

#

then do transform.rotation = Quaternion.AngleAxis(angle, Vector3.up);

#

AngleAxis takes an angle and an axis and gives you a rotation

minor moss
#

Someone know why I can't see my bird when im in game but in scene?

lilac crow
#

thank you i'll do what you said.😘 🌹
again thank you for your time . 🙏🙏
i annoyed you too much!😅

#

and thank you for your explanations i've learnd the things that i didnt knew.

swift crag
#

no problem (:

swift crag
#

you need to provide more context or it'll be hard to help you

#

Perhaps the sprite has a weird Z position. It could be behind the camera

minor moss
polar acorn
swift crag
#

I'm talking about the Z axis.

#

That's the one that points into the screen in a 2D game

minor moss
#

I meant Z sorry

swift crag
#

Turn off 2D mode and have a look at your scene

#

If they're both at Z=0, then that won't work

#

the camera has a minimum distance before which nothing gets rendered

#

Put the camera at Z=-10 or something like that

minor moss
#

I think the problem is that I added a gravity system so it just falls down so fast

#

Since when I play it looks like this

swift crag
#

well, that also sounds like a problem

#

but if the camera and the bird are both at the same Z coordinate, you'll never see the bird

#

Fix that.

minor moss
#

Ah okay

#

I changed now so the camera is Z -10 but I still don't see it

polar acorn
#

So now see about that gravity thing

swift crag
#

pause your game, then hit play

minor moss
short hazel
#

You may have a script that warps the camera to Z = 0, if you wanted the camera to follow the player

minor moss
#

This is the only script I got

astral basin
#

hello, in the video is code i wrote that check if a scene is the one loaded and then sets a bool to true, then if the bool is true it prints "interactable", i made it so the if statements only ran once using a bool to detect it, so why does it print "interactable twice? any help or direction will be appriciated, thanks

polar acorn
astral basin
#

is it possible that the dont destroy on load resets the script?

polar acorn
astral basin
#

the new scene doesnt have a copy, it only gets it when the scene is loaded and the object from the last scene comes into the new one

#

and whenever there are two of the same, i made it so one gets destroyed

#

could it be that unity reads the script before destroying it?

polar acorn
#

Show the !code for it

eternal falconBOT
astral basin
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DDOL : MonoBehaviour
{
 
    public GameObject ab;
    // Start is called before the first frame update
    void Awake()
    {
        DontDestroyOnLoad(ab);
    }

    // Update is called once per frame
    void Start()
    {
        int numberOfTaggedObjects = GameObject.FindGameObjectsWithTag("mainCanvas").Length;
        DontDestroyOnLoad(ab);
        if(numberOfTaggedObjects > 1)
        {
            Destroy(GameObject.Find("mainCanvas"));
        }
    }
}


#

the object that holds the script is the mainCanvas, this is the script that moves it from scene to scene and destroys it if theres a clone

swift crag
#

you're finding things with a tag

#

then destroying things with a name

#

that seems odd.

astral basin
#

yes since when you find things with tags it gives you all objects with that tag, i used name because i only one to delete one of the maincanvas, so theres one left as there should be

polar acorn
#

Also, if you ever have three objects at once this breaks. You would queue up three destroys on the same object

astral basin
#

its impossible that there will be three objects, thanks for the heads up though

astral basin
eager elm
#

probably because you have it twice in your scene

astral basin
#

so how do i destroy the object before unity reads the script inside it

#

or is there a way to check if a script has already ran before?

#

wait

eager elm
#

first of all, why the heck do you need a canvas to be DDOL? To your question, you would check in Start if an object with the tag mainCanvas already exists, and if it does you destroy yourself.

#

I assume not both objects get instantiated at the same time, right?

astral basin
swift crag
#

Explain what you're trying to make your game do here.

astral basin
#

okay

#

im trying to move the maincanvas from scene to scene, since it has the player in it and all of the achievment ui, and i need that data to move between scenes, so i made it DDOL, i think the problem is that when you first start the game, the maincanvas already becomes a DDOL, therefore when you go back to the scene there are two canvass and the script runs twice, so it there a way to make the object DDOL only when you are not inside the first scene? is what im saying making sense or do i need to rephrase it

swift crag
#

Your component should check if an instance already exists. If one does, it should destroy itself.

#

Awake isn't going to run many times on DDOL'd objects' components

#

It runs once, when the object is first created.

astral basin
#

yeah i used awake just beacuse i didnt know what it did, i deleted it, the DDOL command is in the start function now

#

the thing is

swift crag
#

Awake and Start will probably both work fine.

#

But what you can't do is just grab a random object with GameObject.Find

#

I'm not sure which object that'll wind up grabbing

astral basin
#

yeah

swift crag
#

is ab the object holding the canvas?

astral basin
#

ab is the maincanvas yes

swift crag
#

you should make a static field that references this canvas. If it equals null, put the canvas in there and DDOL it

#

If it's not null, destroy your canvas (and yourself)

#

Now, even if you create many copies of this thing in the scene at once (which probably won't happen), one will get moved into the DontDestroyOnLoad scene and the rest will be destroyed

swift crag
astral basin
#

one gets created at the start of the scene, when i press play, the other is the one that comes with me to every scene

#

what if i make it so when you press the move scene button the maincanvas gets destroyed so that when you come back its not even there?

swift crag
#

if you can create a new one every time you load a scene without losing any data, then sure

astral basin
#

one sec, im completely lost, nothing works, so we took it down to the issue where there are two canvasas in the scene after you load back, so is there a way to make sure theres only one canvas in the firstplace? so that i dont need to use destroy, so that the canvas wouldnt even be there and the script wont be called twice, im sorry i know this is confusing but im not really sure how to phrase what im saying, i just think if the second canvas iisnt there in the firstplace it would be easier

swift crag
astral basin
#

i dont get what you mean by put the canvas in there and ddol it

#

what do i do in here

swift crag
#
public static Canvas canvasInstance;
public Canvas myCanvas;

void Awake() {
  if (canvasInstance == null) {
    canvasInstance = myCanvas;
    DontDestroyOnLoad(canvasInstance.gameObject);
  } else {
    Destroy(myCanvas.gameObject);
  }
}
#

something like this

#

I'm assuming that this component is attached to the same object as the canvas. If not, then it should also destroy its own game object afterwards, I suppose.

unreal imp
#

my dear freinds i need help with this,my code is executing a bunch of particles and I just want to generate one,the code: public bool isInFire = false; public GameObject fireParticles; private GameObject fire; if (isInFire) { fire = Instantiate(fireParticles, transform); if (!fire.active) { hitsReceived = maximalHitsToDestroy; } }

swift crag
#

well, since you haven't shown any context, it's hard to say much

#

please share the whole script

unreal imp
#

ok

swift crag
#

I'm guessing that the code is getting run many times, thus spawning many fire particles

astral basin
unreal imp
#
    public GameObject explosionParticlesPrefab;
    public int minimunHitsToDestroy = 6;
    public int maximalHitsToDestroy = 12;
    public int hitsReceived;
    public float impactForceScale = 1.0f;
    public float velocityOfImpactForExplode = 7f;
    public float velocityOfCollisionByObject = 4f;
    public bool isInFire = false;
    public GameObject fireParticles;
    private GameObject fire;
    public int random;
    public int random1;
    public int random2;
    public float maxDetectionDistance = 10;
    public float maxDetectionForce = 5;
    [System.Obsolete]
    private void Start()
    {
        random2 = Random.RandomRange(1, 5);
        random1 = Random.RandomRange(minimunHitsToDestroy / 2, maximalHitsToDestroy / 2);
        random = Random.RandomRange(minimunHitsToDestroy, maximalHitsToDestroy);
    }

    [System.Obsolete]
    void Update()
    {
        if (hitsReceived >= random)
        {
            //if (random2 <= 3)
            //{
                Instantiate(explosionParticlesPrefab, gameObject.transform.position, Quaternion.identity);
            //}
                Destroy(gameObject);
            Vector3 position = gameObject.transform.position;
            Quaternion rotation = gameObject.transform.rotation;
            GameObject sherds = Instantiate(toiletSherds, position, rotation);
        }
        if (isInFire)
        {
            fire = Instantiate(fireParticles, transform);
            if (!fire.active) {
                hitsReceived = maximalHitsToDestroy;
            }
        }
    }```
acoustic arch
#

hey is there a way an image on an item can be completely nothing? i have it set to none yet it still has a square sprite

swift crag
#

...why do you have [System.Obsolete] on your methods?

swift crag
unreal imp
#

because the system recommended it to me

swift crag
#

Or set the image's color to have zero alpha, I guess

acoustic arch
swift crag
swift crag
#

Ideally, you'd encapsulate all of this in a method

unreal imp
#

wait,what means in particle system the simulate method?

acoustic arch
swift crag
#
public void ShowItem(Item item) {
  image.color = Color.white;
  image.sprite = item.sprite; 
}
swift crag
#

are you talking about these properties of the ParticleSystem?

astral basin
unreal imp
swift crag
#

Do you need the one that's already in the scene?

astral basin
#

yes i need the old one to get destroyed

swift crag
#

Okay, you want the old one to die.

astral basin
#

no i need the one that is moving from scenes

#

exactly

swift crag
astral basin
#

no

swift crag
#

the old one is the one that's currently in the DontDestroyOnLoad scene

astral basin
#

when you move scene, one canvas stays in the scene and the other moves with you. the one thats being destroyed is the one thats moving with you from scenes

swift crag
swift crag
#

nothing "stays" in the old scene

#

the old scene is gone

astral basin
#

let me remove the destroy and show you what i mean one second

unreal imp
astral basin
#

this is what i mean. the old canvas is the one that is staying in the scene and the player doesnt move correctly in, thats the one i want to delete

astral basin
eager elm
# astral basin when i do that the canvas just destroyes itself as soon as i press play

your approach is just gonna give you more and more problems, notice how the old canvas lost it's reference to the camera? I still don't see why you need the canvas so persist, could you show us what's in there and needs to not be destroyed?
Having your player walk on a canvas is also a little strange, usually you would use SpriteRenderers and have them walk around the scene without a canvas

opal fossil
#

when is scriptableobject onEnabled called?

rich adder
flat solstice
#

my animation is stuck at frame 1 (can transition to self is unchecked)

        animator.SetInteger("State", (int)state);
        animator.SetInteger("Direction", (int)direction);

this is the code for the animator

#

it's on update

flat solstice
#

@rich adder

#

it's inside a sub-state machine

rich adder
# flat solstice

I'm not even sure whats supposed to be what. im guessing having conflicting anystates with diff integers is causing issues

#

have you inspected the animator while in playmode if you click the animator you will see whats going on transitions wise

flat solstice
#

the anystates don't really conflict, up is for integer 0, side for integer 2, and down for integer3

#

i'll post it in a second

#

@rich adder

rich adder
#

like it constantly playing?

flat solstice
#

it's stuck on up's first frame

rich adder
#

right

#

did you make the state "Not Transition to Self"

flat solstice
#

yes

rich adder
#

cause it sounds like thats what its doing tho

#

the code is in update also causes it

acoustic arch
#

im trying to make a way that when each inventory slots button is pressed it becomes selected, how would i make an int thats equal to the slot selected?

golden ermine
#

How can I add days counter to this script?

acoustic arch
#

but i cant figure how to let the code know which slot was clicked

flat solstice
bitter carbon
#

how to destroy clones?

flat solstice
#

wait

#

I got it

#

I have to make a "base" state inside the layer

rich adder
bitter carbon
rich adder
bitter carbon
#

k

golden ermine
rich adder
#

nothing simpler than adding to a timespan

#

you could also just store ticks

#

then translate it to formatted time when needed

golden ermine
#

can i do that?

rich adder
#

how do you even define what a "new day" is

short hazel
#

Complexifies it, since you now need to handle multiple variables, and not forget to increment them when needed

bitter carbon
rich adder
#

whats that mean

#

I have no context to ur code and what ur trying to do

short hazel
golden ermine
rich adder
#

I often just store in ticks since thats only an int

bitter carbon
rich adder
#

StartTimespan and then Timespan when you're checking gives you the elapsed time

golden ermine
golden ermine
#

oh sorry

rich adder
#

example

#

or if you dont want to store a bool on the playerscript itself make a dictionary

#

idk what conditions u want for it set to destroy

golden ermine
rich adder
#

you don't have to do any ++ counter

bitter carbon
#

i just wanna destroy all those after an if statement basically

golden ermine
#

do*

rich adder
rich adder
#

that will display whatever time has passed with timespan
lookup how timespan struct works, its very handy

bitter carbon
#

yea but how? i dont get how to reference each object in those loops

rich adder
#

you loop thru them in a list

bitter carbon
#

idk how to do that

#

gtg anwyay\

inner marsh
#
{
    [SerializeField] Transform EquipmentsParent;
    [SerializeField] EquipmentSlots[] EquipmentSlots;

    private void OnValidate()
    {   
        EquipmentSlots = EquipmentsParent.GetComponentsInChildren<EquipmentSlots>();
    }
}``` i dont understand what the error is, everything works fine but it has a problem with object reference
rich adder
#

EquipmentsParent.GetComponentsInChildren<EquipmentSlots>(); ?

inner marsh
#

yes

rich adder
#

is the second screenshot inspector in playmode ?

#

and are you certain you don't have a clone of this script?

#

type t:EquipmentPanel in your hierarchy's search

inner marsh
rich adder
#

make sure there's no copy

golden ermine
#

is this okay @rich adder

rich adder
short hazel
#

And why two TimeSpan, when one would be sufficient, since it can handle pretty much all time units at once

sand veldt
#

!code

eternal falconBOT
golden ermine
glad ore
#

how to make environment black , i removed skybox , still getting a plain blue sky ,
i am new to URP . changed the camera settings too .

rich adder
short hazel
sand veldt
#

need help with animator trigger
the customer has only 2 trigger walk and sit and i have set animation to loop
but the customer sit only for a .2 sec and start walking again
https://gdl.space/ebicebaquq.cs

#

am i not using trigger correctly

inner marsh
acoustic arch
#

i have an inventory slots array with all of them in it

rich adder
acoustic arch
#

does anyone know how i could achieve this

golden ermine
inner marsh
#

im not even getting said error now anymore so ig im good ty for help

rich adder
golden ermine
#

so it will add days like i wanted to right?

ashen ferry
#

how do I instantiate prefab as like legit blue tinted prefab prefab with code

short hazel
#

This is direct compiler output, and I didn't know 51278 minutes would equal to roughly 35 days. You don't need to know and calculate yourself either, so let the runtime handle it for you

buoyant knot
#

How do you write a method like TryGetComponent, where it has an out component that only gets written if it returns true?

short hazel
#

With an out parameter in the declaration

#

The compiler will then force you to assign a value to that parameter before any return (or the end of the method) is encountered

buoyant knot
#

so does TryGetComponent just assign null if it returns false?

slender nymph
#

yes

buoyant knot
#

then how would Dictionary's TryGetValue method work? the output could be a struct

short hazel
#

It assigns default, which is type-agnostic

#

The default value for the type

buoyant knot
#

ah. I didn't know that keyword. ty

echo spindle
#

Hello there. I am new here also beginner. Can anyone help me for my camera script?

slender nymph
golden ermine
short hazel
#

For the third time, you need only one time span variable

golden ermine
#

so i only need to have TimeSpan currentTime;

short hazel
#

As long as there's still 60 minutes in an hour, and 24 hours a day in your universe, you're good with one TimeSpan

golden ermine
#

whole day is minuteLength

short hazel
#

That's not what I'm talking about

golden ermine
short hazel
#

I'm not talking about how many real minutes a game day is

golden ermine
#

oh okay

#

so what now

short hazel
#

You're doing the math for that already, what matters is whether 60 minutes in your game is 1 hour in your game
And whether 24 hours in the game is a day in your game

golden ermine
short hazel
#

You're done

#

The code for handling time is complete

golden ermine
#

yea but it still doesnt count days

short hazel
#

It does

#

It's in currentTime.Days

#

Try and print it, after 15 minutes of real time it'll say 1

golden ermine
#

oky i will try

acoustic arch
#

how do i referenece the object of the button clicked

short hazel
#

Depending on where you want to get the object is should just be gameObject lol

golden ermine
#

nice, it counts but it starts with a zero not an one

#

i put that here

rich adder
#

just +1 lol

short hazel
#

Yes because the first 24 hours is before the first day's end

rich adder
#

or start it from timespan with an added day

golden ermine
short hazel
#

Better method, so you don't need to do +1 everywhere

#

And forget it in one place, and wonder if you have a bug

golden ermine
#

okay how to display that here, in dayText;

rich adder
#

the same way you did it in your debug

#

wdym

golden ermine
#

no like in game

#

on text

#

TMP_Text

short hazel
#

Probably with the d format string

#

You need to look at the docs mate, before using anything that's not extremely simple

cyan wigeon
#

what does the #2 mean ?

rich adder
#

you should know its your asset xD

short hazel
#

Hm, second touch screen lol?

golden ermine
rich adder
#

maybe two finger touch buttons?

cyan wigeon
#

well thats kinda what I hope it is xd

#

Im just trying to get single vs multiple finger touch using unity input system

#

but I cant find documentation that says waht these mean

rich adder
#

I've yet to use touchscreen with new input system 😮

#

doc isn't mentioning anything about a #

cyan wigeon
#

I just want 2 separate inputs for touchscreen that can be set to button

#

cuz I cba to write logic for dragging and I just want to test 2 different actions on mobile

rich adder
#

im sure it possible

#

if Input class can do it

#

im sure this can too

cyan wigeon
#

ye im sure it is I just wondered if anyone knows waht those are

#

would save me some time figuring it out 😄

golden ermine
acoustic arch
#

public GameObject ItemSelect() { GameObject slotSelected; //Object of slot selected int slotValue = EventSystem.current.currentSelectedGameObject.GetComponent<Slot>().slotNumber; //Slot number slotSelected = inventorySlots[slotValue].gameObject; //Slot Object return slotSelected; }

#

how would i then use the slotSelected variable? after returning it

slender nymph
#

three backticks, not just one

#

and you store the returned value in a variable that you can then use

acoustic arch
slender nymph
#

sure

acoustic arch
#

outside of the method

acoustic arch
# slender nymph sure

GameObject slotSelected; public GameObject ItemSelect() { int slotValue = EventSystem.current.currentSelectedGameObject.GetComponent<Slot>().slotNumber; //Slot number slotSelected = inventorySlots[slotValue].gameObject; //Slot Object return slotSelected; }

so then would the slotSelected variable be what it returns in the method?

short hazel
slender nymph
golden ermine
#

i want seperate text for days

short hazel
#

Then use another Text variable

slender nymph
eternal falconBOT
golden ermine
short hazel
#

What's "not working" with it?

golden ermine
#

it doesnt count days

#

i did something wrong

short hazel
# golden ermine

The format string is not correct and likely will throw a FormatException

#

You need to do something like @"'Days:'\ d"

acoustic arch
#

there

golden ermine
short hazel
acoustic arch
slender nymph
acoustic arch
#

after the ItemSelect();

slender nymph
#

can you explain what the fuck you're actually trying to accomplish here so that i don't have to try and guess what the actual intention is from your ever changing code?

golden ermine
#

okay it works now, thanks everyone

ashen ferry
#

whats happening here it just goes back and doesnt do anything, I dont know anything about assembly definitions lol I could try referencing it in settings but wouldnt that mean I then include whole ass new assembly in my builds too? I wanted to try and use https://docs.unity3d.com/ScriptReference/PrefabUtility.InstantiatePrefab.html from that and put directive so it wouldnt include that class into a build but I cant use it in editor itself

acoustic arch
#

overall grabbing the selected Slots GameObject

#

this is all on a button click on the Slot

slender nymph
#

okay so waht are you actually trying to do

acoustic arch
#

be able to move around the items in the slot in the inventory

#

itll select it, then eventually if you click the button while one is already selected itll either trade the item's in the slots or fill it in

slender nymph
#

i meant with the code you were asking about. what is that code supposed to be doing

golden ermine
eager elm
acoustic arch
short hazel
ashen ferry
#

yea I dont want it in a build

#

just in editor so I can spawn some prefabs

slender nymph
golden ermine
ashen ferry
#

but I cant use it in editor as well

short hazel
#

AddDays(1)

slender nymph
# acoustic arch no

then make the method return void and remove the entire return statement since that is 100% unnecessary

slender nymph
#

then what is the current issue?

golden ermine
eager elm
short hazel
#

Do it once, not in the coroutine

ashen ferry
#

actually it compiles even though in ide its an error wtf

acoustic arch
slender nymph
acoustic arch
#

i think its all good

#

thanks for your help

crimson widget
#

Hey, I saw this bit of code somewhere recently, and wanted to ask, what does the " : this() " do?

wintry quarry
#

It's completely unnecessary here

#

It would matter if you had defined a parameterless constructor explicitly which I don't actually think you can do for a struct

short hazel
#

Not for the C# version Unity uses, indeed

zenith cypress
ashen ferry
#

wow

#

I just was looking around

#

why my whole region is gray

#

thx

short hazel
#

(for those using VS, it's the dropdown top-left of the code view)

spiral oak
#

Hey! :>
This isnt a question.
I made a Object Pooling script in which I create a generic pool object with some useful features.
I wanted to share it because I like it pretty much, so, if anyone wants to see it or use it I can send them the script with some instructions
Thank you :>

slender nymph
#

fun fact but unity 2021+ already has an ObjectPool<T>

spiral oak
#

Wait what

zenith cypress
#

Also has pools for Dictionaries, Lists, HashSets, etc

spice smelt
#

guys how do i make my ground ghost-proof

short hazel
#

Spread some garlic on it

slender nymph
#

send in the ghost busters

spice smelt
#

i mean i have basic code that i can walk on

short hazel
#

Wait that's vampires not ghosts lol

spice smelt
#

but if i use my gun and gain movement

#

i can go through

spiral oak
slender nymph
slender nymph
spice smelt
#

scrap mechanic lore be like

slender nymph
spice smelt
#

thats what i want

#

make me more psychics friendly

slender nymph
#

please learn to read

spiral oak
slender nymph
#

what features does your object pool have that unity's does not?

spiral oak
#

And it implements IEnumerable so you can traverse it with a foreach

slender nymph
#

ah yours is one of those "throw anything in the pool and ask for specific types of things" in it?

spiral oak
#

Howerever you can also use it as a normal pool

ashen ferry
#

share it on asset store

spiral oak
#

I mean, its just a script

ashen ferry
#

thats not a thing if its free

#

u never saw

#

what kind of bs

#

people ask money for there

spiral oak
#

Well... I will research about it, thanks

spiral oak
zenith cypress
#

Unity one can do this too hmm_waddle

spiral oak
#

Really?

#

Did I really waste my time? kekwait

slender nymph
#

you provide it with a func to create an instance, so yes it does that too

ashen ferry
#

yea so dynamic pooling I had mine instantiate around 50 upfront of what will be used and if its not enough resize it

slender nymph
#

unity's does that too

spiral oak
#

And Unity one implements IEnumerable?

slender nymph
#

unlikely because why should you need to enumerate over your object pool

spiral oak
#

Thats true

#

I dont know why I actually made mine enumerable

zenith cypress
#

You can give it a function to run when it gets the object as well, so not sure why I'd ever want to traverse the pool outside of that

slender nymph
spiral oak
#

Well, yeah, I use a HashSet to store objects

#

Howerever... At least I had fun sadok

ashen ferry
#

yall fancy isnt dictionary o1 as well

#

actually lemme google

slender nymph
#

it approaches o(1), yeah

spiral oak
#

Anyways, my game wont have so much objects so I think my pool worths it for my game

slender nymph
#

by all means, keep using yours. making it yourself is a good learning experience. i recreated unity's on my own to ensure i understand how it works and to use it in a 2020 project once.
but it also sounds like yours may not be a good general use one and is more purpose built

grizzled wraith
#

how do i make it so the collider gets disabled after a set amount of time after collision

summer stump
#

That looks like it should be in OnCollisionEnter, not FixedUpdate

#

Also, your !ide is not configured

eternal falconBOT
grizzled wraith
#

thats for the falling part

grizzled wraith
slender nymph
# grizzled wraith ?

you don't have errors underlined or syntax highlighting. having configured tools is a requirement to get help with your code here

grizzled wraith
#

ill do that later

slender nymph
#

then you'll get help later

summer stump
grizzled wraith
#

why

hexed terrace
#

because we're not your compiler

slender nymph
#

because how are we meant to help you with your code if you insist on using variables that don't exist?

grizzled wraith
#

cant i just describe

summer stump
grizzled wraith
#

whatever dude, thanks anyways ill come back some day when ive done the configuring thing

slender nymph
grizzled wraith
slender nymph
#

no

grizzled wraith
#

you can always ignore

spiral oak
#

Boxfriend is one of the nicest here ):

#

He's just tired of people with not configured IDE

#

Such as me my first time here

rich adder
grizzled wraith
summer stump
rich adder
#

coding is not something you do in a rush

grizzled wraith
summer stump
grizzled wraith
#

no its fine, i got it anyways

zenith cypress
#

Could have set it up in the amount of time you have been resistant against setting it up hmm_waddle

rich adder
#

the time you spent saying you're in a rush could've been time spent downloading the dam extension

spiral oak
summer stump
summer stump
#

Nice

grizzled wraith
#

since like fucking a year ago

rich adder
#

clearly it didnt work

summer stump
grizzled wraith
#

clearly

rich adder
#

and a year ago things have changed

spiral oak
summer stump
#

And the extension from a year ago is obsolete

rich adder
#

new Unity extension was dropped

grizzled wraith
#

well i was inactive

rich adder
#

its lik 1 thing

grizzled wraith
summer stump
grizzled wraith
#

okok

rich adder
#

cool. time to caatchup to the new extension then

summer stump
#

Then Microsoft had to make their own extension

grizzled wraith
rich adder
summer stump
robust stirrup
#

Does anyone know how to get a dropdown menu to only show whatever is selected?

summer stump
# robust stirrup

So you want the swaptype to show material when you have a material selected?

rich adder
robust stirrup
rich adder
#

basically you can just put an if statement and show w.e

swift crag
#

A property drawer does not sound relevant here.

#

that customizes how a single property is drawn

#

I guess you could redo this a bit, so that you have a struct that contains all of the fields

#

and then customize how that struct is drawn

#

I think that's what I've wound up doing in the past

slender nymph
#

could also use something like NaughtyAttributes and the ShowIf attribute. or odin inspector has something like that too

swift crag
#

yeah, NaughtyAttributes could do this

rich adder
slender nymph
#

although i'm not 100% certain about recommending naughty attributes anymore. i've read that it force all types to use IMGUI for the inspector instead of uitk which is now the default in 2022+

swift crag
#

pretty sure it does

#

it's a MonoBehaviour custom editor, innit?

robust stirrup
#

I don't mean to be rude, but I am so lost right now

slender nymph
rich adder
#
           ScreenCapturing myScript = (ScreenCapturing)target;
            GUILayout.BeginHorizontal();
            myScript.fileName = EditorGUILayout.TextField("File Name", myScript.fileName);
            GUILayout.Box(".png");
            GUILayout.EndHorizontal();
            myScript.DefaultFolder = GUILayout.Toggle(myScript.DefaultFolder, "DefaultFolder");
            GUILayout.Space(6);
            if (!myScript.DefaultFolder)
            {
                myScript.folderName = EditorGUILayout.TextField("Folder Name", myScript.folderName);
            }```
hexed terrace
#

Just use Unity Recorder to do screenshots

rich adder
hexed terrace
#

Yep

slender nymph
rich adder
#

oh wow.. I was sleeping on this

hexed terrace
#

Set it to capture images, set to single frame

rich adder
#

yay no more obs xD

rich adder
#

like the script

hexed terrace
#

yes

rich adder
#

oh nahh its a bit more complex than that

#

it takes screenshots of your gameobjects and makes sprites out of them

#

for like inventory icons n stuff

hexed terrace
#

That url doesn't load

rich adder
#

oh wops its missing dot

#

its so old.. i didnt even bother putting the script just .unitypackage :dolt

#

turns all the texture2D import settings turn into Sprite2D

spice smelt
#

should i put animation https://pastebin.com/2Qmr8f3P between every one ?

    if (Input.GetKeyDown(KeyCode.Alpha1))
        selectedWeapon = 0;


    if (Input.GetKeyDown(KeyCode.Alpha2) && transform.childCount >= 2)
        selectedWeapon = 1;


    if (Input.GetKeyDown(KeyCode.Alpha3) && transform.childCount >= 3)
        selectedWeapon = 2;


    if (Input.GetKeyDown(KeyCode.Alpha4) && transform.childCount >= 4)
        selectedWeapon = 3;
#

im just working on game and i have 4 weapons and what do i do to make them animated

rich adder
#

ofc its an example , you could make i t better also prob use switch if you got mora than 2 enum values :p

rich adder
spice smelt
swift crag
#

so if you have other stuff, you'd have to draw it yourself

#

a custom property drawer with a class/struct might work:

[System.Serializable]
public class FooInfo {
  public enum FooKind {
    One,
    Two
  }

  public FooKind kind;
  public float oneData;
  public int twoData;
}
#

I did this with IMGUI in the past. You just draw the relevant properties and skip the others

#

Not sure what you'd do for UI Toolkit.

rich adder
#

yeah this is probably better way to do it

#

just thought Id have some fun in Editor script, its been a while since i've touched it

ashen ferry
#

cant u just do DrawDefaultInspector(); and u wouldnt need do draw usual stuff manually

rich adder
#

Yeah I think so

rich adder
#

it doesn't "draw the rest"

#

it draws all of them

#

Unless Im using it wrong

ashen ferry
#

yea if its serialized in real script it will draw as well

#

ive got mine hidden and drawn from editor script what I need

rich adder
rich adder
ashen ferry
#

kekW public but with [HideInInspector] or [NonSerialized] idk which one is more correct I use first and didnt get into any trouble yet with default values or sum

rich adder
ashen ferry
#

yea

rich adder
#
DrawDefaultInspector();
        EditorGUILayout.PropertyField(myenum, new GUIContent(nameof(myenum)), GUILayout.Height(22));```
timber tide
#

When would you need [NonSerialized] anyway

ashen ferry
#

HideInInspector iirc from my testing actually

#

serializes just dont show the thing

spice smelt
ashen ferry
#

so it wont be null when it would normally be

timber tide
#

[HideInInspector] doesn't serialize without [SerializeField] anyway which I'm not sure why

rich adder
#

then any weapon parented to it will do that anim

ashen ferry
#

ooh

spice smelt
#

i have no arms in my game just a gun

ashen ferry
#

then idek whats NonSerialized for then lol

rich adder
timber tide
#

NonSerialize is like when you want the editor to change a value on the editor, but reset to defaults when the scene is closed

#

I guess more tool utility?

ashen ferry
#

but how do u make it show up in editor then

timber tide
#

public or private + [SerializeField]

ashen ferry
#

WHAT

#

[NonSerialized][SerializeField] ? kekW

rich adder
#

lol

timber tide
#

wat

swift crag
#

I don't believe you can make a non-serialized field appear in the inspector.

#

The inspector displays serialized properties, by definition

slender nymph
rich adder
#

^

ashen ferry
#

so whats the difference between this and [HideInInspector]

timber tide
#

oh you want nonserialize to show up

#

uh

slender nymph
ashen ferry
#

so I was right all along

#

mao rizzed me up

rich adder
#

will this work ?
[HideInInspector] [SerializeField] private MyEnum myenum;

#

so i don't gotta make it public

timber tide
#

you sure HideInInspector serializes? I thought the values reset if you don't serializeField it

slender nymph
timber tide
#

oh but you would use it on public data, so that would serialize it

rich adder
#

dam scripting editor is a pain

ashen ferry
#

ikr

#

anyone got naughty attributes thing is it any good for these things

rich adder
#

maybe it would probably work with strings , cause thats what the unity examples does

slender nymph
#

you wouldn't be able to use the nameof operator there, but hard coding it or getting the name via reflection would work

rich adder
#

yeah thats what unity does, thought iwas being slick

#

xD

timber tide
#

You want to serialize a private variable, but don't want the inspector to show it.

rich adder
#

I wanted to see if I can make it private but then display it manually with OnInspectorGUI

timber tide
#

You can if you make it a serializeproperty, no?

#

that usually overrides all of that

rich adder
#

thats what im doing but I gotta change it from nameOf to string to work

#

manually typing all the field names

#

yucky

timber tide
#

yeah I hate string stuff

#

too easy to break

rich adder
#

yup 3Am typing missing a letter

#

why is isnt it workingggggg

#

lol

timber tide
ashen ferry
#

just imported the thing boutta see whats up

rich adder
#

hmmm how do you turn this
myenum = serializedObject.FindProperty("myenum");
into a valid enum now because its a SerializedProperty

    if (myenum == MyEnum.A)

now don' work

timber tide
#

it's pretty good but can get a little messy. Good for just developing out the GUI.

#

but once you're set on what you want, you'd probably want to make your own custom editor

ashen ferry
#

why messy? name implies im just gonna pepper attributes around no?

timber tide
#

It can get messy with containers that need attributes

ashen ferry
#

aaa

timber tide
#

because then it needs to use some meta attribute to resolve

ashen ferry
#

I see it can serialize dictionary

#

so thats already worth

timber tide
#

Unity editor stuff is honestly ok, it's just the workflow of editing two scripts at once because you decided to want to expand out the data (or edit previous data and types) is quite annoying.

sturdy lintel
#

So I have this Sliders script which I'm trying to use to update the speed, interval, lifespan variables which are being used in other script.

public class SlidersWithEcho : MonoBehaviour
{   public TravellingBalls TBall;
    public Slider intervalSlider, speedSlider, lifespanSlider;
    public TextMeshProUGUI intervalText, speedText, lifespanText;

    void Start()
    {
      intervalSlider.onValueChanged.AddListener(HandleIntervalSliderChange);
      speedSlider.onValueChanged.AddListener(HandleSpeedSliderChange);
      lifespanSlider.onValueChanged.AddListener(HandleLifespanSliderChange);
    }

    private void HandleIntervalSliderChange(float value)
    {
        intervalText.text = value.ToString("F4");
        TBall.UpdateTBallSpawnInterval(value);
    }

    private void HandleSpeedSliderChange(float value)
    {
        speedText.text = value.ToString("F4");
        TBall.UpdateTBallSpeed(value);
    }

    private void HandleLifespanSliderChange(float value)
    {
        lifespanText.text = value.ToString("F4");
        TBall.UpdateTBallLifespan(value);
    }
}
#

This is the TravellingBalls script which uses speed, lifespan, interval.

#

I am not trying to understand why the sliders aren't properly bound to the variables. because when I try to change the slider value, my variables don't update

timber tide
#

Are your methods getting the speed here

sturdy lintel
ashen ferry
#

did u try logging at every part where it goes wrong it looks good to me idk

timber tide
#

so you've debugged and it does give you a new values in

    private void HandleSpeedSliderChange(float value)
    {
        speedText.text = value.ToString("F4");
        TBall.UpdateTBallSpeed(value);
    }

Such that it is then passed into UpdateTBallSpeed

sturdy lintel
spice smelt
timber tide
#
    void Update()
    {
        Debug.Log(speed);
        this.transform.localPosition += targetDirection * speed * Time.deltaTime;

        if ((Time.time - lastSpawnTime) > spawnInterval && isCreated)
        {
            CreateTBall();
            lastSpawnTime = Time.time;
        }
        else if ((Time.time - lastSpawnTime) > lifeSpan)
        {
            Destroy(this.gameObject);
        }
    }

How about here then? Does speed variable get updated?

#

Looks all fine to me honestly

sturdy lintel
#

Debug.Log(speed);
this doesn't update the speed, shows the default 6f only

ashen ferry
#

debug log speed inside UpdateTBallSpeed does it get the change

sturdy lintel
ashen ferry
#

so then u got more than one instance of that class?

#

it will change only in one u refer to in that slider script

sturdy lintel
timber tide
#

Either you're reading a different instance or something is setting it back to defaults is my guess.

sturdy lintel
ashen ferry
#

is TravellingBalls controller of those balls or like each ball has one

wintry quarry
unreal imp
#

Guys, is there any way to detect when an object is destroyed?

sturdy lintel
unreal imp
#

oh,thanks

wintry quarry
#

Or just do something from the code that destroys it

sturdy lintel
ashen ferry
# sturdy lintel yea each ball has one

lol sry for ignore I thought praetor gonna take over you need some sort of central place where balls are moved or they look up at what speed they need to move and move themselves

timber tide
#

Debug it in the Start() method where you're setting listeners and make sure each new ball instance is subscribing.

#

better to just use VS debugger to set breakpoints if you're spawning a lot

ashen ferry
#

bro boutta be so confused rn

sturdy lintel
#

If I debuglog the speed in start(). After every ball being instantiated, the log says 6 only. It doesn't change the value for any of the future balls being instantiated

ashen ferry
#

look up what is singleton make one up

#

make a list<UrBalls> = new() in that singleton and in balls script in start add ball instance to that list and in that singleton when you change speed change speeds in all of the balls in that list

#

ur use an event idc

sturdy lintel
sterile river
#

i have a question but it is for unity itself and not for code. where do i post it? 😄

timber tide
ashen ferry
#

its same thing u still want static float or singleton balls can get their speed from or a Setup method in a ball script to set their speed when u instantiate

#

if u paste code into hastebin I could plug that in ig

timber tide
ashen ferry
#

balls spawn at current speed and dont change afterwards

timber tide
#

because if that's the case then you have to probably read directly from* the slider after you subscribe.

#

ah, ok then I'm not too sure. I don't really use listeners but it sounds like they're the problems if they are sure they are absolutely creating these TBalls with this wrapper class.

ashen ferry
#

I know what he wants he just needs to spawn balls from spawner with speed var and set speed in spawner with that slider he uses which would be used to spawn the ball with correct speed

#

bro dipped tho kekW

timber tide
#

yeah, subscribing isnt enough after instantiating, but if it's not updating after the slider moves, then that's more of a subscription problem.

ashen ferry
#

he didnt use events I just offered that previously but if balls care about the speed only once when instantiating u dont need event

ashen ferry
#

can I somehow look through my assets folder for prefab by name ive got script I add and remove shortly after but it needs reference to prefab I dont want to keep dragging it in

timber tide
#

Asset database I think had a method for that

ashen ferry
#

yea that works ty

acoustic arch
#

how can i make a button perform a method if its condition is met or another method if its condition is met

#

2 differents methods on the button

slender nymph
#

have the button call one method which checks the condition and calls the relevant method

acoustic arch
#

i have it as-

#
    public void ItemSelect()
    {

        if (isSlotSelected == true)
        {
            isSlotSelected = false;
            int slotValue = EventSystem.current.currentSelectedGameObject.GetComponent<Slot>().slotNumber; //Slot number
            slotMovingTo = inventorySlots[slotValue]; //Slot Moving To Object Image
            Debug.Log("Slot Moving Too " + slotValue);
        }

        if (isSlotSelected == false)
        {
            isSlotSelected = true;
            int slotSelectedValue = EventSystem.current.currentSelectedGameObject.GetComponent<Slot>().slotNumber; //Slot number
            slotSelected = inventorySlots[slotSelectedValue]; //Slot Object Image
            Debug.Log("Slot Selected " + slotSelectedValue);
        }
    }
#

in 1 method

slender nymph
#

use else if

#

or just else

acoustic arch
#

but it ends up playing them both anyway

acoustic arch
slender nymph
#

no, you currently check if isSlotSelected is true. if it is you set it to false and do other stuff. then you check if it is false, which at this point it is because you just set it to false so it does that stuff too

acoustic arch
#

ohh i thought since it was read down it wouldnt go back to do the first one when the condition is met

#

is

#

if else, the same as an either or?

#

one or the other

slender nymph
#

they are two separate if statements right now and you don't return from the first so naturally it will check the second. you need to use else or else if for that second one so that it doesn't run if the first condition is true

acoustic arch
#

alright

#

basically just

#
    public void ItemSelect()
    {

        if (isSlotSelected == true)
        {
            isSlotSelected = false;
            int slotValue = EventSystem.current.currentSelectedGameObject.GetComponent<Slot>().slotNumber; //Slot number
            slotMovingTo = inventorySlots[slotValue]; //Slot Moving To Object Image
            Debug.Log("Slot Moving Too " + slotValue);
        }
        else
        {
            isSlotSelected = true;
            int slotSelectedValue = EventSystem.current.currentSelectedGameObject.GetComponent<Slot>().slotNumber; //Slot number
            slotSelected = inventorySlots[slotSelectedValue]; //Slot Object Image
            Debug.Log("Slot Selected " + slotSelectedValue);
        }
    }
#

or do i keep the condition?

slender nymph
#

however all but one line in both of the if statements is practically identical. use the if/else for just that one line instead of copying the code and just invert the bool

acoustic arch
#

yeah they are nearly identical right now, but eventually itll be used to move the items around to the slotMovingTo from slotSelected

#

alright it worked

twin bolt
slender nymph
#

on which line

twin bolt
#

2

slender nymph
#

did you actually put anything into the array?

twin bolt
#

Yes, the first line, actually work but for some reason it cant grab the length from it.

slender nymph
#

that's not what i asked. have you actually assigned anything to the elements of the array? or have you left them null? and no, i'm not referring to the instance of the array itself. the individual elements of the array

twin bolt
acoustic arch
#

can someone point me in a direction in adding drag and drop into my inventory

#

is the inventory manager

twilit trail
#

if i have a scene where the ui isn't working what are the usual culprits?

sour fulcrum
#

UI isn't working is a little too vague homie

twilit trail
#

UI elements don't animate when clicked or trigger onClick methods

#

like on a Canvas type UI elements

slender nymph
inner marsh
#

public event Action<Item> OnItemRightClickedEvent; says this namespace cannot be found, is this not correct?

rich adder
#

do you have using System

inner marsh
#

just using System?

rich adder
#

just System

inner marsh
#

alr

north kiln
#

Your !ide is not configured

eternal falconBOT
north kiln
#

you should be using your IDE to add namespaces (on top of getting error highlighting and autocomplete)

acoustic arch
#
Sprite slotSelected; //Selected slot
    Sprite slotMovingTo; //Slot To Move Item Too
    bool isSlotSelected = false;
    public void ItemSelect()
    {
        if (isSlotSelected == true) //Moves/Swaps items in inventory
        {
            isSlotSelected = false; 
            int slotValue = EventSystem.current.currentSelectedGameObject.GetComponent<Slot>().slotNumber; //Slot number
            slotMovingTo = inventorySlots[slotValue].sprite; //Slot Moving To Object Image

            slotSelected = slotMovingTo;
            slotMovingTo = slotSelected;
            Debug.Log(slotSelected + " moved to " + slotMovingTo + " in slot " + slotValue);
        }
        else //Selects the first item
        {
            isSlotSelected = true;
            int slotSelectedValue = EventSystem.current.currentSelectedGameObject.GetComponent<Slot>().slotNumber; //Slot number
            slotSelected = inventorySlots[slotSelectedValue].sprite; //Slot Object Image
        }
    }
#

how come the sprites arent changing at all even tho they should be?

rich adder
acoustic arch
#

it showed that the sprite was moved to the new slot then

#

it never actually showed the sprite swapped

rich adder
#

you tried how ?

#

have you used debugger before ?

#

step thru the code

#

slotMovingTo = inventorySlots[slotValue].sprite; //Slot Moving To Object Image

        slotSelected = slotMovingTo;
        slotMovingTo = slotSelected;
#

whats even goin on here

acoustic arch
#

the sprites are swapping

ashen ferry
#

trynna make custom attribute for better buttons and it all works fine but can I do anything about this https://hatebin.com/yvbveokhju ClickableCheck string I wanted to pass in func<bool> but that aint possible from what I can tell so what else can I use to point to a method kekW

polar acorn
ashen ferry
#

he just copied relevant part brackets intendation especially at the end implies this is not the last one

polar acorn
acoustic arch
polar acorn
#

The way to read this is like so:

bool ThisReturnsABool(object somethingOrOther){
  ...
  return false;
}
polar acorn
#

"Check lines 12 and 13" -> provides code with no line numbers

ashen ferry
#

aaa mb

acoustic arch
#

is there a way to have it with numbers?

polar acorn
eternal falconBOT
acoustic arch
#

i usually only use hatebin for the entire code

#

but ill send the full

#

lines 59 and 60

#

im wondering how come the sprites arent swapping with each other

polar acorn
#

Let's talk about these two lines

acoustic arch
#

ok

#

please do

polar acorn
#

Let's say slotSelected is currently something called "Sprite A"

acoustic arch
#

alright

polar acorn
#

and slotMovingTo is something called "Sprite B"

#

then you run these two lines

#

The first line happens. What is the value of slotSelected and slotMovingTo

acoustic arch
#

slotSelected is Sprite B

#

slotMoving is Sprite B

polar acorn
#

Okay and what is slotMovingTo

acoustic arch
#

^

polar acorn
#

Why did it suddenly become Sprite A

acoustic arch
#

oh mb i read wrong

polar acorn
#

First line

acoustic arch
#

yeah

#

both are B it doesnt change

#

ohhhhh

polar acorn
#

So, before the first line, slotSelected is Sprite A, and slotMovingTo is Sprite B.
After the first line, slotSelected is Sprite B, and slotMovingTo is Sprite B.

acoustic arch
#

its basically making one equal to it then making the other equal to what it already is

polar acorn
#

Now, what happens on the next line

acoustic arch
#

slotMovingTo is Sprite B and slotSelected is still Sprite B

polar acorn
acoustic arch
#

yeah

polar acorn
#

Hold the value in that, set one, then set the other to the temporary

north kiln
#

to swap two variables these days I use a neat trick with value tuples
(a, b) = (b, a);

ashen ferry
acoustic arch
#

ye im a beginner

polar acorn
acoustic arch
#

but i also come here like 5 times a day im grinding to learn super hard

acoustic arch
#

cause it has no use outside of it

polar acorn
north kiln
acoustic arch
#

but id rather just learn as i go and not force myself to learn multiple things to get 1 done otherwise i wont remember any of it

acoustic arch
ashen ferry
# polar acorn Well, what needs the `Func<bool>`

yea so just theres full full script of what I want to do with comments tbh I dont mind strings that much I can detect wrongdoings but what if I want refactor or smthn + maybe learn something. I add attribute to method in class -> custom editor draws button but checks if you can click it right now running method returning bool which would be set in attribute class https://hatebin.com/rhflqouszb

opaque fox
#

Was looking at the official Unity Flocking tutorial. Between now and 2021 the Flocking tutorial itself seems to be out-of-date.
Specifically this line of code in the above screenshot. I've tested the Flocking tutorial's final code to work in the 2021 version of Unity but it completely breaks upon launching it in 2023.1.9f1 (I can't go to any newer versions).

Flock can't seem to reference the FlockManager, and I'm not entirely sure how to perform that. I tried creating a FlockManager object in the Flock script that is equal to the FlockManager object created in the FlockManager script (FM) but it doesn't seem to work.

rich adder
#

or start

opaque fox
#

Start

#

my bad

rich adder
opaque fox
#

In FlockManager?

acoustic arch
#

https://hatebin.com/fkalzybrnl
i debugged it and it showed that when you move an item in the inventory it swapped but it still didnt actually swap sprites so something must be locking the spriates into whatever slot their in

#

and i cant figure out why

north kiln
# opaque fox In FlockManager?

You should always aim to initialise variables in Awake, so other scripts can use them in Start and not have execution order problems

opaque fox
#

Gotcha

north kiln
violet topaz
#

im trying to get the camera to follow the player. but when switch scenes i cant the cam to follow the player ```cs
public class CameraFollow : MonoBehaviour
{
[SerializeField] private Vector3 offset;
[SerializeField] private float damping;

public Transform target;

private Vector3 vel = Vector3.zero;


private void FixedUpdate()
{
    Vector3 targetPosition = target.position + offset;
    targetPosition.z = transform.position.z;

    transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref vel, damping);
}

}
character selectcs
public class GameManager : MonoBehaviour
{
public static GameManager Instance;

public Character[] characters;

public Character currentCharacter;

public void Awake()
{
    if(Instance == null)
    {
        Instance = this;
    }
    else
    {
        Destroy(gameObject);
    }

    DontDestroyOnLoad(gameObject);
}
private void Start()
{
    if(characters.Length > 0) 
    { 
        currentCharacter = characters[0];
    }
}
public void SetCharater(Character character)
{
    currentCharacter = character;
}

}```

rich adder
#

Obligatory cinemachine xD

#

like

#

fr

#

even tho it doesn't fix ur original question bbtw

#

hmm make a prefab your player + camera and persist them both with DDOL

#

(doesn't need to be prefab with DDOL)

acoustic arch
#
public void ItemSelect()
   {
       if (isSlotSelected == true) //Moves/Swaps items in inventory
       {
           isSlotSelected = false; 
           int slotValue = EventSystem.current.currentSelectedGameObject.GetComponent<Slot>().slotNumber; //Slot number
           slotMovingTo = inventorySlots[slotValue].sprite; //Slot Moving To Object Image

           //Swaps sprite for the one selected
           Sprite CSprite = slotSelected; //C = A
           slotSelected = slotMovingTo; //A = B
           slotMovingTo = CSprite; //B = C

           inventorySlots[slotValue].sprite = CSprite; //Makes the slot you moved the item too display the new item
           //Here needs to make the original selected slot equal to the MovingTo Slot


           Debug.Log(slotSelected + " moved to " + slotMovingTo + " in slot " + slotValue);
       }
       else //Selects the first item
       {
           isSlotSelected = true;
           int slotSelectedValue = EventSystem.current.currentSelectedGameObject.GetComponent<Slot>().slotNumber; //Slot number
           slotSelected = inventorySlots[slotSelectedValue].sprite; //Slot Object Image
       }
   }
#

i got the item to appear in the MovingTo slot, but idk how to make the original selected slot the MovingTo

inner marsh
rich adder
#

and what is 'js' visual studio? lol

inner marsh
#

just

#

js

#

yes

#

im dumb

#

mb

acoustic arch
#

how can i change this value inside of the other section?

rich adder
#

seems you're making ur whole inventory system backwards, you're using sprites for logic is little strange

rich adder
acoustic arch
#

yeah

#

thats why i cant do this

#

but im wondering how i would do it instead

rich adder
#

the normal way u change it from local to non-local

#

declare it outside the scope/method

acoustic arch
#

but then it wont update to the slot selected

#
       
        else //Selects the item
        {
            isSlotSelected = true;
            int slotSelectedValue = EventSystem.current.currentSelectedGameObject.GetComponent<Slot>().slotNumber; //Slot number
            slotSelected = inventorySlots[slotSelectedValue].sprite;//Slot Object Image
        }
#

this whole method is on a button

#

each slot has slot number

#

then the slot is selected

#

if it was outside of the method it wouldnt select the slot at all

rich adder
#

make a better way to manage your slots

acoustic arch
#

so i should just remove all of this

rich adder
#

no just need to make it less flimsy , also using if sprite == null to check for an empty slot is not so good

#

Slot should be its own class and you have a main script manage the occupancy of the slots and retrieve the sprite from an infodata , of the asset

acoustic arch
#

yeah i know

#

slot is its own class right now it just only holds the slotNumber

rich adder
#

Image[] inventorySlots

#

this should be Slot[]

#

then put more useful data in the slot

#

slotnumber is useless

#

the array is the slot number

acoustic arch
rich adder
#

that would be a start yes

#

right now you already managing two lists, when it can just be 1

#

Slot could just hold ItemData

#

sprite should be inside ItemData

#

(ideally this is a scriptable object ?)

acoustic arch
acoustic arch
rich adder
acoustic arch
rich adder
#

yea lol

acoustic arch
#

but im not very sure where to even start

#

i made that Slot class

#

and now ill give it to each slot

#

but then what?

inner marsh
#
    [SerializeField] EquipmentPanel EquipmentPanel;``` ive imported both as it shows to do, but still says that its missing the references these scripts provide
rich adder
# acoustic arch but then what?

like i said earlier, I'd have the slot itself hold the data . maybe make it easier and also keep the Image component reference in the slot

wintry quarry
acoustic arch
inner marsh
north kiln
eternal falconBOT
inner marsh
rich adder
acoustic arch
inner marsh
# wintry quarry Yes that is the error

and what does said error mean? there should also be two slots to import the inventory manager and the equipment panel if i am correct and those dont exist in the inspector

wintry quarry
wintry quarry
rich adder
wintry quarry
#

You have to fix all errors first

inner marsh
#

ah okay

acoustic arch
#

probably farther in the future

inner marsh
# wintry quarry It means there's no function by that name on that class. You can't use nonexiste...
    {
        for (int i = 0; i < EquipmentSlots.Length; i++)
        {
            if (EquipmentSlots[i].EquiptmentType == item.EquiptmentType)
            {
                previousItem = (EquippableItem)EquipmentSlots[i].Item;
                EquipmentSlots[i].Item = item;
                return true;
            }
        }
        previousItem = null;
        return false;
    }
    public bool RemoveItem(EquippableItem item)
    {
        for (int i = 0; i < EquipmentSlots.Length; i++)
        {
            if (EquipmentSlots[i].Item == item)
            {
                EquipmentSlots[i].Item = null;
                return true;
            }
        }
        return false;
    }
}
``` from equipment panel, which is called
rich adder
#

if it didn't reach another slot you restore it back to old slot

wintry quarry
acoustic arch
wintry quarry
#

You can't use a nonexistent function "IsEmpty"

acoustic arch
inner marsh
inner marsh
#

but i make a refernce to the scripts containing these functions

wintry quarry
#

You can't use functions that don't exist

inner marsh
#

which should mean it works