#💻┃code-beginner

1 messages · Page 13 of 1

timber tide
#

I choose to use arrays for my inventory and slots, and many other things that should be of limited indices. Easier to debug imo

wary sable
#

for context:

#

red = array, green = list

#

actually after taking a step back I will probably have to refactor a decent bit of what I've started just to make integration with the ui a bit simpler, oh well time to sleep

timber tide
#

looking good

queen adder
#

If the slots are named you should use a struct

#

To be honest even for the unnamed one you probably should

#

Actually, to be honest, if you have nullable fields (e.g. they can be empty) a dictionary indexed by an enum might be more appropriate

chilly sandal
#

helo everyone i am stuck at some point whene i want to add more prefabs in the script of manomotion sdk and then i want them to change/spwan/loop these prefabs on ui button click.... but i donno how to achieve this!!! here is the script and the sdk is used giving by manomotion sdk for ring try-on example
https://paste.ofcode.org/RwAgCJkk8NkrvAPjrGc2JL

#

can anyone help em out in this?

fossil drum
eternal falconBOT
#
Posting code

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

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

chilly sandal
#

here it is ... and i am sorry i didn't know about that..

fossil drum
#

No problem, now you do UnityChanThumbsUp

chilly sandal
#

so is ther any solution regarding it ?

tender stag
#

when smelting finishes i get an error on line 123

#

it removes the item from the cell and etc, it just doesnt spawn a new item

#

the outcome

#

wait it does spawn it

#

but i get an error

fossil drum
tender stag
#

i can when i get home

#

idk if your still gonna be willing to hell

tender stag
tender stag
ivory bobcat
#

Should post it in the forums if you need archiving. People will not check old messages on Discord.

tender stag
#

it worked when i didnt have the foreach inside the foreach

ivory bobcat
fossil drum
# tender stag i just left for college

Don't know, but I think the full stack trace would be useful. It might also be that you are foreaching over a list with null values in them. Anyhow, good luck.

ivory bobcat
#
inputCell.cell.Remove();
Destroy(inputCell.cell.item.gameObject);``````cs
inputCell.cell.item.GetProcess(ProcessTypes.ProcessType.Smelt).processOutcomes```
silent jay
#

I'm making a game where you need to catch falling coins, your score goes up with each coin you catch. Is there a way to make it so the score only increases when the coin lands in the catcher? (at the moment if the coin touches the catcher at all the score goes up, even if you didn't properly catch it)

fossil drum
silent jay
ivory bobcat
ivory bobcat
silent jay
#

At the moment I'm using the mesh collider to register the collision

ivory bobcat
#

Example: It's considered caught when the velocity of a coin is minimized below a certain threshold but within proximity or making contact with a bucket etc.

silent jay
#

At the moment the score increases if it makes any contact with the chest. I'm trying to make it so if the coin hits the sides nothing happens but if it lands inside the chest the score goes up

#

So score goes up if the coin goes in the green but just bounces off if it hits the red

eternal needle
#

As suggested above

silent jay
#

I'm very dumb, how do I make a trigger area in the chest?

#

As I said I'm just using a mesh collider rn

#

What do I script to make it differentiate between the two different colliders?

eternal needle
silent jay
#

From the inspector to where?

eternal needle
#

This would be entirely within the inspector, where you would drag the box collider into the appropriate field

ivory bobcat
#

If you opt to use another object such as a box (child), you can make it invisible by disabling the renderer and set IsTrigger to prohibit collision etc.

silent jay
#

...ok

#

I'll try some of your suggestions

chilly sandal
silent jay
fringe pollen
chilly sandal
#

yes

fringe pollen
#

Use inatantiate to spawn them and use the TMP buttons which make it really easy to connect functions to button clicks

chilly sandal
fringe pollen
chilly sandal
hollow zenith
fringe pollen
chilly sandal
stoic spear
#
        //Camera
        transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivity, 0);
        cam.Rotate(-Input.GetAxis("Mouse Y") * sensitivity, 0, 0);
        //Movement
        rbLateralVelocity = new Vector3(rb.velocity.x, 0, rb.velocity.z);
        Vector3 tgtMoveDir = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical")).normalized;

        if (tgtMoveDir == Vector3.zero) rb.AddForce(-rbLateralVelocity * removeSpeed, ForceMode.Force);
        else if (rbLateralVelocity.magnitude < tgtSpeed) rb.AddRelativeForce(tgtMoveDir * addSpeed, ForceMode.Force);

        //Jumping

        Vector3 v3 = new(transform.position.x, transform.position.y + 1, transform.position.z);
        if (Physics.Raycast(v3, Vector3.down, out RaycastHit hit, 1.1f))
        {
            isGrounded = true;
        }
        else
        {
            isGrounded = false;
        }
        if (Input.GetKeyDown(KeyCode.Space) && isGrounded) rb.AddRelativeForce(Vector3.up * jumpHeight, ForceMode.Impulse);
    }```
#

currently having a weird issue where every time i land from a jump, my lateral velocity is reset to 0

fossil drum
stoic spear
#

well, i just tried moving the AddForce lines to FixedUpdate() and now i cant move at all hollow

fossil drum
stoic spear
#

aaand also running into the issue where if i walk into an obstacle it starts rotating me

#

ive figured out the jump thing, it feels a lot better if i just make the jump smaller

ivory bobcat
#

Physics forces can be done in Update if they're instantaneous (impulse etc)

silent valley
#

how can i make it so the notebook updated text only happens once?

eternal needle
burnt vapor
eternal falconBOT
#
💡 IDE Configuration

If your IDE is not autocompleting code
or underlining errors, please configure it:

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

VS Code*
JetBrains Rider
Other/None

*VS Code's debugger plugin is unsupported.
We recommend using VS or Rider instead.

silent valley
burnt vapor
#

I don't know about Jetbrains, but I do know you should definitely not use Visual Studio Code for Unity since the support is very bad (I guess that's what you mean with plugin?)

silent valley
#

I'll uninstall everything and start from scratch with setting it up

burnt vapor
#

Feel free to message me if you get stuck. I do have a long ass meeting in 40 minutes but I'll try to answer.

silent valley
#

I appreciate that. I'll get on it now

queen adder
#

is it possible to make an inspector property that holds 2(or more) floats(from 0-1) in a single slider?

#

via custom editor

frozen dagger
#

hello, i did player controller and its ok for me, but it have an problem, when i colide with any object it stop moving, but if i dont press horizontal buttons it falling down, is there any tutorial on youtube how to fix it or can you help me?

ivory bobcat
burnt vapor
#

But I am just making assumptions since you haven't actually shared your !code

eternal falconBOT
#
Posting code

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

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

burnt vapor
#

Yes so notice how the check for grounded checks for a collission with something that has the Ground tag. This is the platform you hit, and this causes the velocity to reset.

#

It is not a good idea to have such a simplistic system for this. Instead you want to make a second collider just below the player, which will check if it collides with anything at all. The player collider is then just a simple collider

frozen dagger
#

... its a wall... but, it colides ground too

burnt vapor
#

If you want to improve it even more, you add a seperate collider on all sides, and you can then determine if you get hit on any side. For example, if you run right and the right collider has a collission, you can reset the velocity

burnt vapor
#

So as I said, you should probably make multiple colliders for each side, or you need to somehow determine on what side the collission is coming from

#

I personally make multiple colliders since it is simpler, and then I maintain a context of what sides are being hit at that point.

frozen dagger
#

okay

#

ill try

frozen dagger
#

i fixed it with this:

    if (walled == false)
    {
    rb.velocity = new Vector2(move * speed, rb.velocity.y);
    }

private void OnCollisionEnter2D(Collision2D other)
{
    if (other.gameObject.CompareTag("Ground"))
    {
        grounded = true;
        speed = setSpeed;
        walled = false;
    }
    if (other.gameObject.CompareTag("Wall"))
    {
        walled = true;
    }
}

