#💻┃code-beginner

1 messages · Page 363 of 1

upper forge
#

from the scene

summer stump
#

You spawn the prefab, not a scene instance

summer stump
upper forge
summer stump
graceful crescent
#

Have you attatched any scripts in the prefabs that makes them disappear?

summer stump
#

Again, prefabs are NOT IN THE SCENE

upper forge
summer stump
#

They are not in the hierarchy

#

They are in the project window

#

Show the thing you are spawning with a screenshot

upper forge
#

GameObject newBalloon = Instantiate(balloonPrefab, spawnPosition, Quaternion.identity); takes me to this line of code when i click the error

summer stump
#

Yes. Show me the thing you dragged into balloonPrefab

#

You likely dragged a scene object, NOT the prefab

upper forge
summer stump
#

Ok, that IS the prefab. Well, then are you calling Destroy(balloonPrefab) anywhere?

#

Can you show the actual error as a screenshot

upper forge
#

uhh, it randomly started working again?

summer stump
#

Well alright then. Haha. Good luck then

upper forge
graceful crescent
summer stump
#

Yeah. If something didn't compile, a restart would force that.
Ctrl+r also does a recompile too

graceful crescent
#

Ohh a recompile

#

Anyways thanks y'alls
Imma go sleep now gn

upper forge
#

very sorry lol, how would i make the balloons gravity increase over time, so it goes up faster

willow scroll
wicked flare
#

is there any difference in coding with VS and VS code? like for a beginner which one would be easier to grasp? (i know its the same code, i mean maybe the themes and shit like that might help)

willow scroll
wicked flare
willow scroll
#

I suppose, the majority would consider it much more comfortable

#

Also VS Code is not an IDE

brave robin
#

I don't use the vast majority of features in VS, but found it easy enough to pick up and work in, as the integration is very good and you don't need to do anything other than Save All and jump back to Unity to test 99% of the time

compact nymph
#

why is it saying hit is wrong in the getcomponet?

brave robin
#

mouse over it to get the reason why, it's probably because hit is unassigned

polar acorn
brave robin
#

you're missing a method that populates hit with data

polar acorn
#

you never give it a value

brave robin
astral bridge
#

Yo, can anyone help me brainstorm this please, I am making a hide and seek game where you can choose to be the hider or the seeker, the seeker can only see other players if they are in his fov, I am doing this using the URD (universal renderer data) by modifying the opaque and transparent layers and using the stencil effect.
Now for the question, how can I switch to be a hider and remove all the effects (because these are specific to the seeker). As of right know when I choose hider, I cannot see myself nor other hiders

languid spire
#

right.
A) This is a code channel and this does not sound like a code question
B) Read what you have written and think if you knew nothing about your situation. Would you understand one single word you have written?

brazen canyon
#

hey guys, I need a little help.
How to draw a class diagram for my game ?

brazen canyon
brave robin
#

There's a Class Designer tool in VS, but that's outside the scope of this channel, and I've never used it

brazen canyon
brave robin
tiny plaza
#

hey is it possible to activate the method of another game object on collision?

timber tide
#

very much possible

willow scroll
timber tide
#

