#💻┃code-beginner

1 messages · Page 578 of 1

rich adder
#

last element is list.count - 1

scarlet shuttle
#

So this is an error waiting to happen

rich adder
scarlet shuttle
rich adder
#

if the script pretty much does the unintended thats a diff story

north kiln
#

No it's not

#

No.

#

i-- returns i and then subtracts 1 from it

scarlet shuttle
north kiln
#

--i returns i - 1 and subtracts

lean basin
north kiln
rich adder
#

yeah sorry never seen that before lol

lean basin
#

hmm I should learn to make C# project so I could test code without waiting for unity to load

rich adder
#

use C# console apps, they are fast

#

or yea online compiler is good enough but very basic IDE

scarlet shuttle
#

I assume enemies.Count is updated each loop then in the condition, so it stays within new limits without indexing something not there

north kiln
#

It would generally be better to use a reverse for loop

#

As then you don't have to do anything special with the indices

#

You can write them easily by autocompleting forr

scarlet shuttle
#

I’m very python minded so this entire situation hurts my soul

rich adder
#

ya that code caught me offguard lol

north kiln
#

Removing from the end of a list is cheaper than the front, so it'll be more performant too

rich adder
#

(you get met with error in trying to do so)

scarlet shuttle
grand snow
#

all elements after get "moved" up

scarlet shuttle
#

Ahhhh

grand snow
#

so removing from the end first ends up being quicker

scarlet shuttle
#

Ok makes sense

eager spindle
north kiln
#

What pointer?
If you remove the second element then there'd be a gap in the array. It needs to be continuous

chrome apex
#

I am looking up a variable from an instantiated prefab to an object in scene.

The variable changes but I can only ever get the initial value, even if I find the object and component in Update().

Why?

languid spire
rich adder
north kiln
eager spindle
chrome apex
rich adder
#

show code

chrome apex
#

spawner = GameObject.Find("Spawn Manager");
spawnManager = spawner.GetComponent<SpawnManagerX>();
// Set enemy direction towards player goal and move there
Vector3 lookDirection = (playerGoal.transform.position - transform.position).normalized;
enemyRb.AddForce(lookDirection * spawnManager.enemySpeed * Time.deltaTime);

#

this is what I moved to update

astral falcon
#

!code

eternal falconBOT
eager spindle
#
{SerializeField] GameObject p_bullet;
void Start() {
  var bullet = Instantiate(p_bullet);
}

p_bullet gives the initial value.
bullet gives current value

chrome apex
#

sorry for formatting, I will learn

#

enemySpeed is the float that I can only get the initial value of even though I moved it to update

eager spindle
chrome apex
#

nope

eager spindle
#

this is a problem with using GameObject.Find, it may pick the wrong spawnmanager

rich adder
eager spindle
#

you'll need to learn how to debug your code, and check that you're referencing the correct spawn manager.

rich adder
#

and which value are we looking

#

this is hella wrong * Time.deltaTime

#

you don't use that inside AddForce
that will make your rigidbody crawl without boosting its speed to ridiculous numbers

chrome apex
#

we are looking at enemySPeed

eager spindle
#

AddForce already takes into account (Time.fixedDeltaTime)

rich adder
#

physics steps is already fixed time

chrome apex
#

since I don't know how to format 😄

eager spindle
#

You need not include it in

chrome apex
#

you are right, shouldn't use delta time for physics

#

I knew that but forgot

languid spire
rich adder
#

screenshots are not friendly to people who use screenreaders or blind :\

languid spire
#

or to copy/paste solutions

chrome apex
#

Ok I will sorry

#

I am proficient in playmaker and can make a game fully without help, but code still confuses me

#

I am learning

rich adder
languid spire
#

what has that to do with following simple bot instructions? !code

eternal falconBOT
chrome apex
chrome apex
chrome apex
# rich adder `Debug.Log($" enemySpeed: {spawnManager.enemyspeed} ");`

When I add that, I get this error:

Error CS1061 'SpawnManagerX' does not contain a definition for 'enemyspeed' and no accessible extension method 'enemyspeed' accepting a first argument of type 'SpawnManagerX' could be found (are you missing a using directive or an assembly reference?) Assembly-CSharp C:\Users\pc\My project (4)\Assets\Challenge 4\Scripts\EnemyX.cs 31 Active

eager spindle
#

spelling mistake

#

variables are case sensitive

rich adder
#

it was example

chrome apex
#

whoops

eager spindle
#

you'll want to learn c# first before delving into scripting

burnt vapor
#

Just Unity in general

eager spindle
rich adder
#

ya basic c# will d o you wonders

chrome apex
#

hey

#

it worked all this time

#

but in the public field of the prefab, it just showed the initial value

rich adder
#

you probably never saved before

chrome apex
#

I thought it was supposed to be shown in the public field when it changes

rich adder
#

not on the prefab , the instance of the prefab

chrome apex
#

yea it doesn't show on the instance of the prefab

#

when I pause and select a prefab in the scene, doesn't show

#

but debug log shows it works correctly

rich adder
chrome apex
#

compare debug.log with the inspector field

#

oh no

#

I'm showing the wrong variable

#

ffs

rich adder
#

thats not being touched

chrome apex
#

goddamn

#

so I should instaed do speed = spawnManager.enemySpeed

#

and it should show

rich adder
#

did you want to do speed = spawnmanager.enemySpeed

chrome apex
#

yea yea

#

I got it now

#

yea ofc it works now

#

I hate it when it's stupid mistakes

#

rather than complicated mistakes 😄

rich adder
#

soon enough you'll get those too 😮
those are harder to undo!

chrome apex
#

so all this time the issue was I was looking at the wrong float, it worked at the start

scarlet shuttle
tiny wind
#
 public void Attack3()
 {
     anim.SetTrigger("attack 3");
     cooldownTimer = 0;
     if (Input.GetMouseButton(2))
     {
         slashes[0].transform.position = slashPoint.position;
         slashes[0].GetComponent<Projectile>().SetDirection(Mathf.Sign(transform.localScale.x));
     }

 }

Hii, how do I add a delay to the if statement?

rich adder
#

or ig Async delay but ehh

chrome apex
#

yeah I have good familiarity with unity, I've done shaders, animations, modeling, textures and everything else including programming with Playmaker

#

just confused by c# still

tiny wind
rich adder
night raptor
#

time -= maxTime I would do, not a big difference though

rich adder
#

ah yeah that also hehe

scarlet shuttle
rich adder
#

preference

night raptor
rich adder
#

interesting

night raptor
#

There's also a case where maxTime is smaller than .deltaTime in which case the difference may be huge. if you do time -= maxTime, the time will keep increasing until the game speeds up enough to take care of all of those (likely never). If this is a concern, one should use a loop where while (time >= maxTime) time -= maxTime; to immediately take care of them all

scarlet shuttle
tiny wind
#

yeah Im making a combo

night raptor
#

I'm unsure what combo refers to in this case

noble forum
#

Hi, I'm creating a tarot Chess game. I'm on the brink of starting a multiplayer. I have already decided on Peer to Peer as it's my first commercial product, and I don't have the money for servers in case my game would get around 400 active players. (I saw that on many sites more than 100 is paid).
So, it seems so complicated and hard to follow, and such things really effect my passion.
So, how do I even begin this?
I would like to understand the topic, but I'm also struggling with time, as I need to program around half of the gameplay as a side project in 3 months.
Any advice?

rich adder
scarlet shuttle
languid spire
noble forum
tiny wind
noble forum
rich adder
languid spire
rich adder
#