so, when it colides only with wall it wont be able to move, but if it colides with ground too it will be able to move

#

cuz im new to code and i dont know anything better than this

#

greate.. i dub... i got another proble ny doing this...

#

i hate to learn ore about how to code..

idle orbit
#

A quick question, I have a grid menu for mission select that currently uses mouse input and I would like to add controller and keyboard support on top of that. What do you suggest?

rare basin
#
    public AnimatorController graphicsShowcaseAnimatorController;
    public AnimatorStateMachine animatorStateMachine;
    public AnimatorState animatorState;

these variable types are using UnityEditor.Animations namespace. If i understand correctly, I cannot use them in build, just in the editor?

#

how can i use these variables in the build? I kinda need them

teal viper
#

You can't. Store the data in some other way/ custom class/struct.

rare basin
#

i see

#

thank you

willow imp
#

How to let AGameObject position move to BGameObject position

timber tide
#

gameobject.transform.position

willow imp
#

I want AGameObject like Animation move to BGameObject just like gun shooting

teal viper
#

transform.position

#

Over time

#

For example you could lerp between origin position and the target position.

willow imp
#

Thanks you

silent jay
#

My intellisense isn't working like it should (or at least how I'm used to it working) and visual studio isn't showing me errors. I have to save the script and go back to unity to see errors in the console. Is there something I need to enable/install or is it just messed up for whatever reason?

fossil drum
silent jay
fossil drum
# silent jay

It isn't configured, read the !vs guide on how to configure it for Visual Studio

#

!ide

eternal falconBOT
#
💡 IDE Configuration

If your IDE is not autocompleting code
or underlining errors, please configure it:

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

VS Code*
JetBrains Rider
Other/None

*VS Code's debugger plugin is unsupported.
We recommend using VS or Rider instead.

fossil drum
#

!vs

eternal falconBOT
#
Visual Studio guide

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

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

silent jay
#

Just didn't want to work the first time it seems haha

fossil drum
silent jay
#

Ok

#

Thank you

fossil drum
astral temple
#

!vs

eternal falconBOT
#
Visual Studio guide

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

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

willow imp
willow imp
#

Thanks

#

But how to fix the code?

fossil drum
willow imp
#

it say Enemy line 37 is problem line but I don’t have a idea to fix it

north kiln
#

Did you go through the doc, and understand what the cause is, and also get to the part where it talks about resolutions for the type of object you're dealing with?

edgy prism
#

Hello Random.Range in the unity docs say its both minInclusive and maxInclusive but in Visual Studio it says its minInclusive maxExclusive I am like 90% sure that the docs are correct but someone is telling me theyre not can someone smart clarify which one is correct for me?

shell sorrel
#

you might be looking at the float vs int overloads for it @edgy prism

shell sorrel
#

float is both min and max inclusive

#

int is min inclusive and max exclusive, its done this way so the random range on ints would be valid indexs

#

for example
var id = ids[Random.Range(0, ids.Count)]; would be valid code since ints are max exclusive

edgy prism
#

Thankyou for clarifying

weak plaza
#

When I do Screen.SetResolution
Only the windows size changes.

sage mirage
# willow imp How to solve it

Hello, friend! When in your code arising errors like this one, then you have to think that you forgot either something in your inspector of an object for example a value that you didn't save or there is a null reference and you don't initialise the field/variable of the object that's the most common errors but still sometimes they can be complicated XD

modest dust
#

Well, he's trying to use GetComponent<Bullet>() on the GameObject with the Enemy script

#

He most likely wanted to do it on the newly Instantiated Bullet

#

Leaving aside the part where he could just reference the Bullet script instead of the GameObject and instantiate that

sage mirage
#

I barely see what the code says why he didn't take a screenshot from his pc and take a photo from his phone

modest dust
#

Maybe he doesn't have discord on his PC because he doesn't want his mom to see his discord dms

#

Either way, it's readable enough

swift crag
#

Sign in to the discord web application

modest dust
#

If you have a magnifying glass at hand

swift crag
#

Posting photos of your screen is awful

dusk minnow
dusk minnow
#

yes my friend

#

those greens are blocks where tower can be placed

wintry quarry
# dusk minnow yes my friend

If it's a perspective camera, cam.ScreenToWorldPoint is only going to return the camera's position the way you're using it

#

yeah ScreenToWorldPoint is the wrong approach here

#

Use Plane.Raycast

swift crag
#

(or just use ScreenPointToRay plus a raycast)

#

ah yeah, that's the second option on that page

dusk minnow
#

Everything works now ❤️

#

Thank you guys

swift crag
#

Everyone gets tricked by that perspective camera behavior at least once

rare basin
#

Hello. I want to disable collision between player and dead enemy bodies, so I've created this function

        public void DisableCollisionsWithPlayer()
        {
            foreach (RagdollComponent[] ragdollComponents in ragdollComponents.Values)
            {
                foreach (RagdollComponent ragdollComponent in ragdollComponents)
                {
                    ragdollComponent.collider.gameObject.layer = deadEnemyLayer;
                }
            }
        }

that sets collider object's layer to deadEnemyLayer set through inspector, and I've disabled collision between player and deadEnemylayer layers, yet my player still collides with the enemy dead body. Any ideas why?

swift crag
#

Perhaps there are other colliders on the enemy.

#

Log the exact collider your'e hitting

rare basin
#

Okay i figured it out, the layer is not changing

#

its still on Enemy layer

#

did i change the layers wrong in code?

swift crag
rare basin
#

it is supposed to be on DeadEnemy layer

swift crag
#

does it happen to be a LayerMask

rare basin
#

public LayerMask deadEnemyLayer;

swift crag
#

yeah, that won't work

rare basin
#

ow

swift crag
#

a LayerMask is a combination of layers

#

basically, 32 layers get packed into a 32-bit integer

rare basin
#

oh yea true

swift crag
#

each bit is a 1 or a 0 for yes or no

rare basin
#

cuz i can set many layers in LayerMask

#

how can i do this tho?

swift crag
#

You want to use LayerMask.NameToLayer to convert a name to a layer ID

#

I don't know if there's a way to just pick a single layer ID in the inspector

rare basin
#

ragdollComponent.collider.gameObject.layer = LayerMask.NameToLayer("DeadEnemy");

swift crag
#

you probably can..

#

But yeah, that'll work just fine

#

You were probably setting the layer to a really big number

#

I dunno what the exact behavior is. It might give you an error.

north kiln
#

Afaik you have to make/find a property drawer

#

No idea why there's no property attribute for it

rare basin
#

okay i see

#

thank you guys

swift crag
#

they forgor

#

):

odd radish
#

I got this code from brackey's, movement script for single player

#

and tried to change it for multiplayer

#

but I can't seem to look to the left or right

wintry quarry
north kiln
wintry quarry
polar acorn
odd radish
#

I'm not getting any errors

#

and it seems that the camera wants to go to the left and right but gets stopped

wintry quarry
#

e.g. you're setting the rotation to the mouse input instead of adding the mouse input to the rotation

odd radish
#

it shakes shortly when I try going left or right

wintry quarry
#

but without seeing the code, can't say for sure. Just guessing

odd radish
#

Mousescript:

#

Movement script:

polar acorn
#

What is Player set to

odd radish
#

Empty gameobject, highest in the hiërarchy for player

wintry quarry
odd radish
wintry quarry
#

or perhaps from the networking aspect

odd radish
#

This is the player prefab

wintry quarry
odd radish
#

Didn't change anything saying that it shouldn't so I don't know why it would :x

toxic geode
#

Leak Detected : Persistent allocates 75 individual allocations.
What does this mean? How do I fix it?

polar acorn
# odd radish

Is that MouseLook script rotating itself? You should have a separate object doing left/right than the one doing up/down