check the collision methods or trigger methods (if you're not using rigidbodies)

tiny plaza
willow scroll
tiny plaza
slender nymph
#

it's not public

tiny plaza
#

i completely forgot lol

tiny plaza
rich adder
runic holly
#

I'm quite confused, what shoul i do?

slender nymph
#

start by configuring your !IDE 👇

eternal falconBOT
runic holly
#

i installed it via Unity already..

#

it's not working as i want

wintry quarry
polar acorn
upper forge
#

I found a bug, where, when i click out of the screen, the game pauses, and it makes it much easier for the player to win this way as they can easily keep pausing the clicking on the balloon, how can i make it so that the game carries on no matter what

ruby thistle
#

Problem: My Player is moving with the same Speed when i press "W" or "W" and "D" when i am touching a wall and pressing "W" and "D" at the same time i am moving to the right but with a slower speed (can someone help) ?

swift crag
#

let me find it

upper forge
wintry quarry
runic holly
#

not sure about getting errors while setting it up

swift crag
#

I believe you want to turn on "Run in Background"

upper forge
ruby thistle
upper forge
ruby thistle
wintry quarry
ruby thistle
upper forge
#

well, its going to be slower, if youre moving diagonally to a wall

wintry quarry
#

You'd have to project your motion vector on the surface normal of the wall, subtract that projection from your motion, calculate the magnitude of the removed bit and add it back to the projected vector

swift crag
#

So you want to move at full speed, even though your movement vector is pointing into a wall?

ruby thistle
wintry quarry
upper forge
#

anyone know how i can decrease gravity as time goes on for my sprite?

wintry quarry
upper forge
wintry quarry
#

You would write code that decreases the gravity scale as time goes on

#

The exact nature of that code depends heavily on how you want that to work

upper forge
#

need to take track of the time thats been played and when it reaches a certain time the gravity decreases. Thats what i want it to do

#

or just gradually decreases

wintry quarry
#

Tracking time is simple. Just use Time.time or make a timer yourself with float and Time.deltaTime

ruby thistle
swift crag
#

you get rid of the first part

#

then you increase the length of the second part to compensate

#

If you were moving at 2m/s into the wall and 4m/s along the wall, you want to throw out the first half

#

and then move 6m/s along the wall instead

lethal apex
#

can anyone help me with the grid thing in unity please?

polar acorn
lethal apex
#

oh ok

#

but yeee i figured it out tysm

lethal apex
swift crag
#

if your problem isn't a code problem, then ask it in another channel

lethal apex
#

ok

queen adder
#

is there a way i could make it so its like when im holding a button down something is consinstently happening

viral shadow
swift crag
#

read the documentation to find out!

viral shadow
queen wren
#

For some reason this won't work, any idea?
worldSpaceCanvas.worldCamera = Camera.main;

slender nymph
#

what isn't working about that? is the worldCamera property still null after that line runs?

queen wren
#

yes, the canvas won't take the camera, I also place it in Update but still won't work

#

Unity 2022.3.30

slender nymph
#

are you certain that code is running? do you have a camera in your scene tagged as the MainCamera?

queen wren
#

This code is running on the same gameobject of the Canvas

{
    private Canvas worldSpaceCanvas;

    // Start is called before the first frame update
    void Start()
    {
        worldSpaceCanvas = GetComponent<Canvas>();

        if (worldSpaceCanvas = null ) 
        {
            Debug.LogError("AssignMainCameraToCanvasWS component on " + gameObject.transform.root.name + " requires a Canvas on the same object!");
        }

        worldSpaceCanvas.renderMode = RenderMode.WorldSpace;
        worldSpaceCanvas.worldCamera = Camera.main;
    }
}```
slender nymph
#

the fact that you have this line GameObject.FindGameObjectWithTag("GuiCamera") and are (allegedly) not receiving an exception that would prevent the latter lines from running indicates that your camera is not tagged as MainCamera

queen wren
#

🤔 I didn't check that! 😅
Let me see

#

it's not tagged 🤦‍♂️

#

😅

queen adder
#

so is it possible i could make it so inside an if statement when on collision with a specific object it stops being held

polar acorn
queen adder
#

okay so how i would do that

eternal needle
#

inside an if statement apparently

polar acorn
eternal needle
#

try to be more descriptive, and show relevant code with code questions. This is so vague it cannot be answered. What does it mean to be "held" in your game?

queen adder
#

when being held the object is at the position where the mouse is

#

!code

eternal falconBOT
queen adder
#
   if (holding)
        {


                Rigidbody2D rb2d = heldObject.transform.GetComponent<Rigidbody2D>();


            if (Input.GetMouseButton(0))
            {

                if (rb2d != null) heldObject.transform.position = mousePos;
                if (rb2d != null) rb2d.AddForce((mousePos - heldObject.position) * 6f);
                if (rb2d != null) rb2d.velocity = ((mousePos - heldObject.position) * heldObject.transform.GetComponent<Rigidbody2D>().mass);
                

            }

slender nymph
#

you know you can put more than one statement inside an if statement, right? you don't need to check the same condition three times in a row

eternal needle
#

this is truly some code

summer stump
#

Your getmouse condition has all that inside, so you clearly know you can do multiple statements.
Oh, and the if (holding) condition

eternal needle
#

you've already cached the rb2d, you dont need to GetComponent it again at the end there too.
But also for your problem, you still need to describe more. "collision with a specific object", what is colliding with what? The only thing i can suggest from this is using OnCollisionEnter2D and then possibly checking a layer, tag, or if some script is on the other object collided with

stuck palm
#

no idea why, but since migrating to a new kinematic system my scientist character remains suspended in the air when everyone else experiences gravity normally. combed through the entire class and was unsure about what caused this, as the scientist inherits the character class

slender nymph
#

you will need to review what is different about the scientist compared to your other characters. that information is not enough for anyone not intimately familiar with your project to have any idea what could have caused it

stuck palm
#

i tried adding a debug log to print the value of my movement vector every time its set, but the stack trace just shows things working as intended

stable lagoon
#

Can someone help me understand why this code isnt working?
using UnityEngine;

public class Handle : MonoBehaviour
{
[SerializeField] private Collider triggerCollider;
[SerializeField] private GameObject guardToUnhide;

private void OnTriggerEnter(Collider other)
{

    if (other.CompareTag("Guard"))
    {
        guardToUnhide.SetActive(true);
    }
}

}

#

when a gameobject with the guard tag enters the trigger colider nothing happens

stable lagoon
#

ohh thankss

signal comet
#

Hi I wanted to make a game where normal game objects shoot bullets that are entities, is that possible?

signal comet
deft grail
#

if its 2d use a Rigidbody2D, if 3d use a Rigidbody

#

i dont really understand?

rocky canyon
#

but both are integrated into Unity.. just gotta select the appropriate components (3D) or (3D) and Physics. or Physics2D.

teal viper
rocky canyon
#

oh yes..

signal comet
signal comet
teal viper
#

For example, if you decided to use the GameObject physics, you could have an rb + collider for your bullets and have an entity with rendering related components sync position with the rb.

#

Or the other way around, you could have all the physics handled by ECS and sync GameObjects with it for the rendering.

#

You could also handle only the bullets by ECS entirely and other stuff by gameObjects physics. You'd need to create ECS colliders for your other objects that you want the bullets to hit and sync them with the GameObject counterpart.

signal comet
#

Ok I’ll look into that thanks!!

nocturne violet
#
    Vector2 keys

    private void Update()
    {
       keys = new Vector2(Input.GetAxis("Horizontal"), rb.velocity.y);
    }
    private void FixedUpdate()
    {
        rb.MovePosition(rb.position + keys * Time.fixedDeltaTime);
    }
#

does anybody know how to make the gravity now slow?

deft grail
#

MovePosition isnt good

nocturne violet
#

ah

#

ok

eager wolf
#

any insight on why this NavMeshSurfaceEditor returns this error?

nocturne violet
#
    private void FixedUpdate()
    {
        rb.velocity = new Vector2(keys, rb.velocity.y);
    }
#

yo im back

#

it works good but is there any way to make it where it doenst stick to walls?

nocturne violet
#

it you walk in a wall you will just stick to it

deft grail
#

what else do you want it to do?

slender nymph
nocturne violet
#

i want it to slide off the wall

slender nymph
#

this is a code channel, perhaps you want to ask in #📲┃ui-ux ?

eager wolf
queen adder
#

maybe have a second parent with the same properties, scale the 2nd parent, and then move the children, then turn off the 1st parent. That's about all I can think of, I don't think there's a way to exclude children from scaling, I could be wrong tho

#

@tawdry arch

#

you could group those children, to make moving to the 2nd parent easier

crimson ibex
#

I am having trouble linking up my UI components to this script, anyone know why?\

slender nymph
#

you're likely using the Text Mesh Pro UI objects rather than the legacy objects.

#

use TMP_Text and TMP_InputField for the variable types

crimson ibex
#

in here right?

slender nymph
#

yes. you also need to get your !IDE configured

eternal falconBOT
crimson ibex
#

now im getting this error

queen adder
#

use

crimson ibex
#

genius! thank you

queen adder
crimson ibex
#

Still having trouble connecting the last element lol

summer stump
#

Show the inspector for the object you are dragging in

slender nymph
eternal falconBOT
queen adder
rocky canyon
#

use TMP for everything

#

legacy text is 🤢

crimson ibex
#

Thanks everybody it looks like my WebSocket client is connecting!

eternal needle
queen adder
#

if he's knew, I doubt he knows what IDE even means

rocky canyon
#

the Bot message kinda makes it obvious

eternal needle
#

doesnt matter, its a rule to have it configured for help here. they can ask or google what an IDE is

crimson ibex
#

I know what IDE means lol, I am using Visual Studio, but I don't know how to configure it

rocky canyon
#

^ i was gonna say, if u dont wanna get tired of hearing it everytime u post a question you'll just get'r done regardless ;D

crimson ibex
#

I think it is configured now?

queen adder
#

if you wanna verify, comment out "using.TMPro", and if your visual studio yells at you and makes a suggestion for "TMP_Text", it's working fine

crimson ibex
#

Yes it does lol

queen adder
#

I mean there's more to it, but that's basically what they were suggesting

untold pier
#

im setting up running and jumping animations for my character on 2d unity, and when i call the methods that run the animation within my player mvmnt script, it just breaks and says "object reference not set to an instance of an object."

teal viper
crimson ibex
#

Do you need to enable rich text for TMP_TEXT?

teal viper
#

You enable it if you need rich text features. I don't get the question

rocky canyon
#

no, you dont.. that just enables rich text

#

allowing u to use tags.. like <b> For Bold </b>

#

etc

untold pier
#

so this is running in my player movement script:

_playerAnim.Jump(true);

and the class looks like this:

public void Jump(bool jumping)
{
_anim.SetBool("Jumping", jumping);
}

this is my error 🥲 :

#

NullReferenceException: Object reference not set to an instance of an object
PlayerMovement.FixedUpdate () (at Assets/Scripts/PlayerMovement.cs:56)

eternal falconBOT
rocky canyon
#

ur animator is not assigned correctly

#

wel actually... ur using _playerAnim and _anim

#

which one is it?

crimson ibex
#

Looks like by default it is enabled, thanks bros

untold pier
#

player animation is where the second chunk of code is from

teal viper
rocky canyon
#

thats syntax for the Animator component.. not a script.. 🤔

#

ohh i see.. well anyway.. NullReferenceException.. just means its trying to access something that's not assigned.. or is null.. (doesn't exist)

untold pier
#

by the second bit of code i meant the jump method

rocky canyon
#

i can declare an AudioSource called aSrc.. and can call aSrc.Play(); but if its not assigned toa particular audiosource it isnt gonna do anything

untold pier
#

the two pieces of code i sent are from two different files

rocky canyon
#

well, the error is on PlayerMovement

#

on line 56

#

so.. kinda pin-points it for you

summer stump
untold pier
#

like 56 was my call, so _playerAnim.Move(1);

summer stump
#

Then _playerAnim is null

untold pier
#

@rocky canyon is right. its something with my method in the other file

summer stump
#

Where do you assign the reference to it?

untold pier
#

but im not rlly sure how to properly run the animation that i have set for "Jumping"

#

i was following a tutorial

summer stump
#

The error is that _playerAnim is null

#

So lets resolve that

queen adder
#

also when I say inspector, I just mean, you're reference is not assigned

#

mb

untold pier
#

sry i’m not disappeared im still looking for help just away from my pc

#

thank u everyone for helping sm 😓

rocky canyon
untold pier
#

how should i upload my code so it can be accessed easier

queen adder
rocky canyon
#

someone posted a bot message right after you posted ur code..

dense root
#
        // remove diagonal movement
        if (input.x != 0)
            input.y = 0;
        if (input.y !=0)
            input.x = 0;

How come for removing diagonal movement in my character it works great with input.x !=0 but not the other way around with input.y !=0

untold pier
untold pier
teal viper
summer stump
#

Is PlayerAnimation on the same object as PlayerMovement?

rocky canyon
untold pier
summer stump
#

Generally/often the animation would be on the child, so just checking

untold pier
teal viper
summer stump
untold pier
summer stump
#

It is specifically _playerAnim in PlayerMovement, as the error said

untold pier
#

because im only using it to be accessed in my movement script that is assigned to my player

untold pier
summer stump
summer stump
untold pier
#

im so confused

summer stump
#

Is the component on the same object

summer stump
rocky canyon
#

when u use GetComponent its searching the same gameobject ur searching from..

untold pier
#

okay yes

summer stump
#

Don't crop it

rocky canyon
#

so if the component is somewhere else.. it wont be found

untold pier
#

you mean this right

#

im selected on my player

rocky canyon
#

i dont see the PlayerAnimation script on there anywhere tho...

summer stump
#

So playerAnimation is NOT on the same object

rocky canyon
#

this isnt gonna work.. b/c ur playeranimation script isn't on the same gameobject

dense root
#

What's causing my code to throw an Object reference not set to an instance of an object error?

void Update()
{
    input.x = Input.GetAxisRaw("Horizontal");
    input.y = Input.GetAxisRaw("Vertical");

    // remove diagonal movement
    if (input.x != 0)
        input.y = 0;

    if (input != Vector2.zero)
    {
        animator.SetFloat("moveX", input.x);
        animator.SetFloat("moveY", input.y);
    }

    movement = new Vector2(input.x, input.y);        
}

I have the animator attached to the player object and an animator controller set too. Am I missing something?

slender nymph
slender nymph
#

also i feel like we just went through this same thing with the rigidbody

untold pier
#

so i need to assign the playeranimation script to the animator component on my player on the inspector thing right

dense root
#

We did lol

slender nymph
#

yeah so you should know what to do then

cosmic dagger
untold pier
#

wait no

untold pier
#

this is what happens when im jus trying to jump into it without knowing what half of this code means

summer stump
#

The component needs to be actually attached to the same object as PlayerMovement

eternal falconBOT
#

:teacher: Unity Learn ↗

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

rocky canyon
#

if ur using GetComponent.. it should be on the same gameobject... to find it..
if u have a public or a [SerializedField] private reference.. it could be anywhere.. as long as u drag in the reference..

summer stump
#

Do this before doing anything on youtube

rocky canyon
#

it just depends on ur setup

dense root
#

Got it working, thank you so much everyone

queen adder
#

Spawn is right

untold pier
#

okay so first thing is what do you mean by a component. because right now its in my code and i dont really know what it means

teal viper
rocky canyon
#

until you get a grasp on why things work the way they do.. don't put objects on different places, just follow the tutorial 1:1

#

you may have missed a step also, not sure entirely

untold pier
#

is there anywhere in the animator that i can assign it to

queen adder
#

on the same object as your movement script

rocky canyon
#

thats an Animator ^ its not the same thing as ur playerAnimation script

#

which is what confused me at first

queen adder
#

yea lol confused both of us

rocky canyon
#

thats this

untold pier
# teal viper I've said several times already, but this issue is simply you not following the ...

https://youtu.be/qdnoOlTxhng?si=pvwjvjxbJaYeYG3Z
this is my yt tutorial and there is no background context on anything going on in anything else on this guys code other than just the two scripts he opens

#

im trying

rocky canyon
#

what u just screenshotted would be private/public Animator animatorName;

untold pier
#

OHHH

queen adder
rocky canyon
#

weird naming tbh

untold pier
#

im genuinely an idiot im so sorry

rocky canyon
#

PlayerAnimationController.cs woulda confused me alot less ;D

queen adder
untold pier
#

i dont know why i was thinking i needed to drag the script into a little box thing. i forgot i can just add it as part of the object. thats why i didnt know what u guys meant

#

okay great so now player animation is assigned to my player object

#

AYEEE

#

okay that was a really stupid mistake by me thank u guys for being patient

teal viper
rocky canyon
#

as long as ur Player Animation has the animator referenced correctly that should be good 👍 as long as ur playeranimation script is referenced correctly..

#

if its on the same gameobject now. the GetComponent should find it no problem

summer stump
eternal falconBOT
#

:teacher: Unity Learn ↗

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

untold pier
#

yeah i see what was going wrong now. i cant lie a lot of the terminology was kinda going over my head bcs this is all new to me as of the past two days.

rocky canyon
#

you can always debug references too..
Debug.Log(theReference);

#

and it will spit out in the console.. what gameobject it has assigned

untold pier
#

its not great trying to like cut and paste pieces of other ppls games and im seeing that now

#

nothing was integrated properly

#

and the guy was doing a bunch of stuff super weird

summer stump
#

It's a natural thing to try, but skipping a strong foundation makes it a slow path

untold pier
#

right now im just trying to get a basic layout down just to introduce myself for hs ISU

rocky canyon
#

^ once u understand how things work.. its alot easier to copy and paste parts that you need but u have to know how to integrate them into your code..

#

and know what changes to make to make it work

untold pier
#

just dipping my feet in. but i really should learn

rocky canyon
#

b/c everyone copy and pastes..

#

no one types out a simple mechanic that has been documented/ and written 1000 times before

rocky canyon
#

BUT.. gotta get that context 🙂

untold pier
#

and right now the integration process is where im finding out which things i gotta learn i guess

rocky canyon
#

why am i copying this part.. and not that part*

#

etc

untold pier
#

learning by debugging

#

🙂

rocky canyon
#

debugging is a Valuable skill

#

i can't even stress how valueable it is

#

but it comes with experience

#

just keep trying and failing 👍

untold pier
#

yeah like all these errors are shit ive never seen in my life

#

but im getting there

rocky canyon
#

well big take-a-way from this one would be... the script name.. and the line-number..

#

if theres two numbers its the character number and then the line number

#

its the errors w/o any script name thats the hard ones lol

untold pier
#

lol

#

yeah

#

see when i saw the error with that line

#

i thought that it wasnt working because when i called the method something inside the method was brekaing

rocky canyon
#

you should be able to double-click most errors.. and it will open the script and go right to the line its on

#

just a tip

untold pier
#

would that have shown me a different kind of error then

#

or would it have still kinda just been generic about it being that line of code

rocky canyon
#

if u click the error on the bottom box theres a thing called a stack-trace

#

that will show u the order..

#

so if it calls another script.. it will show that too

untold pier
#

ahhh

rocky canyon
#

this script->
that script->
etc

untold pier
#

okay interesting

#

thank you

#

and thats all just with the error tracking on unity?

#

or are u talking about vs

rocky canyon
#

thats the console in Unity

untold pier
#

neat

rocky canyon
#

theres a different debugging process for inside the IDE

#

which is alot better.. but most people dont learn that until later on

#

cuz its a bit more involved

#

you can set break-points where the code i will stop.. and then it will wait for u to tell it to step-through it

#

and u can follow how the code is being called.. 1 step at a time (and it will tell u what values the functions are getting, and returning, and all that jazz)

untold pier
#

havent really made use of it much yet though

rocky canyon
#

me neither..

untold pier
#

only really was useful for me when i was trying to do an assignment in assembly

#

assembler...?

#

whatever its called

rocky canyon
#

nah the IDE debugger

#

Assembly Definitions?

untold pier
#

nah im talking about a whole other language

rocky canyon
#

ohh assembly yea

untold pier
#

had that same stop and step process thing

#

on the website i was using for it

untold pier
#

thats hella useful (eventually)

rocky canyon
#

yeap!

untold pier
#

seeing all the values and stuff is rlly nice i didnt know u could do that

#

@rocky canyon is there a way to speed up my jump animation depending on scale of my jump do you think

#

bcs right now the animation just runs through regardless of how high i jump... so i jump on the ground lol

ivory bobcat
#

Runtime debugging with the ide is good if you need to know the state of certain instances at specific moments. Logging to the console or a file is good if you don't have a specific instance (or know of the specific instance) that you're wanting to fixate on.

untold pier
#

or should i separate my animations into an up animation and a down animation

#

and then base it off of my velocity

rocky canyon
#

theres also a thing called BlendTree's

untold pier
rocky canyon
#

that does stuff for u automatically.. u give it abunch of clips.. and it'll transition between those clips depending on the values u pass..

untold pier
#

ill try and look into that

#

thank u

cobalt creek
#

is t.gameObject.GetComponent<TextMeshProUGUI>().text or t.GetComponent<TextMeshProUGUI>().text better? where t is a Transform in array of Transforms

#

oh wait nvm it doesnt work

#

i use firs one

wintry quarry
#

Second one is simpler and therefore better

cobalt creek
#

thank

wintry quarry
#

Also - cache your references if possible

acoustic arch
#

can't use certain types as parameters for a button?

#

the type is a class it is asking for

rich adder
#

you mean the type?

acoustic arch
#

yeah

#

mb

rich adder
#

yea what are you trying to pass

acoustic arch
#

a class that simply holds my cards data

#

i've done it before tho

rich adder
#

with the inspector?

cosmic dagger
#

you need a custom unity event . . .

acoustic arch
#

yes

acoustic arch
amber spruce
#

anyone know how i would change this to use a layermask

private void OnCollisionEnter2D(Collision2D collision)
{
    if (isAttacking)
    {
        if (collision.gameObject.tag == "Enemy")
        {
            Debug.Log("Hit Enemy");
        }
    }
}
cosmic dagger
#

create a LayerMask variable to check against. access and convert the GameObject layer to check with . . .

amber spruce
#

yeah what code would i use to check if the gameobjects layer is in that layermask

cosmic dagger
#

oh, that part you can easily google . . .

amber spruce
#
if (collision.gameObject.layer == enemyLayer)

like this

cosmic dagger
amber spruce
rich adder
#

no sorry other way around

amber spruce
#

and how would i find layer number

summer stump
#

You already did it on the left side

amber spruce
#
 if ((enemyLayer & (1 << collision.gameObject.layer)) != 0)
 {
     // mask contains layer.
 }

so this?

rich adder
#

enemyLayer.value

rocky canyon
#

layermasks and bitmasks 👀 gives mes anxiety just spectating 🤣

cosmic dagger
rich adder
#

as a enemeyLayer is not a int you get type conversion error

amber spruce
#

cool it works

#

thanks

#

also would there be a type of variable that holds 2 numbers?

#

or should i just make 2 floats

rich adder
#

tuple

rich adder
#

even better ^

summer stump
#

Quite a few ways to do it

cosmic dagger
#

keep 'em coming . . .

rich adder
#

the possibilities

restive kayak
#

I've noticed some rigidbody FPS character controller scripts update the camera's position in the update function, rather than just attaching the camera to the player or the player's head. Since the player's head is always a satisfactory position for the camera and they aren't doing any camera smoothing, I'm curious why they keep the camera separate and use a script to update its position instead of just attaching it. Is there a specific reason for this? If so, wouldn't it be better to use LateUpdate to update it's position?

rocky canyon
#

rigidbody movement isn't always smooth if ur looking thru the FOV of the RB

#

it only updates 50 frames a second

rich adder
wintry quarry
#

LateUpdate is most likely better, but it depends on how the player moves

amber spruce
#

whats the best way to do chances so like a 1 in 100 chance for x to happen is it just if random.range equals 1?

#
if (UnityEngine.Random.Range(whitefuryminimumchance, whitefurymaximumchance + 1) == 1)
{

}

so like this

#

or is there a better way of doing this

restive kayak
cosmic dagger
wintry quarry
amber spruce
amber spruce
wintry quarry
amber spruce
#

cool thanks i no longer need 2 variables

rocky canyon
#
   if (Random.Range(0f, 1f) < 0.5f){ }``` is 50 precent chance
rich adder
amber spruce
wintry quarry
rocky canyon
#

oof, i always forget about .value

rich adder
#

.value 0-1

amber spruce
#

it will have like a 1 in 10000 chance of happening but will make you do insane damage and will have a really cool effect i hope

rocky canyon
#

protip

cosmic dagger
rocky canyon
#

yup yup.. im jotting that down in my notes rn

amber spruce
#

yeah didnt know random.value was a thing i always did the random.range

thin wind
#

Hey all I am having a confusing issue I am making one gameobject the child of another. I then change the local position and rotation to 0 which in theory should match the parents. The parents position and rotation are all 0. however when I do this in code, the position of the gameobject is 0 however, the rotation is (x -180, y 180, z 180)

' _currentEquipped.Equip();
_currentEquipped.transform.SetParent(equipmentSlot);

        _currentEquipped.transform.localPosition = Vector3.zero;
        _currentEquipped.transform.localRotation = Quaternion.identity;

'

rich adder
#

random class has a few interesting ones

rocky canyon
#
if (Random.value < 0.01f)```
#

aye! much better lol

wintry quarry
#

that's the fun part about euler angles, they're not unique

thin wind
wintry quarry
#

where are you seeing that

thin wind
wintry quarry
#

Again, what do you mean by "it", and where are you seeing that?

thin wind
wintry quarry
#

the inspector?
In a log statement?

thin wind
#

the answer to that is that as i was having so much issues with the rotation i seperated them to see what the issue was.

rocky canyon
#

this is why quaternions are used..
euler angles can have some quirks about it

thin wind
rocky canyon
#

many different values can be the exact same rotation when using eulers

wintry quarry
thin wind
#

could a child have impact on it?

wintry quarry
#

just euler angles being euler angles. This is why you don't rely on them

thin wind
rocky canyon
#
(-180, 180, 180)
(180, 0, 180)
(0, -180, 180)
(360, 0, 0)```
wintry quarry
thin wind
wintry quarry
#

yes

thin wind
#

ahahaha

#

now i get it

#

thank you heaps mate

nimble apex
#
        while (true)
        {
            if (counter < 1)
            {
                float tempY = warpObject.transform.localPosition.y;
                tempY = Mathf.Lerp(tempY, 0.5f, counter);

                warpObject.transform.localPosition = new Vector3(warpObject.transform.localPosition.x, tempY, 0);
                counter += 0.02f;
            }```

im on my last step for optimizing certain animation, as u see its a lerp animation but its inside a coroutine
the only problem left is this lerping will finish in one frame, which its supposed to be at least 50 frames , and im trying to avoid doing it on updates/fixedupdates
#

aight looks like i gonna try fixedupdates first

verbal dome
#

If you waited a frame in the while loop then it would happen over time

wintry quarry
#

Yeah where's the yield??

nimble apex
#
IEnumerator test(GameObject warpObject){
        while (true)
        {
            if (counter < 1)
            {
                float tempY = warpObject.transform.localPosition.y;
                tempY = Mathf.Lerp(tempY, 0.5f, counter);

                warpObject.transform.localPosition = new Vector3(warpObject.transform.localPosition.x, tempY, 0);
                counter += 0.02f;
            }
            else
            {
                //commented stuffs
            }
            yield return null;
        }
}```
wintry quarry
#

this won't finish instantly unless counter starts out at 1 or close to it

cosmic dagger
wintry quarry
#

Use Debug.Log to see what's going on

nimble apex
#

oh 💩 let me fix it ty 👍

verbal dome
#

If counter is a class variable then it probably is already at 1+ when you run this the second time

#

Unless you reset it to 0 somewhere

nocturne violet
#

Yo does anybody know what the correct variable name for a cinemachine camera (2d)?

wintry quarry
#

You mean virtual camera?

nocturne violet
#

yeah

wintry quarry
#

CinemachineVirtualCamera

nocturne violet
#

im trying to edit the lens for it

#

thank you

#

ill try that

vale karma
#

!code

eternal falconBOT
nimble apex
#
IEnumerator test(GameObject warpObject)
    {
        warpObject.transform.localPosition = new Vector3(warpObject.transform.localPosition.x, 0, 0);
        warpObject.GetComponent<MegaBendWarp>().axis = MegaAxis.Z;
        warpObject.GetComponent<MegaBendWarp>().from = -0.5f;
        warpObject.GetComponent<MegaBendWarp>().to = 0;

        float counter = 0;

        while (true)
        {
            if (counter <= 1)
            {
                float tempY = warpObject.transform.localPosition.y;
                tempY = Mathf.Lerp(tempY, 0.5f, counter);

                warpObject.transform.localPosition = new Vector3(warpObject.transform.localPosition.x, tempY, 0);
                counter += Time.deltaTime;
            }
      yield return null;

dw it does reset

#

@verbal dome

cosmic dagger
vale karma
#

hello, I have a state machine built and i found that the PlantSeedState's UpdateState function is not getting called, I think the problem lies with going two levels deep into a substate. So the Superstate runs its Update function, the substate runs its update function, but its substate does not. Is there something im missing in this code? https://gdl.space/yutopidaka.cs

wintry quarry
#

The only time I see substates getting set is here:

    public override void InitializeSubState() 
    {
        if (Ctx.IsYoung)
        {
            SetSubState(Factory.Young());
        } 
        else
        {
            SetSubState(Factory.Adult());
        }
    }```
vale karma
#

so the super state, in this case the Alive state, will initialize the substate Young, and that should initialize another substate further called Seed. Everything works up until the update function in Seed

#

im able to get all the way into the Enter function in the Seed state.

#

but it works for young and alive, so its like i didnt reach far enough down lol

ivory bobcat
wintry quarry
#

iot's not updating its substate

vale karma
#

young is its substate and its running okay, are u meaning the seed state?

wintry quarry
#

This is in PlantYoungState

#

I just don't think you actually set the substate to Seed because of this^

vale karma
#

😮 Ohh my goodness

#

let me test it before i hug you

#

hollyyy crap it workedd, i have been staring at it for about 2 days working around this problem. Thankyou goodsir

faint agate
wintry quarry
#

As per the docs you linked:

This function sets enter to the distance along the ray, where it intersects the plane.

faint agate
#

thank you

#

ima mess around a bit more, but that helped a lot

wintry quarry
#

think of it as the distance between the black and orange circles here

vale karma
#

now its not running through the Enter function of the Seed state lolll, its doing weird stuff now, its better tho XD

wintry quarry
vale karma
#

i see it was orginally called in the switch state method, would i just need to add it to the intializeSubstatemethod too?

nimble apex
#

god dammit i figured out the problem

faint agate
nimble apex
#
float counter = 0;
while (true && counter <= 1)```

if 1 is an integer, will it pollute counter and turn it into int as well?
wintry quarry
wintry quarry
#

you declared it as float

#

variables cannot change types in C#

nimble apex
#

ok then i must debug

#

because

while(true){
    .....stuffs
yield return null;
}``` should make the coroutine having update like feature
faint agate
nimble apex
#

like it will not finish in one frame

#

but now it is, it just finished in one frame

wintry quarry
#

Since it's using Vector3.forward as the Plane's normal vector, that's the X/Y plane.

wintry quarry
# wintry quarry

If you look at this picture again, the thing in the top left is the normal vector for the plane. If you think about Vector3.forward being the normal vector, it's plain 😉 to see that the Plane will be the X/Y plane.

vale karma
void seal
#

Ok it's been a hot minute since I've touched an old project let alone use C# but I'm trying to make it so I deceleration slower if I'm above my top speed as to keep some of that momentum.

#

Feel like I'm missing a very obvious fix and syntax error.

void seal
#

LMAO

wintry quarry
#

also if (velocity.x) doesn't make sense 2 lines before that

#

also Your IDE is not configured

#

you need to configure it

#

!ide

eternal falconBOT
ivory bobcat
#

Definitely get it configured though to prevent minor errors.

void seal
#

483 is the velocity.x || velocity.y argument.

#

And could have sworn I got it configured but guess not? I'll get on that.

wintry quarry
void seal
#

Nice.

#

Wow the whole time I thought I'd just have to figure it out and deal with it lmao.

faint agate
#

another question, I have a script to shoot a raycast and hit a object. When it does, itll print the name of the object which works, but how would I acces the object, would I use " GetComponent<GameObject>(). "?

wintry quarry
faint agate
#

okay

void seal
#

Ok, remembered magnitude exists and is a far better arguement. It's configured for Unity now too.

#

coolio

#

ty!

ivory bobcat
void seal
#

Took the screenshot like 5 minutes before and was testing if it works.

#

It's installed trust.

ivory bobcat
#

You don't need to reinstall Visual Studio but simply run and modify it. Make sure the workloads section is checked. External editor stuff, regenerate project and reboot the Unity Editor.

dense root
#

My goal is to disable the animation when the player collides with the wall to prevent the animation from continuously walking. Any thoughts on where I'm going wrong?
https://gdl.space/ahisawivus.cs

wintry quarry
dense root
#

The character is continuing to move

wintry quarry
#

Do you have a Rigidbody? Your code is using Transform based motion

dense root
#

Yup I have a RigidBody2D

wintry quarry
#

so line 36 is basically pointless as-is

dense root
#

Oh I see

#

In the original Pokemon is walking animation disabled when they hit a wall?

nimble apex
#

ok , the coroutine is good , the problem is a function call after the coroutine messed up the lerp animation💩

#

really sad

#

and it wasted 3 hrs

faint sluice
#

Hello, does StopAllCoroutines stop the coroutine immediately or after the next frame?

wintry quarry
faint sluice
faint sluice
#

Oh that's neet

wintry quarry
#

It simply won't continue after its next yield statement

faint sluice
#

I see, thanks!

wintry quarry
#

The only things that can affect the actual line-by-line flow of C# code are C# control statements

#

i.e. return break yield if while etc...

#

Barring such things, code will run immediately, line by line, in order.

faint sluice
queen adder
#

PB is nearing 300k messages here now UnityChanwowUnityChanPanicWork

smoky niche
#

Hey, I had a quick question about Mathf.Lerp. If I have Mathf.Lerp(a,b,t) where t > 1, will it result in a number outside the bounds of a and b, or will it take a and b as min, max values?

languid spire
#

t > 1 will return b

#

t < 0 will return a

willow scroll
smoky niche
#

Where it doesnt give a or b as min/max

willow scroll
cosmic dagger
smoky niche
#

Thanks!

unkempt carbon
#

hi guys im trying to move a prefab game object to another game objects transform. The script is attached to the prefab game object. What am I doing wrong here GuraWail

willow scroll
cosmic dagger
willow scroll
#

Moving a prefab to another GameObject's transform means assign the prefab's transform.position

#

So the created Vector2 has to be assigned to it

cosmic dagger
#

you need to assign the position of one GameObject to the position of another GameObject or Vector2/3 . . .

willow scroll
#

Also, make sure you don't Find the GameObject twice. The GameObject's position can also be assigned directly.

#
yourPrefab.transform.position = GameObject.Find("PlayerSlots").transform.position;
#

If the z axis is relevant, the (Vector2) cast should be used

yourPrefab.transform.position = (Vector2)GameObject
    .Find("PlayerSlots").transform.position;
unkempt carbon
#

thank u guys for the info KRComfiSalute

willow scroll
#

If z position isn't supposed to be 0, assign it this way

Vector2 newPos = GameObject.Find("PlayerSlots").transform.position

yourPrefab.transform.position = new(newPos.x, newPos.y, zPos);
#

Also make sure you know about the disadvantages of the GameObject.Find method

unkempt carbon
#

thank you, its in 2D so no z axis needed GuraThumbsUp

willow scroll
unkempt carbon
willow scroll
willow scroll
# unkempt carbon no o:

The z position in 2D games plays a huge role when displaying the objects.
If the camera's z position is 0 and it's facing the direction forward, then the objects in a specific distance, which have a larger position e.g. 1, 10, 20 will be displayed correctly. The object, which is nearer to the camera will be displayed above the farther one. This way, if the camera's position is 0, the object with the position 1 is on top of the one with position 2, as 1 - 0 < 2 - 0.
If you have an object with the z position smaller than the camera's, and the camera is still facing the direction forward, the camera will simply not see this object, as it's not in its range of view.

unkempt carbon
#

oooh so it affects the layering

willow scroll
#

Yes

cosmic dagger
#

there really is no "2D"; as from the scene view, everything is in 3D. it's just the illusion of 2D. physics and movement are applied on a different axis. it's all a LIE!

cosmic dagger
#

the z-axis is used for layering . . .

unkempt carbon
#

alright i made this

cosmic dagger
unkempt carbon
#

it works!!!!

willow scroll
willow scroll
cosmic dagger
#

now, you can simplify it. this is redundant. no need to access gameObject because you already have access to transform . . .

#

i would use GameObject.Find in a different method to store the PlayerSlots GameObject. this avoids using Find every time you want to move the card . . .

willow scroll
#
  • this is just needed when referencing the global value instead of the local one, or when deriving from an overload
  • The MonoBehaviours are derived from Component, and can thus access the Component.transform property
unkempt carbon
willow scroll
unkempt carbon
willow scroll
#

Either call it once, or assign the desired object in the Inspector

cosmic dagger
unkempt carbon
#

i tried assigning it in the inspector, but I can't assign a prefab to another prefab? it won't allow it..

willow scroll
#

In this case, this.value is the global one, and value is the method's 1st parameter

willow scroll
#

Prefabs cannot just reference the objects from the scene

#

They can reference each other though

eternal needle
unkempt carbon
ivory bobcat
cosmic dagger
unkempt carbon
willow scroll
unkempt carbon
#

no, i understand now

ivory bobcat
unkempt carbon
#

basically, monobehaviour has already defined "gameObject" and "transform" for you, so you dont have to do that

#

is that right?

cosmic dagger
willow scroll
#

As you can see, both properties from from Component

cosmic dagger
#

the same applies for gameObject if you need access to any of the GameObject members . . .

willow scroll
#

MonoBehaviour is derived from Component, so can access them both

supple belfry
#

how to make linear motion for the playable character like with out momentum and acceleration pressing the button moves the playable character from a to b linearly

ivory bobcat
willow scroll
#

Then simply make it return null and apply the constant value multipled by Time.deltaTime

supple belfry
willow scroll
unkempt carbon
willow scroll
#

So you simply assign the position of playerSlot to... its position, assuming the object with the name PlayerSlots is the same one?

cosmic dagger
willow scroll
#

And then, when the card is supposed to move, you simply assign it to the position of the playerSlot. So it just works once if the playerSlot's position isn't changed anywhere

cosmic dagger
#

then you can use playerSlot to get its position at any time . . .

jade fox
#

Hello, i'm struggling with shaders, i'm tryna make theese dynamic patterns and put them on sprites, but i keep having issues

jade fox
#

ok...

unkempt carbon
#

I have a new problem: I'm trying to limit the amount of child game objects to the parent object to 3. I tried to use bool in this way but its not working!

eternal needle
#

You simply have 3 bools that are false, they are then set to true while doing the same logic 3 times. Except for card 3 because you are checking if it's true instead of false

#

You should really look more into basics of c# first and just like really what classes are. Maybe do some basic problem solving using them
Theres a clear misunderstanding about what code does here

cosmic dagger
#

your code checks a bool and adds a child if that bool is false. this will set all the bools to true when attempting to add a single card because it will run each if statement . . .

#

a collection would have been better here, but i would try to understand or work out the logic behind what you want to achieve first, then attempt to implement it one step at a time . . .

eternal needle
# unkempt carbon <:KRSad:632133336449548290>

This is just the truth. You could keep going on with whatever solutions temporarily work, but eventually everything will be such a mess that you cant do anything new and debugging takes hours.
You will save a lot more time by learning simple stuff first. Even I could start trying to guide you towards the right code, but I've seen the messages above. You really shouldnt try struggling your way through a game. Especially if you think having 3 bools that do nothing will limit the child count of another object

runic holly
#

im following a tutorial on procedural dongeon generation and i got error even when i import the code from the github of the tutorial, here are the errors in VS Code and the code

languid spire
#

you have duplicate scripts in your project

cosmic dagger
#

duplicates!

#

twinsies!

runic holly
#

thx

eternal needle
# unkempt carbon no, you're right

For your learning relevant to this problem, look into lists and arrays. A much better setup for this would be having your player slot have some script on it. On that script, you could store an array or list of all cards. You can add cards via some public method on the player slot script. This script already has the list so it knows if theres already 3 elements.

lavish galleon
#

Does anyone use A* Pathfinding Project?

#

How to get the collider to work on 2 Ais?

nimble apex
#
        while (true && counter <= 1)
        {
            //card rotation fix 
            float rotFixY = cardObject.transform.localEulerAngles.y;
            rotFixY = Mathf.Lerp(rotFixY, 0, counter);
            cardObject.transform.localEulerAngles= new Vector3(0, rotFixY, 0);

            counter += Time.deltaTime;

            yield return null;
        }```
consider this lerping animation inside a coroutine , it does work, but the lerping seems a bit off

for example, when i stopped at -61 on y , this function executes , and then y will go from -61 -> -360( which is equal to 0)

why though? and how can i make it to -61 -> 0 instead of -360?
because if i ever moved from 61 to 360 it means the card will spin , which will be very bad
#

or if i try to do -61 -> -0.5f , it might work

languid spire
#

your logic is flawed.

float rotFixY = cardObject.transform.localEulerAngles.y;

needs to outside of the while

nimble apex
#

ok thats bad lol

#

ty

nimble apex
languid spire
#

yes. But bear in mind if you do
Euler A -> Quaternion -> Euler B.
A and B will almost certainly not be the same

nimble apex
#
rotFixY = Mathf.Lerp(rotFixY, 0, counter);```

the problem still exists, -61 -> -360 (0)
#

im now gonna do Mathf.Abs(0) and see if it works lol

errant pilot
#

Guys i want to collect a coin by dragging the mouse towards it how can i do that?

languid spire
#

you should not be updating the value you are Lerping in the Lerp @nimble apex

unkempt carbon
tough abyss
#

how would I display the wave name on the HUD?

deft grail
tough abyss
deft grail
nimble apex
#

so the only thing i can do is doing the whole thing in a while loop

languid spire
nimble apex
#

oh ok nice

#

ty

verbal dome
#

It wraps around 360 degrees correctly, unlike Math.Lerp

hexed terrace
#

!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)

nimble apex
#

👍

tough abyss
#

why does the name string variable display the name of the gameobject its under?

storm pine
#

Is there any way to set a Dictionary<> through the Unity Inspector? It just doesn't appear. I found you can create a Serializable class that constains the pair key-value and then use a list or array of this class. And finally on the awake or Start transform the list or array to an actual dictionary, but I think there should be a better way to do that, looks so complex for an easy problem. This is an example if I don't explain to good with words:

[System.Serializable]
public class IntPuzzleCanvasPair
{
    public int key;
    public PuzzleCanvas value;
}
public class PuzzleManager : MonoBehaviour
{
    [SerializeField]
    private List<IntPuzzleCanvasPair> puzzleCanvasList = new List<IntPuzzleCanvasPair>();

    private Dictionary<int, PuzzleCanvas> puzzleCanvasDictionary;

    void Awake()
    {
        puzzleCanvasDictionary = new Dictionary<int, PuzzleCanvas>();

        foreach (var pair in puzzleCanvasList)
        {
            if (!puzzleCanvasDictionary.ContainsKey(pair.key))
            {
                puzzleCanvasDictionary.Add(pair.key, pair.value);
            }
            else
            {
                Debug.LogWarning("Duplicate key found: " + pair.key);
            }
        }
    }
}

fossil drum
# tough abyss

No clue what your actually trying to achieve, but name defaults to the name of the gameobject this script is on.

tough abyss
languid spire
tough abyss
#

should be referencing this

storm pine
#

something like waveSpawnerScript.GetActualWave().name;

stuck palm
#

if i comment out stuff like this, will the reference still be there when i uncomment it

hexed terrace
#

I want to say yes.. but test it. Add a new var

stuck palm
#

i've got this issue where this guy will stay in the air. p1 is a duplicate that uses the base character class, and player 2 uses the scientist class player 2 doesnt seem to be getting affected by gravity at all and remains suspended in the air. I've commented out the entire scientist inherited class, and he is still having this issue. what steps can i take to try and debug this error?

verbal dome
#

And start debugging its movement variables

#

Does the character always float?

stuck palm
#

lemme show u the components one sec

storm pine
verbal dome
#

Also make sure that all layers and layermasks are correctly set up

stuck palm
#

idk why this guy doesnt

stuck palm
#

offending character is on the left

#

on the right is the debugging one, which uses the base character class

#

I literally copy pasted the one on the right, removed the scientist class and added the character class, and changed nothing else

verbal dome
#

Does your animator have root motion enabled?

verbal dome
#

Does the left version work correctly?

stuck palm
#

gravity wise

#

you cant use the moves because thats the scientist class job

verbal dome
#

Maybe post the scripts. Character and scientist

ivory bobcat
stuck palm
storm pine
willow scroll
fossil drum
# tough abyss trying to show the wave name on the HUD

Your wave manager knows which wave is currently alive.
You can just give that a method that retrieves that name from the current Wave object in the list/array you have in the manager.
What you call all those things is up to you.

verbal dome
#

If thats the case then the script cant be the issue

#

Try recreating the scientist from the normal character again. Make a prefab variant

storm pine
stuck palm
stuck palm
verbal dome
#

So my root motion guess wasnt too far off 😁

stuck palm
verbal dome
#

Maybe some animation has keyframes for y pos?

#

Not sure, I never control movement with anims

stuck palm
#

but i'll have a look, thank you

stuck palm
#

everything works as normal again

verbal dome
#

Nice

stuck palm
queen adder
#

Guys what is the difference of

public float hallucinations;

And

[SeralizseField] (i forgot the rest lol)
languid spire
#

One you didn't forget, the other is complete nonsense ?

#

why would you ask a question and not even be bothered to ask a sensible one?

wintry quarry
spiral oak
queen adder
wintry quarry
spiral oak
swift crag
#

To serialize is to turn something into data.

#

Unity records the values of serialized fields.

queen adder
swift crag
#

okay, several clarifications here

swift crag
#

[SerializeField] is an attribute. It can only be applied to fields.

#

Fields are variables you declare in a class.

#

Update and Start are methods: functions inside a class

wintry quarry
swift crag
#

Both of them return void, which means they return nothing.

queen adder
#

And what are classes?

swift crag
#

They are not called "void start" or "void update", just "Start" or "Update"

spiral oak
swift crag
#

classes are collections of variables and functions (and other more niche things)

#

you have probably made several classes already

swift crag
#

when you create a class that has MonoBehaviour as its parent, you're creating a new kind of component to use in Unity

swift crag
swift crag
swift crag
#
public class Foo {
  public void Bar() {
    if (true) {
      Debug.Log("Baz");
    }
  }
}
#

this is a class called Foo

#

it contains a method called Bar

#

which contains an if statement

queen adder
swift crag
#

The premise holds.

polar acorn
wintry quarry
#

You asked what a class is

#

This covers it perfectly

polar acorn
queen adder
swift crag
#

this doesn't make any sense at all

#

the [SerializeField] attribute can only be added to a field.

queen adder
#

I know but really I need help where you could put serialize fields in

wintry quarry
swift crag
#

fields are declared inside of a class, I guess

spiral oak
swift crag
polar acorn
queen adder
polar acorn
#

It allows you to edit a variable in the inspector, but not access it from another class. That's all.

swift crag
#

today we will be writing a game entirely in Haskell

queen adder
polar acorn
swift crag
#

does Scratch have inheritance

#

and used-defined types

spiral oak
spiral oak
swift crag
polar acorn
#

I made a text based dungeon crawler in Haskell as a final project at college

queen adder
#

Yea classes don’t really exist in scratch

swift crag
#

ooh, fun

queen adder
#

I’m just starting code lol i started yesterday and still learning from a tutorial

spiral oak
queen adder
#

Scratch is block based 🤷

spiral oak
polar acorn
# queen adder What about in… scratch? Lol

Fine, I didn't want to get too specific to avoid muddying the waters but allow me to amend my statement:

Classes are mostly the same thing in every programming language that has them

spiral oak
queen adder
queen adder
queen adder
spiral oak
queen adder
spiral oak
#

I mean, what is text-based?

queen adder
spiral oak
queen adder
#

Text based is a simple way for saying oop (for me)

spiral oak
swift crag
#

you're talking about the visual interface you use to write and modify code

queen adder
swift crag
#

"object oriented" means that you create objects: collections of code and data that you can pass around

spiral oak
queen adder
#

This started as a question now like 25+ msg lol

queen adder
spiral oak
queen adder
#

!code

eternal falconBOT
polar acorn
ionic plank
#

hello, I have a problem with my camera. I want its to follow my character (for a 2d platformer). I succed when i had just one character, but now I introduce an other one to choose which one you would like to play. But now the camera is fix and I don't know why (I have already put a cinemachineVirtualCamera but it doesn't work)

queen adder
#

I’m just saying it my way, I’m not using like idk rust or unreal engine

polar acorn
spiral oak
queen adder
spiral oak
polar acorn
# queen adder I could say OOP and text based whenever I want, u know

Yes, and you'll make things infinitely harder on yourself, learn nothing useful and immediately run into a wall as soon as you see that unity has a visual scripting package.

The first way you learn something is important and it's maddeningly difficult to un-learn something.

ionic plank
# spiral oak How did you introduce the second character?

I use prefab for both character.

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

public class PlayerManager : MonoBehaviour
{
    public GameObject [] players;
    public CinemachineVirtualCamera CVcam;
    int characterIndex;
    // Start is called before the first frame update
    void Awake()
    {
        characterIndex = PlayerPrefs.GetInt("CharacterSelected", 1);
        GameObject player = Instantiate(players[characterIndex], transform.position, Quaternion.identity);
        CVcam.Follow = player.transform;
        CVcam.LookAt = player.transform;
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}

queen adder
spiral oak
polar acorn
ionic plank
polar acorn
#

These are entirely unrelated subjects

ionic plank
spiral oak
queen adder
#

Is ‘’’cs
Test
‘’’

spiral oak
queen adder
spiral oak
queen adder
#

I mean it’s easy to think about but

#

Hard to think it if you get it

spiral oak
#

the code looks well done tho

ionic plank
spiral oak
#

So did you add the PlayerManager to any GameObject of the scene?

spiral oak
# ionic plank yes

alright then start the game and select the Virtual Camera. Check in its inspector if follow and lookAt fields are actually set to your player

ionic plank
spiral oak
#

oh that's weird

ionic plank
queen adder
# ionic plank

The script is disabled and the player is set to none (camera follow)

#

Is that supposed to be like that?

ionic plank
#

I found my mistake ...

queen adder
#

Where is your other script

ionic plank
#

I had two Camera

#

so my screen display the second one

spiral oak
ionic plank
#

thanks you ❤️

wraith hornet
#

to get instanced of a material , use .getComponent<Renderer>().material, right ?