if you aren't earning with 99+ active users to cover basic server costs then idk. ID think a better strategy

tiny wind
scarlet shuttle
chrome apex
sage peak
#

Hey guys, I dont know where to adress this so ill just do it here. I worked on this game for weeks, and I saved it yesterday and clsoed it, now I open it and this is what I see, what do I do?

tiny wind
rich adder
astral falcon
noble forum
#

P2P seemed as a solution so I don't have to worry about the game so much

chrome apex
scarlet shuttle
rich adder
languid spire
timber tide
#

This is why WebRTC is the new magic transport layer everyone uses

rich adder
astral falcon
sage peak
chrome apex
sage peak
noble forum
languid spire
timber tide
#

true, you can use like some minimal relay server though like MQTT

#

pennies for a server

scarlet shuttle
rich adder
lavish kernel
#

Is there a better way to early-exit from a coroutine (inside the coroutine) than a goto? It's not particularly cumbersome but not particularly elegant either.

lavish kernel
#

ohhh that's right thank you.

rich adder
#

a coroutine is just enumeration loop

lavish kernel
noble forum
astral falcon
# sage peak I dont know what that is 🤷

You def. should get familiar with whatever version control, probably git to start off. But that does not help you yet anymore. Your file might be corrupted. Try copying it, moving it, maybe move the meta file and let unity regenerate it. Restart your machine

burnt vapor
#

Git should be one of the absolute first things you set up in a project

#

Any type of version control is a massive help. Not just against corruption but also bug fixing and/or just generally testing stuff and being able to revert whatever you applied

scarlet shuttle
#

Does a component evaluate to null if it was deleted? I think so but now I’m doubting myself

tiny wind
rich adder
#

do basic c#

tiny wind
#

oh right

lavish kernel
rich adder
tiny wind
scarlet shuttle
lavish kernel
# scarlet shuttle Cool, ty

If it is still buggy, maybe try using DestroyImmediate() I may have been wrong about the pending destruction thing, they aren't technically destroyed until the next frame.

scarlet shuttle
scarlet shuttle
#

Actually does unity have animation events? As in trigger an event at a specific frame, If so that’s probably the better option

sharp abyss
#

https://pastebin.com/HPePvkJj grab script
https://pastebin.com/UFaeAgpD lever script
https://pastebin.com/aeE4Gcf0 trapdoor script
the balance script I didnt include just have rigidbody2D.Moverotation()

problem is the lever going back and changing its limits.I cant pull it by grabbing but can push it with my body.

sage peak
tiny wind
obsidian plaza
#

someone corrected me and apparently destroying something destroys is at the end of the frame and not the next frame

charred spoke
#

Yes

lavish kernel
obsidian plaza
#

so instead of doing yield return null in a coroutine maybe you can wait for the end of the frame but im not sure if even that is enough

#

i kinda dont know many of the processing order of things but u can try it

obsidian plaza
#

not sure what ur problem is cause i havent read that much but animation events are super useful

#

and coroutines are really easy to do the basics so you could figure that out in a couple minutes too

lavish kernel
#

It doesn't have everything but it does clear up some ordering problems

scarlet shuttle
#

Just checked but don’t see anything about it, what’s the timing on event execution? Surely it’s not instant, like if you trigger an event in update when would scripts detect it being triggered

lavish kernel
#

What events are you talking about? Animation events are in the upper section.

#

otherwise event listeners are invoked in order immediately after calling the Invoke method

scarlet shuttle
#

Didn’t realize there are different types of events

scarlet shuttle
lavish kernel
#

They're all kind of essentially the same thing under the hood, but Unity calls the Invoke method itself automatically for some components, which is why I asked.

scarlet shuttle
obsidian plaza
#

whats the issue again

#

how its kinda getting stuck when u pull it?

sharp abyss
#

i dont know

#

I think its because of my grab script that adds a joint and then removes

sharp abyss
normal glacier
#

Is there a chat here to talk about random stuff

obsidian plaza
#

random unity stuff or random stuff

#

cause dont think theres an offtopic

normal glacier
#

Random unity stuff

obsidian plaza
normal glacier
#

Thx

#

I j want to share my progress in game dev xD