wintry quarry
toxic geode
#

Yes

polar acorn
#

Player should be a different object, like in the tutorial

wintry quarry
# odd radish

yeah that mouse look script is expected to be on a child object of the Player object

#

the way you have it, it's going to reset the rotation constantly

#

with transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);

#

see how you're setting y rotation to 0?

#

It's intended to be:

Player
  Camera (with that script, pointing at Player for the Player reference)```
#

that's how that tutorial is structured

toxic geode
odd radish
#

indeed that was the problem, put the script on the player camera

#

and then put the player gameobject inside the script

#

and that fixed it

#

thanks @toxic geode @wintry quarry @polar acorn @north kiln

merry spade
#

I have a problem... Im programming with unity for 2 days now and i dont understand this whole collider thing its just weird if im too fast im glitching under the map if im normal and i collide with something all controlls are screwed up, here: In the second phase after i collided with the cubes im only pressing S and its making a curve why is that?

wintry quarry
merry spade
#

how do i send code?

wintry quarry
#

the answe to your question is: because your code and scene are set up in a way that causes that.

#

!code

eternal falconBOT
#
Posting code

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

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

merry spade
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{

    private float dirX = 0;
    private float dirZ = 0;

    private float speed = 5;
    
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        dirX = Input.GetAxisRaw("Horizontal");
        dirZ = Input.GetAxisRaw("Vertical");

        transform.Translate(new Vector3(dirX, 0, dirZ)* Time.deltaTime * speed);
    }
}
wintry quarry
merry spade
#

ah i should do it via velocity right?

wintry quarry
#

Via a Rigidbody or CharacterController

merry spade
#

what is better?

wintry quarry
#

there is no better

#

It depends on the needs of your game

merry spade
#

hm ok i will google the difference but thank you

polar acorn
# merry spade what is better?

Both of them are designed to do certain things easily, but at the expense of other things becoming harder. It depends on what kind of movement you want

merry spade
#

the easier one

polar acorn
# merry spade the easier one

Both of them are designed to do certain things easily, but at the expense of other things becoming harder. It depends on what kind of movement you want

swift crag
#

you have been presented with an apple and an orange and you said "Give me the easier one"

#

A CharacterController is designed to move in a way that respects colliders. It can never be affected by physics forces.

#

A non-kinematic Rigidbody is affected by physics. It will feel gravity (by default) and be shoved around by other physical objects

#

If your character's movement involves lots of physical interactions (e.g. getting launched by a flying platform or bouncing off of walls), then a Rigidbody is a good choice

#

If you want strict control over movement, then a CharacterController makes more sense.

merry spade
#

hm ok i tried it with a rigidbody but now i get: Screen position out of view frustum (screen pos 768.000000, 760.000000) (Camera rect 0 0 1467 762)
UnityEngine.SendMouseEvents:DoSendMouseEvents (int)

#

couldnt find something on the internet the posts to this error are even older than me xD

#

I tried to delete the auto created Camera and manually created one but it didnt work

summer stump
#

Did you try changing the view frustrum?

merry spade
#

whats that

#

im german whats frustum

#

ah

polar acorn
merry spade
#

camera script:

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

public class Camerascript : MonoBehaviour
{
    [SerializeField] Transform player;
    void Start()
    {
        transform.eulerAngles = new Vector3(50, 0, 0);
    }
    // Update is called once per frame
    void Update()
    {
        transform.position = new Vector3(player.position.x, player.position.y + 12, player.position.z - 10);
    }
}
#

ah i solved it nvm

sly lintel
#

is there a "And not" operator in c#?

#

nvm

polar acorn
merry spade
#

so many bugs with this movement thing, when i go against a wall while falling down i stop falling and if i go up a ramp i jump when i stop

summer stump
merry spade
#

velocity

summer stump
# merry spade velocity

So, a pitfall of that, is that if you are setting the velocity by making a vector from horizontal movement, and use a 0 in the y position, you are telling it to have 0 velocity in the y direction. Thus, you hover and won't react properly to gravity

merry spade
#

no i said it to keep the velocity it allready has

#

not 0

summer stump
#

Ah, ok, that is the right way to do it

merry spade
#

that if i implement jump later that it doesnt get overwritten by it

summer stump
#

Maybe something to do with your ground check then? Is it a raycast or overlap?

merry spade
#

i dont have a ground check

#

only have the velocity thing

#

nothing else

summer stump
#

Ok hmmm. I'd need to see code to comment further then.

merry spade
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{

    private Rigidbody rb;

    private float dirX = 0;
    private float dirZ = 0;

    private float speed = 8;
    
    void Start()
    {
        rb = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void Update()
    {
        dirX = Input.GetAxisRaw("Horizontal");
        dirZ = Input.GetAxisRaw("Vertical");

        rb.velocity = new Vector3(dirX * speed, rb.velocity.y, dirZ * speed) ;
    }
}
#

(i dont have a jump button or anything)

summer stump
#

Ok, so the issue might be that when you go up a slope, it gives you a bit of y velocity. Then you keep setting it to that given y velocity for a little bit after you stop. You probably need a ground check to tell when you're on a slope and set it to a negative y velocity until on flat ground.

The falling thing may be a friction issue? Does it happen if you don't fall AGAINST the wall, but fall from midair?

merry spade
summer stump
#

It's gonna get complex haha

merry spade
#

but why is that complex xD i just want to make something simple

wintry quarry
wintry quarry
#

to make something that seems simple to a user is often quite complex behind the scenes

merry spade
#

yeah but i see all those yters that say "yeah im going to do a simple prototype" then the cut 10min after and have a simple movement script camera script and a pathfinding thing that tries to attack the player

#

doesnt sound complex thing

summer stump
#

Youtubers lie

merry spade
#

but i just want to do a "simple prototype" xD

summer stump
#

Also pathfinding isn't a character controller

summer stump
merry spade
#

will it fix all of those errors?

#

problems*

summer stump
#

But it miiight be more conceptually easy? I dunno

#

I use velocity and addforce

merry spade
#

man roblox programming was simpler... xD

wintry quarry
#

Roblox holds your hand

summer stump
wintry quarry
#

Unity is a real game engine

#

with unlimited possibilities

#

with those unlimited possibilities comes complexity and having to deal with the ugly intricacies of things

merry spade
#

but where do i start?

summer stump
#

You can find assets on the store if you want (including free ones).
A popular one is the kinematic character controller

wintry quarry
#

If you want, there are plenty of off-the-shelf character controllers with lots of things handled already

#

Yes KCC for example^

merry spade
#

no i dont want to copy paste things i want to do it myself and learn it

wintry quarry
#

do tutorials then

merry spade
#

na

#

i will forget everything after an hour

wintry quarry
#

but realize that straying off the specific thing the tutorial is doing is going to often be difficult

#

the ability to actually do things on your own comes from lots of experience

#

you need to do the stupid simple things first so that the way the engine works starts to click in your brain, then you can start innovating on your own

polar acorn
#

Then again and you keep it for four

#

and so on until you don't forget it

merry spade
#

from where should i get the motivation to do this?

#

is it easier to start with 2d or is 2d and 3d completly different and 2d knowledge will give me no advantage in 3d?

wintry quarry
summer stump
#

2d is 3d in unity to some extents. A lot is transferable

wintry quarry
#

How badly do you want to learn Unity?

#

If it's not that badly, then maybe pick another hobby.

merry spade
#

did you start with 2d or 3d?

#

@wintry quarry

wintry quarry
#

I don't remember

#

it was 12+ years ago

merry spade
#

what do you suggest me

wintry quarry
#

It doesn't matter

#

either one

#

whatever piques your interest

merry spade
ashen ferry
#

4d

merry spade
#

is it better to do 2.5d in 3d or in 2d?

wintry quarry
#

Ultimately that is just a distinction of camera angles and renderer types

#

the rest of Unity is still Unity

#

you will learn Unity either way

wintry quarry
#

just a camera angle

merry spade
#

what would you do

wintry quarry
#

wdym

merry spade
#

would you do such a project with 2d or 3d

wintry quarry
#

there is no difference

merry spade
#

what would you click in the menu

wintry quarry
#

you're talking about project templates

#

all those do is give you a set of starting packages and camera settings in the scene

#

If you want 2.5d that's basically just a 3d game

#

where the character can only move on one plane

#

Either template can get you there

merry spade
#

ok

#

one last question#

#

what is with all of your names is that a sect?

weak plaza
summer stump
merry spade
#

a religious group xD idk

summer stump
#

Ohhh praetor? That is actually a government official haha. But it's just a name, I assume. Unless they are from ancient rome? Who knows

merry spade
polar acorn
merry spade
#

lets just forget what happened

summer stump
# merry spade what are you talking about haha

I don't understand how it wasn't clear. The word praetor is an elected official. It is still used but the first definition is:
"An annually elected magistrate of the ancient Roman Republic, ranking below but having approximately the same functions as a consul"

#

So I made a joke lol

merry spade
#

to much iq for me

#

just wanted to know why your name is only a letter

polar acorn
#

...?

merry spade
#

im german i cant understand english jokes

summer stump
ashen ferry
#

bro gotta take a nap

merry spade
#

all of you

summer stump
polar acorn
merry spade
#

wait what

summer stump
#

That is... multiple letters

polar acorn
#

Are you in streamer mode in discord

merry spade
#

oh i had obs open

#

Ahhh

#

oups

#

ok

#

nevermind

summer stump
#

Ah, so my joke was even more confusing. The guy you were talking to is named PraetorBlue lmfao

merry spade
#

hahaha

#

now i undestand

north kiln
#

Next time you see something weird in the discord, probably keep it to yourself

merry spade
#

i think i should do haha

summer stump
swift crag
north kiln
#

Please stop notlikethis

polar acorn
#

Yeah we're off topic

summer stump
#

Apologies. Will do. Should have known better haha

merry spade
#

back to the topic of helping me 🙂 with what do i have to replace the 0 in the move y direction when im using character controller

#

because right now the gravity isnt working

polar acorn
#

For a Character Controller you need to handle gravity yourself

summer stump
#

A negative value when appropriate

swift crag
#

SimpleMove automatically handles gravity for you, which is an option.

#

It takes a velocity, not a distance

#

it just adds to your old Y velocity and includes that in the move

#

Otherwise, you'll want to take your old Y velocity, add Time.deltaTime times the gravity strength, and then include that in the move vector

uncut dune
#

best way to add 2 weapon stats variables together, floats get added, booleans turn into the one that is being added and rest stays the same

wintry quarry
#

perhaps even think about overloading the + operator

uncut dune
uncut dune
wintry quarry
#

this is how Unity makes it so you can do cs Vector3 a = Vector3.one; Vector3 b = Vector3.one; Vector3 c = a + b;

#

they overloaded the + operator

#

you can do the same thing for your own custom classes

wintry quarry
#

Each one of them is one simple exmaple:

#
public static Fraction operator -(Fraction a, Fraction b)
        => a + (-b);```