frosty hound
slate haven
#
    {
        if (!IsGrounded())  //make the player fall down
        {
            
            velocity.y += gravity * Time.deltaTime;
            transform.Translate(0, velocity.y * Time.fixedDeltaTime, 0);
        }

        else if (IsGrounded()) //make the player jump with force without gravity
        {
            
            transform.Translate(0, velocity.y * Time.fixedDeltaTime, 0);
        }

     
    }```

I am using this to jump the player but it falls beneath the ground when it comes down with the velocity. I am using raycast in groundcheck
dawn hedge
cosmic dagger
eternal falconBOT
dawn hedge
cosmic dagger
#

make sure it is assigned before using it . . .

dawn hedge
cosmic dagger
dawn hedge
#

nope

#

i started yesterday

cosmic dagger
#

did you follow or learn beginner C#? that very important when trying to code . . .

normal glacier
#

a reference variable is a variable that references something right

dawn hedge
#

i didnt. but a reference variable, is that like this?

normal glacier
#

They seem more like public variables, cus they reference actual values rather than an object

dawn hedge
normal glacier
cosmic dagger
burnt vapor
#

Pls share the full code and not tiny chunks

cosmic dagger
# dawn hedge

to make it easier. there is only one variable on line 52, so that has to be the reference variable . . .

burnt vapor
#

So many screenshots and I have no clue where CurrentObjectRigidBody comes from

normal glacier
#

yes

normal glacier
dawn hedge
eternal falconBOT
cosmic dagger
cosmic dagger
dawn hedge
burnt vapor
#

if(CurrentObjectRigidBody) does not do what you think it does

#
-if(CurrentObjectRigidBody)
+if(CurrentObjectRigidBody != null)

This is probably what you intend

dawn hedge
burnt vapor
#

Then you either use a very shit tutorial or you made a mistake there

#

You have explicitly compare against null. Your current if-statement doesn't do that

#

If you fix this, it seems to assign CurrentObjectRigidBody in the else-statement and fix the issue

#

This has to be done on both line 28 and 60

cosmic dagger
dawn hedge
burnt vapor
#

This code makes no sense in general

#

What is happening here?

#

You definitely miss something here

#

And line 52 has the actual exception

#

Same if-statement must be added, maybe?

obsidian plaza
#

are you not getting errors for these?

#

look at ur red squigglies

burnt vapor
#

There's nothing wrong with the syntax

obsidian plaza
dawn hedge
#

Should i send the tutorial i followed?

#

Maybe i should make a new script.

slate haven
cosmic dagger
obsidian plaza
obsidian plaza
#

gravity is already a thing on rigidbodies

#

why arent u using that

slate haven
#

Because its a kinematic body

#

You cannot use that

lavish kernel
burnt vapor
slate haven
burnt vapor
#

But stuff like that is such a weird check to do

slate haven
#

Raycast detects the ground check

burnt vapor
#

Just specify null explicitly. Now it's a question if does what you think it does you see

slate haven
#

thats working

#

but i need something that snaps my player back to the ground

burnt vapor
slate haven
#

if it falls below it

burnt vapor
#

But the issue is probably that something misses when they enter the block scope here

#

@dawn hedge you should check that

#

You are probably missing an if-statement there

#

On line 50

dawn hedge
burnt vapor
#

You have null checks in the script which prevent this, except for this one

lavish kernel
# slate haven Raycast detects the ground check

I see, I misunderstood your script at first. That block of code looks fine but there are a number of potential problems with the ground check code. Also, you'll run into problems when the character has to move laterally.

1- Make sure the ray won't hit the backfaces of your character's collider
2- Make sure velocity isn't building up while you're grounded
3- Make sure the raycast is emitting from the right spot, in the right direction (use Debug.DrawRay for that)
4- Make sure the raycast isn't starting from the surface of the ground collider, it won't return hits with a distance of 0

obsidian plaza
# slate haven if it falls below it

yea as u said it will probably go past the floor and only then will the raycast detect it so getting something to snap your player back is another question. Which im not sure of but its just a weird way to do it in general

normal glacier
#

a tip for making your game development learning more fluid is to learn how to code. I'm a total newbie with C# and Unity but I learned how to code in other language before

slate haven
normal glacier
#

and c# has been way easier to learn than I thought, easier than C for mexD

slate haven
obsidian plaza
#

yea i figured from what u said

#

just doesnt explain why

slate haven
#

and its kinematic so the movement happens smoothly

lavish kernel
#

hol up

else if (IsGrounded()) //make the player jump with force without gravity
{
    transform.Translate(0, velocity.y * Time.fixedDeltaTime, 0); // if the character has a negative velocity, it will clip through the ground during this step
}

obsidian plaza
#

thats why he wants to snap the player back

slate haven
lavish kernel
#

Ah, in that case you need the hit.distance value from the raycasting code, you can figure out the rest based on what you've showed lol

slate haven
lavish kernel
#

Well your velocity's y component can't be negative if you're on the ground. the hit distance is key here. You've got it broski

lavish kernel
# slate haven Thanks everyone

(I don't know your use case but you may also be able to make a copy of your character's collider that's kinematic and doesn't collide with your player, as a workaround to your player collision problem. Then your character itself can be a non-kinematic body)

slate haven
cosmic dagger
arctic flame
#

How should I start learning unity?

obsidian plaza
#

learn c# basics then !learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

slate haven
#

Hi Folks, I am facing an issue when my player is jumping (In Air on the moment), it is unable to move. While on the ground it moves as expected. Now I am using RigidBody.MovePosition() to move it horizontally, and transform.Translate() to move it vertically (Jump and making it fall down with a custom gravity).

Here's the code for your reference: https://pastecode.io/s/8hns6wbh
Suspected Lines: Line No. 68 for movement, and 123 for jumping

cosmic dagger
cosmic dagger
#

i suggest assigning the velocity because your custom gravity code should affect/use your velocity instead of transform . . .

#

basically, use MovePosition for movement and set velocity for falling and jumping . . .

willow shoal
#

where add 1f? i need this script after time

public GameObject Beginer;

public void whenButtonClicked()
{    
        if (Beginer.activeInHierarchy == true)
        {
            Beginer.SetActive(false);
        }

        else
        {
            Beginer.SetActive(false);
        } 
}
#

"after click"

slate haven
# cosmic dagger i suggest assigning the `velocity` because your custom gravity code should affec...
    {
        // Apply gravity if not grounded manually when kinematic
        if (!isGrounded)
        {
            velocity.y += PlayerGravity() * Time.deltaTime;
        }
        else if (velocity.y < 0f) // Prevents "bouncing" after landing
        {
            velocity.y = 0f;
        }

        // Update position based on velocity (for vertical movement)
        Vector3 newPosition = rb.position + new Vector3(movement.x * moveSpeed * Time.fixedDeltaTime, velocity.y * Time.fixedDeltaTime, 0f);
        rb.MovePosition(newPosition);
    }```

This Works but again it makes my object fall under the ground @cosmic dagger
cosmic dagger
night raptor
cosmic dagger
burnt vapor
willow shoal
#

i just need after 1 second set active false

cosmic dagger
night raptor
#

@cosmic dagger Well, it does interpolation for smoother visuals but otherwise no better

cosmic dagger
verbal dome
#

In 3D though, MovePosition doesn't respect collisions

#

In 2D, MovePosition actually changes the velocity

night raptor
#

That's what I mean, it looks smoother but doesn't make difference physics wise

cosmic dagger
#

yes, you have to code your own collision system to detect obstacles. that is a con for using a kinematic rigidbody . . .

verbal dome
night raptor
#

I thought they were going for the velocities and forces path

cosmic dagger
frail wind
#

guy i been switching from visual studio to visual studio code. i install every extension for C# but some reason the type that detect error doesn't do it job, like you see on the image, i typing random but it say there no error. i mean i still can program normally but not seeing where the error is, was annoying. can anyone know how to fix this?

burnt vapor
eternal falconBOT
cosmic dagger
#

double whammy . . .

vocal blaze
#

hi - can someone help, doesn't work up Force private void AttackPlayer()
{
//Make sure enemy doesn't move
agent.SetDestination(transform.position);

transform.LookAt(player);

if (!alreadyAttacked)
{
    ///Attack code here
    Rigidbody rb = Instantiate(projectile, transform.position, Quaternion.identity).GetComponent<Rigidbody>();
    rb.AddForce(transform.forward * 32f, ForceMode.Impulse);
    rb.AddForce(transform.up * 20f, ForceMode.Impulse);
    ///End of attack code

    alreadyAttacked = true;
    Invoke(nameof(ResetAttack), timeBetweenAttaks);
}

}

leaden pasture
vocal blaze
leaden pasture
#

What happens if you try giving it a much larger force? Try multiplying it by 320 or 3200 instead to check the force is being applied

#

Also use debugs

vocal blaze
#

ok i will try

swift crag
#

Is the function doing absolutely nothing?

#

Is it even running? Log something to check that

vocal blaze
#

no, in video projectile shoot from enemy in diagonally, but in my case its start from enemy center and like magnet fall down

#

forward force work well, up force - not

#

like that

#

but in scripts should be like that

swift crag
#

the AddForce calls look fine to me. I guess I would try larger numbers to see if anything changes, as Tye suggested

vocal blaze
#

i change up force from 8 to 100 and now its ok but shoot back)))

#

forward force was 32 when i up it to 64 he shoot forward but with the same problems from beggining)

swift crag
#

It's possible that the projectile is colliding with the enemy

#

Especially given that you're instantiating it at transform.position

vocal blaze
swift crag
#

ah, that'll do it

vocal blaze
#

that was))))

rancid tinsel
#

I'm about to sit down to make a start on a UI system for a project. I need to include different SOLID principles, as well as design patterns. I'm really struggling with the latter and where to fit which ones, could someone recommend some for me? It's going to be a simple system - shows the score, current theme (word game), will have pop ups when the player gains points (like a "+1" pop up underneath the score text), and will show the count down timer.

#

It will also have animations, but I don't think it makes sense to not use Unity's animation system

#

So far I've basically just got Singleton and Factory (these two I understand) but I don't know what else to use? It seems to me like most other ones are niche usecases

west radish
#

Dont use some design pattern just for the sake of using a design pattern

swift crag
#

You shouldn't be trying to "catch em all"

#

When you encounter a problem that a particular design pattern can solve, you use it

rancid tinsel
#

I know, but that's what the project requires unfortunately - same goes for SOLID.

#

I also don't think it makes sense

swift crag
#

okay, so this is academic

rancid tinsel
#

Yes. To be more clear the uni project requires SOLID principles and design patterns to be showcased in a few word "mini"games. Maybe I'm just not thinking outside the box enough in terms of the ideas?

floral wren
#

Also, Flyweight pattern is pretty easy to implement. Just use a ScriptableObject somewhere that is used twice.

rancid tinsel
#

Thank you! I'll take a look

#

Am I correct in understanding that MVP would usually be used in software as opposed to games?

floral wren
#

In Unity, specifically, the V and C mostly merge together.

#

Having a difference between the UI and the Logic of the game is common though.

rancid tinsel
#

So would it be essentially just separating UI elements from the actual logic?

floral wren
#

Yeah, without really having something in between.

rancid tinsel
#

I think there was another pattern somewhere... mediator maybe? that acts as a middle man or something like that

#

maybe I could fit that in there as well

floral wren
#

Yeah, never really used it explictly honestly.

#

It simply is natural to have object that are central.

rancid tinsel
#

Ok I'll dive in and try to use those, thanks a lot!

floral wren
#

By example, I usually have a [Start/Home/Pause/...]View Monobehaviour that encapsulate the UI. That would be a mediator

swift crag
#

A fun demo would be to completely delete the UI and have your game keep running (just...without anything visibly happening)

untold shore
#

Hey, need some help real quick with coding. Currently, I have issues regarding the DealerHandValue not changing the actual value of the Dealer's hand. Currently, it always says 0, even when DealerNewHandValue has the correct value - it won't change the Dealer's hand.
Here's the main code that is having issues:

    public void DealerCardValueChangeCelestialBond()
    {
        Debug.Log("DealerCelestialBondReset");
        foreach (Transform child in Dealerhand.transform)
        {
            Destroy(child.gameObject);
        }
        dealerHandManager.GetComponent<DealerHandManager>().dealerCardsInHand.Clear();
        Debug.Log("Clear Value");
        Dealerhand.GetComponent<DealerCardValue>().DealerhandValue = 0;
        Debug.Log("ClearValue: " + DealerhandValue);
        DealerhandValue = SpecialCardObject.GetComponent<SpecialCardScript>().DealerNewHandValue;
        Debug.Log("PostClear DealerHandValue: " + DealerhandValue);
    }
}```
DealerNewHandValue always works, it is ONLY DealerhandValue. I don't really know why. Any ideas?
grand snow
#

firstly why soo many get components

#

second im not sure i understand the issue as i dont see the connection between these hand values

untold shore
grand snow
#

best to go change that to start because GetComponent() isnt free and ofc if you accidently have more than 1 of that component on an object it gets the first.

#
[SerializeField]
MySuperAwesomeComponent comp;
untold shore
grand snow
#

yes? if you drag the game object to it then it will become the component (if on said game object) OR you can drag the component itself there

#

not as hard as you think it is

untold shore
#

That...makes more sense. Let me try that real quick.

grand snow
#

Seems to be common thing people dont seem to know about and im not sure why 🤔
Some shit asset store stuff i have seen have never serialized components...

untold shore
grand snow
#

there is too little information to understand the problem...
This confuses me for example, you set a field with the same name elsewhere then log the value on THIS component?

Dealerhand.GetComponent<DealerCardValue>().DealerhandValue = 0;
Debug.Log("ClearValue: " + DealerhandValue);
untold shore
#

That was me just being dumb 😅was just moving the script to figure out where it could work, didn’t remove it. Just did, thanks for catching that.

#

Basically for the confusion part, it's a little weird. Here is the script attempting to get the value from SpecialCardObject:

DealerhandValue = SpecialCardObject.GetComponent<SpecialCardScript>().DealerNewHandValue;

Which accesses this:

 DealerNewHandValue = handManager.GetComponent<HandManager>().handValue;
        Debug.Log("DealerNewHandValue: "+ DealerNewHandValue + " PlayerHandValue: " + handManager.GetComponent<HandManager>().handValue);
        BetManager.GetComponent<BetManager>().ResetCurrentHandCelestialBond();
        Debug.Log("ResetHandCelestialBond");
        Dealerhand.GetComponent<DealerCardValue>().DealerCardValueChangeCelestialBond();
        Debug.Log("DealerNewHand Value: " + DealerNewHandValue + " DealerHandValue " + Dealerhand.GetComponent<DealerCardValue>().DealerhandValue);

Horrible coding, I know, going to fix it with what you said. Basically, it saves the player's card value, then saves it for the DealerNewHandValue, then resets the player's hand. Then resets dealer's hand, but with the new card value

grand snow
#

removing all those GetComponents() will make it a lot easier to read 🙏

#

or get em once in the function

swift crag
#

are all of these variables GameObjects...?

#

you can reference the component type instead

grand snow
#

dw already told em

untold shore
#

Yeah, fixing it right now

#

Code to change DealerHandValue:

       DealerhandValue = SpecialCardObject.DealerNewHandValue;
       
   }```
The connecting thing:
```` public void CelestialBond()
   {
       //Swap hands with other player
       DealerNewHandValue = handManager.handValue;
       Debug.Log("DealerNewHandValue: "+ DealerNewHandValue + " PlayerHandValue: " + handManager.handValue);
       BetManager.ResetCurrentHandCelestialBond();
       Debug.Log("ResetHandCelestialBond");
       Dealerhand.DealerCardValueChangeCelestialBond();
       Debug.Log("DealerNewHand Value: " + DealerNewHandValue + " DealerHandValue " + Dealerhand.DealerhandValue);
   }```
Here we go. Heading to class right now. Just @ me, Ill look at the messages in a second! Thanks.
white girder
#

I tried creating an elevator but when I step on everything but Player obj falls into the void. Player/camera setup is from a youtube tutorial.
Player: rigidbody, Player obj: mesh + collider, orientation: empty game object, Camera Holder: transforms position based on Orientation, Camera: Camera.
Only the Player obj with the collider mesh is being parented to the platform. how do I fix this so everything moves with the lift? https://paste.mod.gg/acuzdovzvurr/0 code being used by the lift

wintry quarry
#

Since that's a child of the main player object, well you see the result

#

You could change it to grab the root instead or the parent of the object with the Collider, or use GetComponentInParent<Rigidbody> to find the object with the Rigidbody and then parent that object instead

#

You would also need to change your Rigidbody to be kinematic for example though

#

Otherwise it won't play well with this

#

Another option is to make the lift an actual physical object with its own Rigidbody instead of doing this parenting thing

white girder
torpid igloo
#

How can i "select" a button by using code? i searched the documentation and googled it but couldnt find anything.

swift crag
#

You want to use SetSelectedGameObject, on the event system component

#

EventSystem.current.SetSelectedGameObject(whatever)

#

note that you don't select a Selectable -- go figure

#

note that google will often give you old docs from when the UI components weren't in their own package

#

mostly still accurate, just annoying

torpid igloo
#

ty

swift crag
torpid igloo
swift crag
#

Yes, Button is a kind of Selectable

#

You can make your own custom selectables too

#

I've done that for my settings menus

livid grail
#

Why does my null check fail?

foreach (Buttons _button in buttonHolder)
{
    _button.button[0].SetActive(false);
    if (_button.button[1] !=null)
      _button.button[1].SetActive(true);
}
wintry quarry
livid grail
#

Index was outside the bounds of array, sorry I should have clarified that clearer

torpid igloo
#

How can I add something to the On Click () thing through code? like running a function

wintry quarry
languid spire
wintry quarry
torpid igloo
#

tysm

untold shore
#

Hey, for some reason it's giving me a null object reference debug log. This is a new thing for me (not the reference, just the hand.handValue). What do I do? It's flagging for this:

    [SerializeField] public CardValuesScript hand;
     public int handValue = 0;
     public int cardCount;
    

     public List<GameObject> cardsInHand = new List<GameObject>(); //Hold list of card objects in our hand

    public void Update()
    {
        handValue = hand.handValue;
    }
naive pawn
untold shore
wintry quarry
#

pretty straightforward

untold shore
#

How do I make it work then? Whenever I was talking to other people they were saying I should do component based so I dont have to do GetComponent(). Should I just keep it a gameobject?

wintry quarry
#

you make it work by assigning a value to hand so it's not null

naive pawn
#

there's nothing wrong with this code

#

hand is either getting unset or destroyed

wintry quarry
#

Or... the instance of the script pictured in the inspector your screenshot is not the one that is throwing the exception you see in the console. It's a different instance.

rich adder
naive pawn
#

or that yes

wintry quarry
#

Also definitely not getting destroyed - that would be a MissingReferenceException. Or in this case no exception at all.

naive pawn
wintry quarry
#

If you accessed a unity property like .transform it would

untold shore
#

This is what I have for the hand - Handposition is an object. Is it because it's not a gameobject?

wintry quarry
#

Is it because it's not a gameobject?
Get your mind off whatever track this is, it's not relevant

naive pawn
wintry quarry
naive pawn
#

ah right yeah

rich adder
#

dont you get a "such and such was destroyed but you're still trying to access it"
or is that just transforms..

untold shore
#

Whenever I click it though, it goes to hand.handValue? Weird. Trying to figure out what's calling it

wintry quarry
#

Search your scene for HandManagers

#

you probably have more than one

naive pawn
wintry quarry
#
t: HandManager``` in the hierarchy search bar
untold shore
#