#

this is a complete example

#

This is also a complete example:

    public static Fraction operator /(Fraction a, Fraction b)
    {
        if (b.num == 0)
        {
            throw new DivideByZeroException();
        }
        return new Fraction(a.num * b.den, a.den * b.num);
    }```
uncut dune
#

so in my case

#

what does it even mean to overload an operator?

#

does it mean it can now work in different use cases?

polar acorn
#

Like, instead of "addition", you can make + mean "Run this function"

wintry quarry
#

normally if you did cs public class Example {}
You can't just write:

Example a = new();
Example b = new();
var result = a + b;```
#

That will be a compile error because it has no idea what Example + Example even means

#

by overriding the operator you are telling it how to do Example + Example

#

so it will let you write that code

uncut dune
#

like a foreach does to a list

wintry quarry
#

if you want to do that you could/should put these stats into a collection of some kind

#

For reasons like that, I often find that a better structure than:

class Stats {
  int hp;
  int armor;
}```
Is something like:
```cs
enum StatType {
  HP,
  Armor
}

class Stat {
  StatType type;
  int value;
}

class Stats {
  Dictionary<StatType, Stat> stats;
}```
#

Then you can do something like:

Stats AddStats(Stats a, Stats b) {
  DIctionary<StatTye, Stat> result = new();
  foreach (StatType st in allStatTypes) {
     result[st] = new Stat() { type = st, value = a.stats[st] + b.stats[st] };
  }

  return new Stats() { stats = result; };
}```
#

just as a quick dirty, non compiling example

#

otherwise - you're stuck manually adding everything

#

which is really not the worst thing in the world

#

you only need to write it once

#

and then just update it whenever stats fields change

uncut dune
#

thats true

#

maybe I'll go with that since its the simplest and less complicated way

#

also it is way more optimized

smoky vault
#

So the function GetDownloadHandlerAsync does yield return on the first Function provided. I'm getting errors saying I cannot call yield in these functions, would calling return in an IEnumerator function being ran as a coroutine give the same result as calling yield return or do I need to change my approach?

wintry quarry
#

In general you cannot mix yield return with regular return statements in the same method if that's what you're asking?

smoky vault
wintry quarry
#

Another option in this context if it's a coroutine is to just yield return theOtherCoroutine;

#

which is what you're doing now but you said you're getting some kind of error?

smoky vault
#

It was an error telling me I can't put yield in an anonymous/lambda method

wintry quarry
#

You'd have to show the exact code and the exact error

smoky vault
#

nvm, just found an alternative way of doing it

#

but I can try and replicate the error again one sec

tender stag
tender stag
smoky vault
sharp oracle
#