I just have this one, which is the one that i showed you

wintry quarry
#

or there's an instance of HandManager that is being spawned at runtime

rich adder
#

Debug.Log(hand, this) check when it goes null maybe? (must go above/before you try to access it)

untold shore
#

How? thats so weird. Ugh, never had this happen before, sorry if I seem rude (I dont mean to be.)

wintry quarry
#

hand = null;

#

is one way

#

or hand = somethingThatResultsInNull;

#

Showing your code would be a good start if you want effective help

#

(the full script)

wintry quarry
#

Is it right away or when you spawn a card

untold shore
#

As soon as Update() is called

naive pawn
#

right from when you play the scene?

untold shore
#

Yes

wintry quarry
#

Are you sure there's only ONE HandManager component on that object?

untold shore
#

Okay, now it's magically not doing it on HandManager? Ugh, so weird. I don't know what fixed it. Checking for any empty things rn...

cosmic quail
languid spire
cosmic quail
#

oh

#

why is it both [SerializeField] and public?

rich adder
#

maybe copied from somewhere

queen adder
#

hello everyone

untold shore
#

I didn't know it would make it public, still very new

cosmic quail
#

without having to make them public

rich adder
queen adder
#

did someone had error: CS0246 before??

wintry quarry
queen adder
#

i have it in my code and i dont know what to do

rich adder
wintry quarry
queen adder
#

okay wait

#

i will sen

#

send

#

smthing like this

wintry quarry
# queen adder

yes you used something in your code that doesn't exist

#

or you're missing a using statement

queen adder
#

and i dont know what of those 🙂

wintry quarry
#

on line 19 of player_movement.cs

rich adder
#

(are you missing a using directive ??? )

queen adder
#

yea let me see

wintry quarry
rich adder
#

is that part of InputSystem..oh issa struct

wintry quarry
#

like if you wrote:

Bagel b;``` that would be an error if you never defined a type named `Bagel`
#

that's your error

#

but with PlayerActions

queen adder
#

i mean i added these and now when i am deleting something with 'PlayerActions' i have more errors ughhh

wintry quarry
#

It's better if you try to understand

rich adder
queen adder
#

i try but im shit at this

#

ugh

#

this is hard

wintry quarry
rich adder
#

new InputSystem is also not very beginner friendly..you jumped into a shark tank right away..

wintry quarry
#

Right now you're working with basically 0 knowledge of what you're doing

queen adder
wintry quarry
#

Yes

#

everyone needs to start from basics

#

2D games and 3D games are equally complex

tepid tide
rich adder
queen adder
#

tysm

rich adder
#

generally you can loop through a certain number and create a ray / bullet per each with slight offsets

tepid tide
rich adder
cosmic quail
rich adder
#

but will be just copying and pasting

#

not learning

tepid tide
#

How to make ALL kinds of GUNS with just ONE script! (Unity3d tutorial):
Here's how to make one script,, which lets you create any gun you like :D

All of the Links ^^:
My Discord: https: https://discord.gg/5S3bBBq
Download CODE: https://www.dropbox.com/s/g077hpelcdnjyqm/GunSystem.cs?dl=0
Brackeys video: https://www.youtube.com/watch?v=9A9yj8KnM8...

▶ Play video
cosmic quail
#

you can learn by doing tbh

rich adder
#

yeah but some basic knowledge is needed, like how to properly type the syntax and basic c#

cosmic quail
#

unless you dont even know the basics of unity yeah

cosmic quail
tepid tide
rich adder
#

ide is at least configured..

#

half way there

tepid tide
#

dont really know what is happening

rich adder
#

yes you blindly copied without knowing you have to actually create types beore using them

cosmic quail
eternal falconBOT
#

:teacher: Unity Learn ↗

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

rich adder
#

also a compare tag and get component, tutorial is shit

#

they never heard of TryGetComponenot or caching the component as a specific check ?

#

316k views tho.

mystic lark
#

What is the comand for destroying a game object

queen adder
#

like in game or in hierarchy??

rich adder
#

like fr fr. dont be lazy

mystic lark
#

ik lol but it this usualy faster than just getting a fhole page that i have to read

queen adder
#

like i mean informatics are lazy but that much?? damn

#

idk how to say it

#

lmao

mystic lark
rich adder
queen adder
#

ChatGPT is also good

mystic lark
queen adder
#

so you wanna wait 5 mins till someone respond??

#

ok

mystic lark
#

BUt anyway see i got another pesrson to gogle it for me and i got my answer in less than 30 sec

astral falcon
wheat escarp
rich adder
languid spire
rich adder
#

true

mystic lark
queen adder
#

but you could just google it dude😭

astral falcon
queen adder
#

lmao

mystic lark
#

yes ik leave it alone i wont do it again i get it

queen adder
#

ok gl with code

wintry quarry
eternal falconBOT
verbal dome
#

Wrap it in ``

#

Oh that part yeah

queen adder
verbal dome
#

Read the bot message for proper fornatting

meager needle
#

is there any way to make a health bar linked to an enemies health if i'm using two different scripts or sohuld i just put them in the same one ? 😓

rich adder
meager needle
#

im lowkey cooked i've been stuck on this for 40 minutes and im mad lost 😓

wintry quarry
meager needle
wintry quarry
meager needle
#

no probs

#

ill do that quickly

#

!code

eternal falconBOT
meager needle
wintry quarry
#

you don't put ``` if you're using a paste site

meager needle
#

oh

#

oops

#

LOL

#

sorry

wintry quarry
#

also you commented out the class declaration?

#

and that second link is just the blank pastebin link

meager needle
#

oops

meager needle
wintry quarry
meager needle
#

oh oops

#

it isnt commented for real 🙏

#

lemme just

#

copy and paste it fully

wintry quarry
#

Just copy and paste the whole thing yes lol

meager needle
#

this should work

naive pawn
#

are TakeDamage and Heal being called at all?

wintry quarry
#

Ok it's really confusing what's going on here

#

which script is supposed to do what here?

#

What is the role of each script?

#

And which object(s) are they on

meager needle
#

enemyhealth is for the enemy to take damage and do the sprite anims