Hello I have this small code the goal of it is just to add x rectangle gameobject to a list of rectangle when I print the len of the list it show me the right result but when I print the content of it it seems to have "null" value I don't know why (I have the rest of the code but it's not usefull for that problem)```csharp
using System.Collections.Generic;
using UnityEngine;

public class EntitySpawner : MonoBehaviour
{
private GameObject spawnedEntity;
private GameObject spawnedEntity2;
private List<GameObject> weaponsListDown = new List<GameObject>(); // Liste pour stocker les armes des anciens ennemies
private List<GameObject> weaponsList = new List<GameObject>(); // Liste pour stocker les armes
private List<int> weaponstypeList = new List<int>(); // Liste pour stocker les armes
private float spawnRange = 5.0f;
private bool entitySpawned = false;
private int life = 100;
float WeaponType = 2;

private void Awake()
{
    for (int i = 0; i < 3; i++)
    {
        WeaponType = UnityEngine.Random.Range(1, 3);

        if (WeaponType == 1)
        {
            weaponsList.Add(spawnedEntity2);
            weaponstypeList.Add(1);
        }
        else
        {
            weaponsList.Add(spawnedEntity2);
            weaponstypeList.Add(2);
        }
    }

    UnityEngine.Debug.Log($"w {string.Join(", ", weaponsList)} {weaponsList.Count}");
}

}

short hazel
tender stag
#

its because i destory it here

#

but i run the loop before that

short hazel
#

Either inputCell or cell or item is null. Basically everything on the targeted line that appears before a . could be null, find out what it is

#

You circled two lines and didn't include line numbers in that screenshot, so I'm taking the broader cases

tender stag
#

i just tested it, when i have more than 1 item in the inputCell

#

it works

#

because you arent destroying it

#

but if its one item in the input cell

#

i get the error

short hazel
#

So it's on line 123 as the stack trace mentioned (did you read my message about how to read a stack trace???), not where you circled the code

#

Anything that is followed by a dot . on that line could be null, you need to do some debugging

tender stag
# short hazel So it's on line 123 as the stack trace mentioned (did you read my message about ...
private void HandleAssembly()
{
    foreach(FurnaceCells inputCell in inputCells)
    {
        if(inputCell.processTime == 0 && inputCell.isProcessing)
        {
            inputCell.isProcessing = false;
            inputCell.processTime = 0;

            //inputBar.fillAmount = 0;

            foreach(ProcessOutcomes outcome in inputCell.cell.item.GetProcess(ProcessTypes.ProcessType.Smelt).processOutcomes)
            {
                Item newItem = InventoryManager.Instance.Spawn(outcome.item, outcome.amount);
                Add(newItem, newItem.amount);
            }

            if(inputCell.cell.item.amount > 1)
            {
                inputCell.cell.item.amount -= 1;
                inputCell.cell.Refresh();
            }
            else
            {
                Destroy(inputCell.cell.item.gameObject);
                inputCell.cell.Remove();
            }
        }
    }
}
#

this works

#

but i dont know why

short hazel
#

Did you find what's null?

#

Which variable

tender stag
#

i just moved the cs inputCell.isProcessing = false; inputCell.processTime = 0;

#

up

short hazel
#

You're not going to solve all future issues by moving code around randomly until it works

#

Learn how to debug things

#

There are guides pinned to this channel

tender stag
#

now its checking every inputCell there is, and if the input cell finished processing, then straight away set the isProcessing and processTime to false and 0, which will unable the rest of the code to run again

#

before since the isProcessing was being set to false at the bottom, the foreach was running a lot more times than it should

short hazel
#

Okay seems like you're not reading what I'm saying nor taking advice, I'm out, good luck with your issue

tender stag
solemn dagger
#

hey everyone I'm new to Unity and was working on a flappy bird type game using the Game Maker's Toolkit Unity tutorial and ran into this error, however I cannot find any problem with this code

solemn dagger
polar acorn
# solemn dagger

You are trying to get a component from an array of objects with that tag. Arrays don't have GetComponent, you'd need to tell it which one you want the component from

swift crag
#

GameObject[] means "An array of GameObject"

#

you can drink a can of soda, but you can't drink a 12-pack of soda

#

you can't drink the box

#

that would hurt

swift crag
#

slurp

#

The tutorial probably did not use FindGameObjectsWithTag

#

I'm pretty sure it only wants one LogicScript holder

#

not an arbitrary number of LogicScript holders

#

FindGameObjectWithTag returns a GameObject
FindGameObjectsWithTag returns a GameObject[]

solemn dagger
#

ok

solemn dagger
#

its all about trying out

swift crag
solemn dagger
swift crag
#

Right.

#

The original code got an array of game objects, then tried to treat that like it was a single game object

solemn dagger
#

so FindGameObjectsWithTag allows me to customise the number of game objects?

swift crag
#

It lets you get many game objects at once

#

This would make sense if you could have many objects with the same tag, and needed to do something to all of them

solemn dagger
solemn dagger
#

then findgameobjects would be used?

swift crag
#

Right.

solemn dagger
#

kk

#

thx for explaining

frigid quartz
#

Hey all, sooo I have these serialized variables, where I can drag and drop the images that I want to use for the appearance of my playing card objects. However, I'd like to be able to change this image from any card and have the change be reflected across every card. I think "static" is my solution but I've never really been able to wrap my head around it. Could anyone help me out?

short hazel
#

Change it in the Editor, or while the game runs?

frigid quartz
short hazel
#

Scriptable objects can do that

polar acorn
frigid quartz
frigid quartz
#

But yeah I think this was an obvious one I just missed. I'll just move the variables over to the SO and then reference them in the appearance script.

daring tundra
#

Does anyone know how you reduce the loading scene time? I'm trying to create a casual mobile game using only 2d and the delay is quite noticable

#

Do you use LoadSceneAsync for this?

tepid cove
#

i have this code to enable a ragdoll when hit with an object tagged "hit" but i dont know what line of code i put here to do that, i have the enable ragdoll code (bit more code above off screen) its just the code to eneable it when hit with an object with the "hit" tag

wintry quarry
wintry quarry
#

To detect physics collisions you use OnCollisionEnter/OnTriggerEnter depending on if you're using trigger colliders or not

tepid cove
# wintry quarry Wdym by "hit"? Like a physics collision?

yeah, i have a bullet object, and when it hits i want the model to ragdoll. the bullet has a tag called "hit" because i want to make other things be able to it like a throwable object. which i why i want to apply a tag to make it easier in the future.

wintry quarry
#

I don't think a tag is particularly helpful here

#

I would say just make EnableRagdoll public, then the bullet script can call that function when it hits the player

tepid cove
wintry quarry
#

or perhaps make a separate "Hit" function and call that (which then calls enableragdoll among other things)

wintry quarry
#

the bullet script would be calling it

wintry quarry
#

unless the floor has a bullet script for some reason

daring tundra
wintry quarry
#

Your scene may be too bloated, and potentially you are loading too much stuff up front

#

perhaps you have things referenced in the scene that are rarely used that would be better off loaded on demand for example

#

it's hard to say without seeing what's in your scene and what is referenced from it, etc.

#

for example maybe you have some kind of menu for choosing different player skins and you have all the skins directly referenced in a script. This will cause them all to be loaded up front

daring tundra
#

In total there are only active 19 objects in the hierarchy (including children)

#

active gameobjects

wintry quarry
#

sure but like I said any referenced assets are also loaded into memory

#

so number of gameobjects is only one part of the puzzle

daring tundra
#

so referencing a script increases load time as well?

wintry quarry
#

if it's a script on a prefab asset, sure

#

any asset you reference is loaded

#

this includes materials. meshes, audio clips, video clips, prefabs, etc

tepid cove
wintry quarry
tepid cove
tepid cove
wintry quarry
#

You get it as part of OnCollisionEnter

honest haven
#

i have a player and an enemy. each has a rigid body and a collider. the player has kenematic flase enemy is try. yet when they pass each other the enemy pushes the player out the way. i want them to just pass though each other and not take force. what do i need to do

sage lotus
#

can anyone help with how I can go about learning how to make other object follow one? like a trailer or even tail?

#

idk what to search for

sick python
#

Hello, i am brand new to unity and I have persisting issue across my projects and don't know what is going on

My camera is never showing my gameobjects in the game even thought it may in the preview

polar acorn
languid spire
honest haven
tender stag
#

i need to fill the bars for input and fuel cells, how do i do it? like make the bar on each cell fill over time (the amount of time it takes the fuel or input item to process)
https://hastebin.skyra.pw/ohosinesal.csharp

sage lotus
sick python
#

@polar acorn the camera is at z=-10 and my grid and player are both at z=0. doesn't that mean the objects are in front of the camera?

wintry quarry
tender stag
polar acorn
wintry quarry
tender stag
#

like it has to be in update

wintry quarry
#

yes

#

sure

#

Ideally you'd make a property so that when you set the fuel amount, it also updates the fill amount on the UI

queen adder
#

So i've trying to make a cube to change colour when ever interact with it using the change cube color code in the minute 21:25 of this video https://youtu.be/gPPGnpV1Y1c?si=pqwMiFlRkQ0oSGce but he said it needs some setting up to make it work properly but i tried alot of ways to set it up but all of them didn't work

The second video in the Lets Make a First Person Game series!
🖐In this video we are going to setup the foundations for our interaction system.

Come Join us on the Discord!
🎮 https://discord.gg/xgKpxhEyzZ

💚 Thanks for watching!

Helpful Links
https://dotnettutorials.net/lesson/template-method-design-pattern/

▶ Play video
wintry quarry
#

so now whenever you set FuelAmount it happens automatically

sage lotus
queen adder
sage lotus
#

I'll continue searching

ashen ferry
#

if you have train on some preset path like rails Im thinking sphere cast might be all you need 2 colliders at the "hands" where containers connect at and following container checks if it touches front one within distance if not slow/speed it up

queen adder
wintry quarry
#

that doesn't really help you figure out which code is running

#

you should have it print different things

queen adder
#

but which thing? 🙂

wintry quarry
#

anything you want

#

"Score is less than 10"

#

"Score is greater than or equal to 10"

#

that would be helpful

wintry quarry
#

a better way to ask the question would be to show the scene setup and code you tried and ask for help fixing it

queen adder
wintry quarry
ashen ferry
#

cant rly spot ur issue but u can change this int randomIndex = Random.Range(0, leftGroupPrefabs.Length); for (int i = 0; i < leftGroupPrefabs.Length; i++) { if (randomIndex == i) { Instantiate(leftGroupPrefabs[i], spawnGroupPos, Quaternion.identity); } } into this int randomIndex = Random.Range(0, leftGroupPrefabs.Length); Instantiate(leftGroupPrefabs[randomIndex], spawnGroupPos, Quaternion.identity);

queen adder
#

Just after 10, get 3 more score. Spawner stop works. Every game its same error

ashen ferry
#

what error

wintry quarry
# queen adder
                int[] randomNumber = { 1, 2, 3, 4 };
                int rN = Random.Range(0, randomNumber.Length);```