#

on the Enemy object

wintry quarry
#

The fact there are two variables that seemingly represent the current amount of health you have:
public float healthAmount = 100f;
public float currentHealth;
This is very problematic

naive pawn
#

ok that just seems like manage health 1 and manage health 2

wintry quarry
#

you need to have one source of truth

meager needle
#

and the Health1 is on a HealthManager object (i was told to put it on there)
and is supposed to be reflecting the damage onto health bar

naive pawn
meager needle
#

did i put too many variables 😓

wintry quarry
#

Yeah it's super unclear which one of these variabels actually determines what the current health is

meager needle
#

that do the same thing

wintry quarry
#

yes

naive pawn
#

you might want to consider health and maxHealth instead

meager needle
#

okaydokes

naive pawn
#

those are the typical terms used in games

wintry quarry
#

I would expect:

  • One script on the enemy that actually manages the enemy's health situation
  • One script on the UI that handles displaying the health from the first one in the UI
#

that's it

meager needle
#

okaydokes

wintry quarry
#

And name the scripts clearly like:
EnemyHealth and HealthBarUIHandler or something

meager needle
#

alrighty alright

#

thank you

wintry quarry
#

Health1 is very vague and doesn't telll us what this thing is supposed to do

meager needle
#

okaydokes

#

ill change them up

#

so i should remove a variable and make one variable i'll use through both scripts?

wintry quarry
#

Yes, the scirpt that actually manages the enemy's health should be the only one with a variable that represents how much health the enemy has.

#

the other script can read that information from the health managing script as needed

meager needle
#

okaypokes so the health managing one shouldnt actually interact with the health other than displaying it ?

wintry quarry
#

One super simple example:

public class EnemyHealth : MonoBehaviour {
    public float Health { get; private set; }

    public void TakeDamage(float damage)
    {
        Health -= damage; // minus  the damage from healthamount
        Health = Mathf.Clamp(healthAmount, 0, 100); // check healthamount is within valid range
    }

    public void Heal(float healingAmount)
    {
        Health += healingAmount; // Add healing amount to healthAmount
        Health  = Mathf.Clamp(healthAmount, 0, 100); // Ensure healthAmount is within valid range
    }
}

public class HealthBarHandler : MonoBehaviour {
    public Image HealthBar;
    public EnemyHealth enemyHealth;

    void Update() {
      HealthBar.fillAmount = enemyHealth.Health / 100f;
    }
}```
wintry quarry
wintry quarry
meager needle
#

okaydokez ill try my best and if it comes to it i'll use that one

#

thank u very much :)

mystic lark
#

is there a way i can stop the timer ?

vestal matrix
#

So somebody at some point recommended me to Newtonsoft to write classes to json as savedata
I'm having an issue where I have this class:

// Put here all the flags you need for the story
public enum EventFlag
{
    TestVar_HasCrossedPlane,
    TestVar_HasInteracted,
    HasLighter,
    HasLantern,
    HasSeed,
    HasCrayon,
    HasWateringCan,
    MuseumEntered,
    MuseumExited,
    IntroDialogueEnded,
    GodDialogueEnded,
    ManDialogueEnded,
    TreeDialogueEnded,
    NakedDialogueEnded,
    PowerDialogueEnded,
    ReturnDialogueEnded,
    SeedDialogueEnded,
    SelfDialogueEnded,
    EndDialogueEnded


}

public class EventFlags
{
    private List<bool> events = new List<bool>();

    public EventFlags()
    {
        
        for (int i = 0; i < System.Enum.GetValues(typeof(EventFlag)).Length; i++)
        {
            events.Add(false);
        }
    }

    public EventFlags(EventFlags eventFlags)
    {
        for (int i = 0; i < eventFlags.events.Count; i++)
        {
            events.Add(eventFlags.events[i]);
        }
    }

    [Other methods...]
}

And when I try to serialize it like this: JsonConvert.SerializeObject(flags)
I just get {}

#

Does newtonsoft not support lists?

obsidian plaza
mystic lark
#

yea thast what i mean is there a way?

naive pawn
#

yeah just stop counting

obsidian plaza
#

u would need to remove it from update

#

put it in its own function

slender nymph
naive pawn
mystic lark
obsidian plaza
#

true but i would

obsidian plaza
naive pawn
#

im not

obsidian plaza
#

brutha

naive pawn
mystic lark
#

i was thinkinng of something like that but i think i found i way

wintry quarry
true owl
#

is there anything to replace drag in the new version of unity?

wintry quarry
true owl
#

i want an acceleration, deceleration time for my character

#

oh

slender nymph
#

did you look at the docs and/or read the error that said the drag property was obsolete?

true owl
#

it's not in the rigidbody anymore

wintry quarry
#

linearDrag

slender nymph
#

linearDamping in the latest versions actually

true owl
#

i see linear damping

wintry quarry
#

yes it's the same thing

#

damping is a better name for what it actually always was

#

it never behaved like real life drag

true owl
#

does the linear drag work if you're on the ground? I feel like it doesn't do anything

wintry quarry
slender nymph
#

linear drag is applied all the time. it's friction that is only applied when contacting other colliders

true owl
#

that's strange

#

i put my linear damping to 0 but my character still stops when i let go

#

so its the friction i need to adjust?

wintry quarry
true owl
slender nymph
#

wdym just using the sliders? aren't you setting the velocity of the object directly?

#

that would obviously not behave the way you are attempting to make it behave

wintry quarry
true owl
#

linear damping

wintry quarry
#

that's the code I'm talking about

#

But yeah this is probably a friction thing

slender nymph
#

it's also 100% the issue if they still have the code they showed a couple days ago where they are just setting the x velocity to the state of their digital input with no smoothing

tawny grove
#

i cant i remove this tile from the pallete? i accidently added it and the shift click thing isnt working

true owl
slender nymph
#

you're assigning the velocity directly, including when your input is 0. so when you have no input you set the x velocity to 0 which means there is no drag or friction affecting it at all. if you want forces to act upon the object then consider moving it via AddForce or just don't assign to the velocity when there is 0 input so that forces like drag and friction will slow it down

true owl
#

ah

#

i did ```
void Move()
{
if (!isDashing)
{

        /* if player is on ground or rail, have holding diagonally affect the same as just horizontally 
            otherwise just use the x input that comes in normally */
        float adjustedMoveInput = isGrounded || isOnRail ? (moveInput.x == 0 ? 0 : (moveInput.x > 0 ? 1 : -1)) : moveInput.x;
        rb.AddForce(new Vector2(moveInput.x * playerSpeed, rb.linearVelocity.y));
        Debug.Log(moveInput.x);
        // rb.linearVelocity = new Vector2(adjustedMoveInput * playerSpeed, rb.linearVelocity.y);
    }

    animator.SetBool("isRunning", true);
}
#

ignore the adjustedMoveInput it's not being used

mystic lark
#

i am trying to delete all clones at once with button press but its showing me this error, but its perfectly fine deleting in the OnTrigger. I tried searching but i cant to find the solution

#

the script is attached to the clones

slender nymph
#

you're calling that method on a prefab

vocal wing
#

when i change the first f nothing special happens just moves vertical normally but when i move second one my object disapears someone know why?

tawny grove
#

hello, I am unsure why this happened, but seemingly all of my scripts can no longer be found by unity. I am still able to access and edit them, but they can no longer be attached to objects. This isnt a script name issue as it is happening with even new and old scripts that were working before. any help would be appreciated.

slender nymph
slender nymph
eternal falconBOT
tawny grove
slender nymph
#