If you're expecting this to ever give you 4 as a result, you're mistaken
#

IDK what the point of the array is anyway

wintry quarry
#

Why not just:

int rN = Random.Range(1, 5); // will return a random number 1-4 inclusive``` and call it a day
sage lotus
wintry quarry
#

you can also just replace:

if (rN == 1 || rN == 2 || rN == 3)
// and
if (rN == 4)```
with:
```cs
if (rN < 4)
// and
else```
queen adder
# wintry quarry a better way to ask the question would be to show the scene setup and code you t...

this is the code: public class Keypad : Interactable
{
MeshRenderer mesh;
public Color[] colors;
public int colorindex;
// Start is called before the first frame update
void Start()
{
mesh = GetComponent<MeshRenderer>();
mesh.material.color = Color.red;
}

// this function is where we design the interaction
protected override void interact()
{
    colorindex++;
    if(colorindex > colors.Length - 1)
    {
        colorindex = 0;
    }

    mesh.material.color = colors[colorindex];
}

}

eternal falconBOT
#
Posting code

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

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

wintry quarry
wintry quarry
#

0 alpha on both of these

#

anyway how / where are you calling Interact()? Have you made sure Interact() is actually running by using Debug.Log?

queen adder
#

done it it done nothing

wintry quarry
#

done what

queen adder
wintry quarry
#

I didn't tell you to set them to zero

#

I'm asking why they are zero

#

that doesn't seem intentional

queen adder
#

yes

wintry quarry
queen adder
#

just for your knowledge the error is Null reference exception

ashen ferry
queen adder
wary delta
#

I'm having trouble finding attributes info in the docs, is there like a list somewhere? Maybe they aren't called attributes.. I'm referring to [Header("blah")], etc.

wintry quarry
wintry quarry
#

e.g. giving the full error message and indicating the line of code on which the error is happening

queen adder
wintry quarry
wintry quarry
wintry quarry
#

Notice it's telling you exactly where the error is @queen adder

queen adder
#

okay ill send it

#

this is it

#

@wintry quarry

short hazel
#

Please post this to a paste site

wintry quarry
eternal falconBOT
#
Posting code

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

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

short hazel
#

At least we'll get line numbers there

wintry quarry
#

this doesn't tell me what line 36 is

#

and it's horrible to read

queen adder
#

yeah yeah sorry fellas just please wait

sage lotus
queen adder
#

this is line 36 if(playerinput.Onfoot.Interact.triggered)

wintry quarry
#

ok then playerinput is null

#

without seeing the code, i'd guess you simply never initialized it

queen adder
#

how do i solve it?

wintry quarry
#

initialize it

wintry quarry
#

it's telling you you tried to use a null reference

queen adder
queen adder
wintry quarry
#

Hard to say without seeing the code but likely something like this

#
void Awake() {
  playerinput = new();
  playerinput.Enable();
}```
queen adder
wintry quarry
#

I wanted you to send the code 10 minutes ago.

queen adder
#

jus wait

wintry quarry
#

I probably don't really need it now

#

but it can't hurt

wintry quarry
queen adder
#

@wintry quarry Thank you, now works!

#

@wintry quarry here ya go

summer stump
eternal falconBOT
#
Posting code

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

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

short hazel
#

That makes three

summer stump
#

Please format it like the bot says

wintry quarry
queen adder
#

thx

#

ill try it

short hazel
#

Maybe they have their own PlayerInput, as per a very popular tutorial

wintry quarry
#

Yes. That is clear by this line playerinput.Onfoot.Interact.triggered

#

I hate that tutorial

#

it manages to confuse the ever loving shit out of beginners every time by naming things in the worst way possible

short hazel
#

In that case, it just means you just didn't attach that script aside Playerinteract on the same object

wintry quarry
#

it's not a script that can be attached

#

it's not a component

#

it's the generated C# wrapper class for their input action asset

short hazel
#

In that case GetComponent would have thrown an exception no?

wintry quarry
#

It probably is throwing an exception

swift crag
#

it is always useful to look for the first error

#

not just the error you're getting 400 copies of

#

the first error is often responsible for the rest

#

turning on "Collapse" can help with this.

queen adder
wintry quarry
queen adder
swift crag
#

Send us your entire script. Send it via a paste site. Follow the instructions.

#

!code

eternal falconBOT
#
Posting code

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

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

summer stump
#

And I guess that is FOUR times the bot was sent? Lol

swift crag
#

Do not paste your code into the chat. Do not drag a file into Discord. Do not show us a single line of code. Share the entire thing with a paste site.

#

If you don't know how to do that, ask us.

swift crag
wintry quarry
#

My guess is private Playerui playerui; is null now

eternal falconBOT
#
Posting code

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

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

ashen ferry
short hazel
#

FIVE!

tawdry rock
#

Is anything wrong with this code snippet? I have a sphere on the player set to trigger, i also refferenced the sphere collider. If a gameobject that has a tag "Enemy" + it has AIExample script on it, then it should call the OnAware function on that gameobject enemy, no? If i debug it it only runs twice on the false branch and thats it.

 public void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.CompareTag("Enemy"))
     {
         other.GetComponent<AIExample>().OnAware();
     }
     
 }
wintry quarry
eternal falconBOT
#
Posting code

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

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

summer stump
# queen adder ok

Click the link in the bot. Copy your code into that website. Click save. Copy the url. Past THE LINK here

polar acorn
#

SIX! SIX BOT POSTS! AH AH AH!

wintry quarry
#

void start() You spelled Start wrong

summer stump
#

Do not type ! code

timber tide
#

Oh is the bot automated now to detect blocks of text

#

awesome

polar acorn
summer stump
tawdry rock
wintry quarry
#

no idea how you managed to have Start spelled correctly the first time and now you wrote start

queen adder
polar acorn
eternal falconBOT
#
Posting code

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

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

timber tide
#

oh lmao

summer stump
#

Stop. Typing. ! Code

queen adder
#

like this?

summer stump
ivory bobcat
wintry quarry
summer stump
#

You have to click save

short hazel
polar acorn
queen adder
summer stump
ivory bobcat
#

Sometimes hatebin refuses to provide a link on save (browser extension block etc), if so try one of the other ones.

polar acorn
#

hatebin sometimes just doesn't generate a URL and we really should have removed it from the bot years ago

polar acorn
#

and for some reason everyone clicks that one first despite it not being the first

polar acorn
swift crag
#

it is nicely centered

#

it sticks out

short hazel
#

It has "hate" in it

ivory bobcat
#

It was popular several years ago

queen adder
polar acorn
queen adder
#