screenshot your entire console window

tawny grove
#

i was renaming some stuff which is what originally caused that error to happen, but because my edits no longer apply, i cannot resolve them

slender nymph
#

well it seems the issue is just in your RoomSpawner and HallSpawn script trying to access something called structures in your RoomTempelate script. and provided you actually save your code, your edits will apply. you just have to fix all of the issues so it can compile

tawny grove
slender nymph
#

prove it

tawny grove
slender nymph
#

notice how that is an entirely different file than the one the error is complaining about

true owl
#

so when would you want to manually set the rb.linearVelocity vs using rb.addForce

tawny grove
slender nymph
#

that is neither RoomSpawner nor HallSpawn

#

please actually pay attention to your errors (and also the responses you receive in discord), you may find that the issues are actually pointed to exactly

tawny grove
#

jesus christ dude you are so aggresive

#

and no, that did not resolve the issue, i will ask someone else

edgy tangle
#

He's right though. You need to learn how to actually interpret errors.

slender nymph
# tawny grove jesus christ dude you are so aggresive

you may want to look up the definition of aggressive, as that was definitely not it. but if you want to throw a fit because i'm not spoonfeeding you the answer and instead telling you where you should look, then i'll just not help you further. and yes this is the aggressive bit

tawny grove
#

what a dick head

slender nymph
#

i'd bet if you were to actually show the two files that are mentioned in the errors we'd find you didn't fix them at all

tawny grove
grand snow
#

you need to actually fix the real issue, if you comment out a whole file the class def is gone.... so another error is probably going to show up instead.

#

if you can see a small bit of code that when commented out will resolve all compiler errors then thats an okay temp solution

swift crag
#

(solution: delete those too!)

grand snow
#

at that point, delete the whole project and start over

slender nymph
#

hardcore programming: start over from the beginning each time you cause a compile error

rich ice
#

rougelite programming: restart the whole project each time you cause a compile error

normal glacier
#

I thought that learning C# would be hard because I only knew js but it seems quite easy so far

normal glacier
mystic lark
#

yes lol

naive pawn
normal glacier
# mystic lark yes lol

By what it seems you need to reference the gameObject you wanna destroy. It would be better to store them in an array like so

TheComponent[] theComponent = FindObjectsOfType<nameOfTheClassOfTheObjectsYouWannaDestroy>();

And then perform a for loop to destroy them one by one

mystic lark
#

thanks vm ill doo it

cosmic dagger
#

What objects do you need in a collection? I would add the objects to a list when they are instantiated (or activated on scene load). Then you can just reverse iterate the list and destroy them . . .

normal glacier
#

I started to code c# and unity this sunday so idk😭

swift crag
#

you only need to do reverse iteration if you are removing them from the list as you go, mind you

#

I'd just do

#
foreach (var whatever in stuff) {
  Something(whatever);
}

stuff.Clear();
edgy tangle
#

but yeah

#
foreach (var whatever in stuff) {
  if (!whatever) continue;

  Something(whatever);
}

stuff.Clear();
winter creek
#

Hi , how can i do these class like that please and what is the name of that ( Scriptable Object ? something else ?)

slender nymph
#

that is a scriptable object

normal glacier
slender nymph
#

they may not necessarily be public though, they can be private with a SerializeField attribute to expose them to the inspector

normal glacier
#

Thx

true owl
#

is there a way to use rb.linearVelocity = ...
and still keep linear drag

#

or do i HAVE to use rb.addForce

#

i still cant figure out why my player can't move back with rb.AddForce, only forward

slender nymph
#

it depends on how/when you want the drag to apply. you can either compute it yourself and just apply the velocity manually, or if you only want the drag to apply when you've released the button then do what i told you earlier

slender nymph
true owl
#

sure 1 sec

slender nymph
#

make sure to show the full !code using a bin site 👇

eternal falconBOT
true owl
#

I tried using rb.AddForce

#

but it only goes right, left should work but it doesnt

#

also when I dont add a friction object to the player he cant move at all

#

when I do that issue occurs like i stated above

winter creek
slender nymph
true owl
#

i tried the Mathf.sign like you said but

#

it didn't work

#

even though it should

slender nymph
#

ah yes "didn't work" how descriptive

cosmic dagger
# normal glacier I started to code c# and unity this sunday so idk😭

@mystic lark As someone who learned C# along with Unity and no prior programming knowledge, I found it to be relatively easy (the basics), but it solely depends on your discipline and willingness to learn

If you don't have that, it's very difficult as there is no time frame or estimate for how long it takes. Motivation doesn't help as it only inspires you to work, not actually do it . . .

true owl
#

i mean i have no idea how to describe it like the player just wouldn't move properly

#

even if i just use moveInput.x it doesn't make a difference

#

the same issue occurs

slender nymph
#

well if you can't describe it then nobody can help you 🤷‍♂️

true owl
#

so I don't think it's that

slender nymph
#

anyway, i told you earlier to log your input and velocity so you can get a better understanding of what is happening. so you've gone and removed your log for the input and are now only logging the velocity

true owl
#

I logged my input before and it was outputting properly

#

1,-1,0

slender nymph
#

log them both at the same time, that's the whole fucking point of doing so

rich ice
true owl
#

sure

rich ice
true owl
#

not really sure what this is supposed to do

#

it's just a really small value

edgy tangle
true owl
#

for the velocity

slender nymph
#

and what is the value of playerSpeed

edgy tangle
cosmic dagger
normal glacier
swift crag
normal glacier
#

I coded flappy bird, next game will be mario

true owl
#

always

mystic lark
# cosmic dagger <@1165426031721717924> As someone who learned C# along with Unity and no prior p...

i know i didnt start just this week i started with the basics like 3 moths ago and didnt realy tuch unity unitll i understood somewhat the basics then i tried making a really simple 2D pong game without tutorial, and i made it with liltle help. now im making flapy bird also without tuorial and as little help as possiblle but i still dont understand stuff so i ask here for help or serch on the topic i am intersted and lean it and people give me some answers and i learn off that

slender nymph
# true owl 30

that's pretty high. do you also have an insane drag value?

#

maybe super high mass too?

true owl
#

my lin damping is set to 0.92 and the auto mass is 0.82

winter creek
#

Thank you guys

slender nymph
true owl
#

right

#

im not sure i'll figure it out

#

it's definitely this addForce thing

slender nymph
#

show me your current log

normal glacier
#

Can I 2d pixel art inside unity

winter creek
slender nymph
#

the default execution order is a hack to prevent issues with accessing the singleton in Awake in other objects.

winter creek
slender nymph
#

no, i recommend not fucking with the script execution order if you can avoid it (you can). either initialize the singleton earlier than Awake, don't access it in Awake or OnEnable on other objects, or lazy load it.
here's my implementation of the singleton pattern that initializes before Awake (not that i ever actually access it in Awake on other objects anyway), and also lazy loads it if an instance doesn't exist
https://github.com/boxfriend/Utils/blob/master/com.boxfriend.utils/Runtime/Utils/SingletonBehaviour.cs

cosmic dagger
slender nymph
# winter creek Ok thank you

note that the implementation you showed was perfectly fine otherwise, and even can be fine if you aren't messing with the script execution order much else either. i just personally find that having to modify the script execution order to prevent errors caused by my own code is hacky

west radish
thorn iron
#

I wish to create ingredient in my restaurant game.
But I don't know how to approach the data structure of the ingredient, whether it's a class, a structure or scriptable object.
The main points of ingredient are :

  • the ingredient has read only datas, and no methods.
  • a new ingredient can be created on unity editor
  • on unity editor, all Mono behaviour which properties contain an ingredient can be manually allocated an custom ingredient that I have created previously
wintry quarry
pure drift
#

!code

eternal falconBOT
pure drift
pure drift
pure drift
rich adder
pure drift
west radish
#

But if it gets called multiple times it'll get multiplied to be smaller every time

#

1, 0.5, .25, .125

rich adder
#

sounds like thats why it goes so quiet right away

pure drift
#

ohh so how could i make it so that it doesnt reduce like that

rich adder
#

have you looked into unity audiomixer it has a master slider already

pure drift
rich adder
#

idk what "all that" means

rich adder
#

if you want the percentage idk why you can't just use the values as is

#

0-1 I look at as percentage

pure drift
#

i kinda want it to be so that it is like where if the sfx is 0.5 but the master is 1 it stays the same if that makes sense

west radish
rich adder
#

like the master scales to 0.5 and you want sfx to be .25

#

ye was going to write similiar thing

#

sfxSource.volume = sfxVolume * masterVolume;
musicSource.volume = musicVolume * masterVolume;

swift crag
rich adder
#

idk I just use audio mixer 🤷‍♂️

#

why rewrite already similiar system

pure drift
cosmic dagger
swift crag
#

(Also, while you're setting up the audio mixer, switch from "linear" to "squared" to get a volume slider that actually sounds linear)

#

unless it was "SquareRoot"; been a hot minute

#

and I'm using FMOD now so I removed my AudioMixer configurations

cosmic dagger
#

@pure drift The problem is when you set the SFX or music volume, it doesn't take into account the master volume . . .

pure drift
edgy tangle
#

You’re making your life harder by not just using the built-in audio mixer system

cosmic dagger
#

I'm unsure why you're not using the audio mixer, it easily does all of this for you. If you connect/link your SFX and music volume mixers to the master audio mixer, it automatically scales the volume when the master volume is changed. You can even set up separate filters for each mixer . . .

pure drift
acoustic meadow
#

whats the best way to lear C# When i have almost never touched it before and dont know what 99.9% of stuff do in there and where should i but the stuff jk and watching tutorials is kinda slow and im probrably not gonna learn much from videos

slender nymph
#

start with the beginner c# courses pinned in this channel

acoustic meadow
#

thanks!

#

its gonna be hard because i dont even understand what some words mean :D

#

english is not my main language haha

slender nymph
#

do the intro to c# course on the microsoft site and set it to your preferred language

acoustic meadow
#

Thanks you guys are real helpful!

slender nymph
cosmic dagger
hasty dragon
#

what does awake() do\

#

i meant why use start if theres awake

rich adder
#

because they are different

cosmic dagger
slender nymph
#

because they happen at different points in the object's lifecycle

rich adder
#

awake => initializations etc
start => reference access etc.

cosmic dagger
#

Awake is called before Start. Awake is called on disabled GameObjects, and Start is called when a GameObject first becomes active . . .

slender nymph
#

Awake and OnEnable are called immediately when an object is instantiated. Start is called later, which could be the same frame or the next frame. the only guarantee is that it will be called before any Update is.
typically you would use Awake for self-initialization and Start for reaching out to other objects

hasty dragon
#

i see

rich adder
cosmic dagger
rich adder
#

apparently public methods called from other scripts do fire on disabled GO, so opted for a public Init() instead

cosmic dagger
#

well that makes sense. so long as you have a reference, you can access and call methods on any GameObject. being active only affects the Unity lifetime methods . . .

rich adder
#

hah yeah assumed wrong that somehow unity was doing something special that might prevent that and maybe only setactive was something different but realize now its untouched

cosmic dagger
#

yep, a lot of my scripts have an Init method for setting them up. i just can't decide being using Init or Initialize. i have both and i need to figure out which one to stick with . . .

#

probably because i have Deinit and Deinitialize as well . . .

rich adder
#

Yea feels much better controlling the events with init method, thats good idea should also have something to do that, maybe Disassemble lol

sullen delta
#

!code

eternal falconBOT
cosmic dagger
# rich adder Yea feels much better controlling the events with init method, thats good idea s...

i make my scripts pretty different from what is standard. i have a brain/controller script with the Update methods. all other scripts on this GameObject have an OnUpdate or OnUpdateXXX method. the brain references all the scripts and calls OnUpdate for them in their Update

when enabled or disabled, the brain adds/removes itself to the correct Update list on an UpdateDispatcher MonoBehaviour. this list holds all active GameObjects and iterates the list in its Update method

this allows me to separate and test systems or mechanics by simply enabling or disabling them to isolate an individual script . . .

rich adder
cosmic dagger
# rich adder ohh this is pretty interesting, seems like a good way to keep things flexible. R...

very true. there are different patterns that can work. i'm deciding (or was until i forgot about it) to allow the child scripts (of the brain/controller) to search for the brain script and add themselves to an event. then, the brain would invoke this event in their Update method giving me the same functionality, but without needing to manually add a reference to each child script that is a part of the brain

i'd miss out on having control of the call order, but i can dynamically attach and remove each child-like functionality from the brain . . .

rich adder
verbal dome
#

@acoustic belfry What you call "voids" are actually methods/functions

acoustic belfry
#

Hi, how i can make that when an object interact with another, it activate the other objects methods

verbal dome
#

(from unity-talk)

acoustic belfry
#

oh, thanks

rich adder
acoustic belfry
#

i mean cuz i know how to make it interact...i guess

acoustic belfry
#

thats why the name

verbal dome
#

DoThing is a method. You call the method with the ()

acoustic belfry
#

also, btw i have to get circle collider trigger on? Cuz i did a lot of other scrips (not made by me, just copy pasting tutorials, thats why im in here now, for make it from scratch) and none of them worked

#

now i have it turned on btw

acoustic belfry
#

also, is there a way to modify the value of the state?

verbal dome
#

Use triggers if you don't want actual physical interaction but need to detect when things overlap

acoustic belfry
#

like, i make the player do thing, and also, i add a value, like, damage

rich adder
acoustic belfry
#

method

rich adder
#

you can modify anything as long as its public

verbal dome
#

Non-triggers are for actually colliding with things

acoustic belfry
#

is just i came from GzDoom and everything is called a state, QwQ

rich adder
acoustic belfry
#

mmm...
then what i should do?

rich adder
#

what does method do?

acoustic belfry
#

cuz what im seeking to do...and that i thought it would be easier for me QwQ but im dumb
Is,
Proyectile touches Player, player loses points on the int value health depending on the proyectile

rich adder
#

pass specific values into it, change the state

acoustic belfry
#

and try to make it the most "by me" and simple possible

#

cuz obviously is better to know what you wrote than just copy pasting

acoustic belfry
#

depending technically on the proyectile

rich adder
verbal dome
#

You can add a TakeDamage (you can name it whatever you want) method to the player. It could take an integer/float value as a damage parameter

polar acorn
acoustic belfry
#

i mean, i know what to do, my issue is, how to write it

rich adder
#

with code

acoustic belfry
#

thats technically always my issue with this kind of stuff

verbal dome
#

Tbh since you didn't know what void means or what methods are called, I feel like you have skipped the basics

#

Of C#

rich adder
#

yeah that is part of the reason its diffcult to write it

#

you have to know the basics of c#

polar acorn
rich adder
#

unity has an API function for each thing you need, just need to know how to read that api (knowing c# basics)

acoustic belfry
#

oh, right

#

well, thanks

cosmic gorge
#

vsc not recognizing PlayerMovement as a component???