finally

polar acorn
tawdry rock
queen adder
#

welp yes now i added it ill try

#

tried and nothing happend

#

welp thx to anyone who helped and sorry for being a pain in the ass but i am a beginner so yeah oc i would like that imma go get some sleep

#

and if you have a soultion leave it here ill read it when i get up

#

goodbye and good night or morning

polar acorn
tawdry rock
#

hmm.. new problem now. if the enemy gets aware it should move to the fpscontroller position (player pos):
if (isAware == true) { agent.SetDestination(fpsc.transform.position); }

however if i walk into the enemy i can push it and the awareness gets broken. this if is inside a update method. (when it didnt had rigidbody i couldnt push it, the enemy could push me btw)

polar acorn
tawdry rock
swift crag
#

well, why not go from "you think" to "you know"?

#

I'd be logging inside that if statement, at the very least

#

to see if it's running

tender stag
#

how do i make the fill amount go all the way to 1, and once its at one to lerp to the process time?cs foreach(FurnaceInputCells inputCell in inputCells) { if(inputCell.isProcessing) { float targetFillAmount = inputCell.processTime / inputCell.cell.item.GetProcess(ProcessTypes.ProcessType.Smelt).processTime; inputCell.bar.fillAmount = Mathf.Lerp(inputCell.bar.fillAmount, targetFillAmount, Time.deltaTime * 10); } else if(inputCell.bar.fillAmount > 0) { inputCell.bar.fillAmount = Mathf.Lerp(inputCell.bar.fillAmount, 0f, Time.deltaTime * 10); } }

#

you can see in the video it lerps to the process time straight away

#

and there is a little gap, it doesnt fill all the way up

polar acorn
tender stag
#

how else do i do it then

polar acorn
#

Enter your start and end values, then increase the t parameter of the lerp from 0 to 1 over however long you want it to be

tender stag
#

but i stop it at some point

#

like when i remove the item from the input cell

polar acorn
#

Then you could stop the coroutine

tender stag
tender stag
ashen ferry
#

not filling all the way up is how its supposed to work while ur filling it back up processing is already going on

ashen ferry
#

I would set fill to 1 upon inputing item for that start

#

so why u mention it

polar acorn
tender stag
tender stag
#

because i dont want the gap

#

i know what the problem is

#

i dont know how to fix it

ashen ferry
#

so set fill to max instantly when it ends or stop processing until it fills back if u want to keep animation. Or dont tie processing progress to lerping progress maybe get time needed from the item and use that to create a lerp

sharp oracle
#

Hello I have this small code the goal of it is just to add x rectangle gameobject to a list of rectangle when I print the len of the list it show me the right result but when I print the content of it it seems to have "null" value I don't know why (I have the rest of the code but it's not usefull for that problem) ```csharp
using System.Collections.Generic;
using UnityEngine;

public class EntitySpawner : MonoBehaviour
{
private GameObject spawnedEntity;
private GameObject spawnedEntity2;
private List<GameObject> weaponsListDown = new List<GameObject>(); // Liste pour stocker les armes des anciens ennemies
private List<GameObject> weaponsList = new List<GameObject>(); // Liste pour stocker les armes
private List<int> weaponstypeList = new List<int>(); // Liste pour stocker les armes
private float spawnRange = 5.0f;
private bool entitySpawned = false;
private int life = 100;
float WeaponType = 2;

private void Awake()
{
    for (int i = 0; i < 3; i++)
    {
        WeaponType = UnityEngine.Random.Range(1, 3);

        if (WeaponType == 1)
        {
            weaponsList.Add(spawnedEntity2);
            weaponstypeList.Add(1);
        }
        else
        {
            weaponsList.Add(spawnedEntity2);
            weaponstypeList.Add(2);
        }
    }

    UnityEngine.Debug.Log($"w {string.Join(", ", weaponsList)} {weaponsList.Count}");
}

}```

polar acorn
#

Where do you set spawnedEntity2?

sharp oracle
#

I don't really do it

polar acorn
sharp oracle
#

I set swpanedentity like that ```csharp
spawnedEntity = Instantiate(entityPrefab, randomPosition, Quaternion.identity);

#

should I do the same ?

#

let me share the whole could would be easier for you to understand

#

here it is

polar acorn
#

What do you want to add to the list

sharp oracle
#

rectangle

#

those one

polar acorn
#

Okay and where do you reference rectangle

sharp oracle
#

it's not really rectangle more cylender

#

*cylinder

polar acorn
#

Okay where do you reference cylender

sharp oracle
#

well I create my "main" cylinder like that ```csharp
private GameObject spawnedEntity;
// code code code
randomPosition = new Vector3(100, 0, 0);

        spawnedEntity = Instantiate(entityPrefab, randomPosition, Quaternion.identity);

// code code```

#

but those 3 "line" basicly create generate position and display it

polar acorn
sharp oracle
#

it's fine for me

polar acorn
sharp oracle
#

like I add it when I press P ?

polar acorn
#

If that's when you want it to go into the list, sure

sharp oracle
#

ok let me try it and tell you the outcome

#

wait what is the goal of my awake function then ?

polar acorn
#

That's something you should know

sharp oracle
#

yeah I know dumb question

#

it worked well thanks

#

now I have another problem how can either hide my rectangle with pressing keynum9 and make it apear again when I press P or delete it when I press keynum9 and make a new one when I press P ?

#

Let me share the lastest code I have

#

For the moment when I press key9 it dissapear well but when I press P again it don't reapear/create new one

wintry quarry
#

all these if statements in a giant Update function are confusing/convoluted

sharp oracle
sharp oracle
sharp oracle
#

thanks

#

I just found a solution which isn't well coded at all but for what I have to do it's fine I just change the position to like 9999 on x y and z when I press 9

#

I know I should do better code but the problem is I don't have enough time for that right now

latent star
#

hi hi!
I'm currently working on a minigame and well I found a bug that you could still destroy objects even tho the time was over. Since the Spawn script and the ScoreSystem are two different scripts I've been trying to get a bool from the spawn script to my ScoreSystem. But when I tested it all I was left with the error

NullReferenceException: Object reference not set to an instance of an object

        script1Reference = GetComponent<SpawnObjects>();
        bool myBoolValue = script1Reference.SpawnIsActive();
        Debug.Log(myBoolValue);

this is what I'm doing to get the bool from my spawner script. Anyone has any ideas on it?

wintry quarry
#
[SerializeField] SpawnObjects objectSpawner;```
The simple approach is to declare a field like this and assign it in the inspector via drag & drop. Then you can use `objectSpawner` as much as you want.
rocky rock
#

how can I access the file text of a file assigned to a UnityEngine.Object field..?

wintry quarry
#

Use TextAsset

#
[SerializeField] TextAsset myTextAsset;``` then you access the text via `myTextAset.text`
latent star
rocky rock
steep rose
#

so i have this raycast suspension script but theres only 1 problem, the raycast suspension has no friction. how would i add forward/sideways friction so i can go on sloped objects and not slide down it? heres the script https://hatebin.com/tklieorceg

wintry quarry
#

so you'd essentially calculate that perpendicular direction (using the surface normal from the raycast), and apply a friction force in the opposite direction of motion

#

you can basically project the rigidbody velocity on the plane defined by the surface normal and do AddForce in the opposite direction as that projection

steep rose
wintry quarry
swift crag
#

Vector3.Project will give you the part of a vector that aligns with a second vector

#

Vector3.ProjectOnPlane will give you the part that doesn't

wary sable
wary sable
#

are you able to use collection literals with unity?

calm coral
wary sable
#

seems to be

swift crag
#

yes, so you can't use anything from C#10 onwards

faint osprey
#

ok so i have a raycast coming out of a vehicle and when the vehicle crashes it executes a function but how would i make it so that if the object that the raycast is coming from crashes into something with the same tag as it it doesnt execute that code

summer stump
swift crag
#

just check if the hit object's tag equals your own tag

#

or call CompareTag with the other object's tag, I guess

faint osprey
#

let me try that

#

that didnt work

#

else if (hit.collider.tag == "winter" && dS.winterIslandConnected == false && hit.collider.tag == gameObject.tag)

#

its the last condition

calm coral
#

gameObject but which game object has this script attached?

faint osprey
#
                {
                    foreach (Light L in Lights)
                    {
                        L.color = Color.green;
                    }
                    gameManager.BroadcastMessage("AutumnConnect");
                }
                else if (hit.collider.tag == "desert" && dS.desertIslandConnected == false && hit.collider.tag == gameObject.tag)
                {
                    gameManager.BroadcastMessage("desertConnect");
                    foreach (Light L in Lights)
                    {
                        L.color = Color.green;
                    }
                }
                else if (hit.collider.tag == "winter" && dS.winterIslandConnected == false && hit.collider.tag == gameObject.tag)
                {
                    gameManager.BroadcastMessage("winterConnect");
                    foreach (Light L in Lights)
                    {
                        L.color = Color.green;
                    }
                }``` it doesnt really matter about the other if statement but here u go anyway
#

its just the hit.collider.tag == gameObject.tag that needs fixing

calm coral
faint osprey
#

the one with the ray cast coming out of it

summer stump
#

Does the gameobject with that script have thr Autumn tag?

summer stump
#

Why the double check. If it does, then why check it explicitly AND via gameObject.tag?

calm coral
faint osprey
summer stump
# faint osprey wdym

You did:
hit.collider.tag == "Autumn"

And
hit.collider.tag == gameObject.tag

But if gameObject.tag is Autumn, those are the same

calm coral
faint osprey
#

omg im an idiot its gotta be hit.collider.tag != gameObject.tag;

summer stump
faint osprey
#

yeah it needed to be != instead of == at the end

summer stump
faint osprey
#
    {
        aTubePos = aTube.transform;
    }``` im calling this statement on start however when aTube gets destroyed later on in the scene im getting the transform ur trying to access no longer exists message
#

however havent i already got the transform data cause i did it at start?

shell sorrel
#

the transform is a reference type

#

aTubePos = aTube.transform; just makes aTubePos point to the same transform as is on aTube

faint osprey
#

yeah

shell sorrel
#

now do you care about the whole transform, or just the position?

#

since if just the position would store just that as a vector3

faint osprey
#

oh right

wary sable
#

Hello, for part of my inventory system I found that it would be helpful to be able to select the type of item (class) from a scriptable object. Is there a way to have a dropdown menu of types in the inspector of an S.O.?

shell sorrel
#

and what are you going to do with that type once selected?

#

you can easily build a popup menu and populate it with what ever you want, and can use the TypeCache or C#'s reflection features to get a list of types

#

but none of it really matters unless you know how you are going to use it

calm coral
# faint osprey oh right

Keep in mind you're running that inside Start method, so you'll get only the starting position, if you want to keep aTubePos updated as long as the game object exists you probably should put that in Update() pepeThink

faint osprey
calm coral
shell sorrel
#

then update the position each frame in update

#

or just hold reference to the transform and use it when you need to get position

#

though would null check it first each time

wary sable
timber tide
#

Depends what data you want shown depending on the enum type

#

if it's all non-unique such it derives from another class, that's easily doable

#

but if you want to show/hide variables depending on the type selected, you need custom editor/attributes

faint osprey
#

im using a list to store GameObjects and im getting no errors in visual studio only in the editor which says 'aTubeHandler' does not contain a definition for 'instanObj' and no accessible extension method 'instanObj' accepting a first argument of type 'aTubeHandler' could be found (are you missing a using directive or an assembly reference?). any ideas?

shell sorrel
faint osprey
#

it is public and it does contain it tho

shell sorrel
#

then you would have to show the problem and the related code

wary sable
# wary sable I had an idea, and after fully typing it out I just realized that it was a reall...

Basically I had a generic method for adding to an inventory that comprised of different lists (this sorted items by type when passed through). Each item has a reference to its own scriptable object which defines things like id, name, icon and description. I needed to pass something into the method to check type against, and thought that since the scriptable object was the item being added to inventory lists that it would make sense that it also contained type data. When in reality I can just pass in the item class (which already has a reference to the SO) and can be checked against.

shell sorrel
#

assumeing its a case where all items are extending from one type so they can be stored in 1 list, and you just need to figure out which spefecic one it is

wary sable
#

assuming this actually works

faint osprey
#

does foreach work with a list?

wary sable
#

yes

shell sorrel
#

yes

#

foreach (var item in list) { ...

faint osprey
#
            {
                Destroy(G);
            }``` im getting problems with this then the objects arent being destroyed
wary sable
#

for each works with any iterable (if thats a word?)

shell sorrel
faint osprey
shell sorrel
#

no

wary sable
#

your code would finish running before the end of the frame

shell sorrel
#

1000 objects would get destroyed at the end of that frame

faint osprey
#

oh well thats not happening

shell sorrel
#

well add some logging

#

make sure G is actaully what you think it is

faint osprey
#

there getting destroyed in the list but not in the game?

#

idk how

#

wait let me explain that better

#

i have a public list on the script

#

and when i look at the list in the editor all the objects get destroyed

#

however there still there visible in the scene

shell sorrel
#

like i said confirm the objects in the list are the same ones in the scene that stay behind

#

what type is your list?

faint osprey
shell sorrel
#

like is it a List<GameObject>

faint osprey
#

yeah

shell sorrel
#

or list of some other script type?

faint osprey
shell sorrel
#

i think you are creating more objects then you added to the list

wary sable
#

are the objects in the game the objects in your list?

faint osprey
shell sorrel
#

like i would not be supprised the ones in your list are not the objects in the scene

#

but are your prefabs

faint osprey
#

instanObj.Add(Instantiate(genTube, cylinder.transform.position, cylinder.transform.rotation));

#

thats how im adding the objects to the list

shell sorrel
#

then like i said before adding logging and confirm you are destroying the objects you think you are

#

and that all the objects you want to destroy in the scene are in the list

faint osprey
#

there definitly the ones in the scene

shell sorrel
#

try DestroyImmediate as a test?

faint osprey
#

oki

#

that didnt work

shell sorrel
#

you are going to need to do some debugging or show the code then

twilit trail
#

I'm trying to disable my starting camera and audio listener when i spawn in a new one as part of my multiplayer player prefab. here's my code:

        var camera = GetComponentInChildren<Camera>();
        camera.enabled = true;
        camera.gameObject.GetComponent<AudioListener>().enabled = true;
        Camera.main.gameObject.GetComponent<AudioListener>().enabled = false;
        Camera.main.enabled = false;```

neither component is getting unchecked in the editor and i get log errors about two audio listeners. what am i doing wrong?
north kiln
#

Are there other errors, and have you established that this code is running?
Because this camera is not tagged as MainCamera so Camera.main will not find it.

twilit trail
#

oh I thought Camera.main just grabbed the active camera and at the time the scene starts its the only one

shell sorrel
#

its just grabs the ones with the tag

#

if multiple have the tag its not reliable which you get

faint osprey
#

just to double check application.quit() wont do anything when ur in the editor right

wary sable
#

What would be the best way to check the type of item in this scenario? (where armor, weapons and genericInventory are each List<ItemSo> -- ItemSO being a type and not the var seen in the method)
Whats shown here doesnt work; but I feel its on the right path.

        if(item.GetType() == typeof(Armor)) {
            armor.Add(item.ItemSO);
        }
        else if (item.GetType() == typeof(Weapon)) {
            weapons.Add(item.ItemSO);
        }
        else {
            genericInventory.Add(item.ItemSO);
        }
    }```
for reference, this is my class structure: