#💻┃code-beginner

1 messages · Page 408 of 1

high cobalt
teal viper
#

I'm not even sure that would compile

#

You need to pass some parameter to the debug log method.

regal basalt
#

hello there, so another error occurred with the game, now the player flies among the camera orientation, can i send a short video of the movement?

high cobalt
#

would taht work?

bright grail
#

yep that would

#

does it?

high cobalt
#

I have no idea cause i have something spamming in the console

#

how does it not exist

bright grail
#

did you set a bool in the animator window for wall sliding

high cobalt
#

yes

#

do i delete that?

bright grail
#

no

high cobalt
#

i deleted it and it fixed it

bright grail
#

idk then maybe you 2 or something

high cobalt
#

okay, debug log now shows me it works but the roll itself does nothing

bright grail
#

does it "yes" get loged in console

high cobalt
#

yes;'

bright grail
#

ok so now you know its prolly something with the animation

high cobalt
#

just anim.SetTrigger for this?

#

or something else

bright grail
#

no you need to set one

swift crag
#

The parameter has to exist.

#

Did you actually create a Trigger parameter called "Roll"?

#

bool/float/int parameters do not count

high cobalt
#

Yeah I have one

bright grail
#

show us

high cobalt
#

like, in Unity?

swift crag
#

Show us the animator window with the parameter list visible.

bright grail
#

yea like a screen shot

high cobalt
swift crag
#

Ensure that there is not a space at the end of the name

#

Then show me the inspector for PlayerMovement.

bright grail
#

yo Fen i also have a rq question

high cobalt
#

this one?

swift crag
#

Oh, right, Animator is private and assigned in Awake

#

Make sure that the Animator on the same object uses the correct animator controller

#

Double clicking on the "Controller" field should open the Animator window

high cobalt
#

This is my Animator

swift crag
#

double click the "Controller" field and ensure that the animator window is still showing the same controller

swift crag
high cobalt
#

yeah its showing

teal viper
#

Clear your console, make sure you are not in play mode and that there are no words in the console, take a screenshot of the console.

high cobalt
#

like, just an empty console?

#

wdym

cosmic dagger
teal viper
#

If it's empty, then it's fine(assuming you don't have errors hidden)

high cobalt
#

yeah there are no errors

teal viper
high cobalt
#

when entering play

teal viper
#

Take a screenshot of the whole editor window

high cobalt
#

but it highlights another object

#

thats unrelated

#

had a deleted script in it

cosmic dagger
bright grail
#

ok so rq before anything this code is just me testing and prototyping ideas, but baically the function run is to check if there is a tile next to this tile and if not the it returns null, in the if statments im checking if the return comes back null but and return a false if it does the timer max is set to 10, anyways im getting back a null error and idk if im just stupid or what so do you guys know why this is comng back as a null error and not a true or false?

high cobalt
bright grail
#

sorry ik its a lot

high cobalt
teal viper
high cobalt
#

The animation works now the thing that doesnt is the rolling mechanic

swift crag
#

Okay, so you are no longer getting the warning about the trigger not existing?

teal viper
eternal falconBOT
cosmic dagger
swift crag
#

else if (GridManager.GetTileAtPosition(new Vector2(transform.position.x, transform.position.y+ 1)).tag == "Water")

Something in here is null.

#

I presume that GetTileAtPosition returned null

#

and then you tried to access the result's .tag member

bright grail
bright grail
#

and it changes based off of where the null tile is

#

it has to do with it not recognizing the null yk

high cobalt
#

it gives no velocity whatsoever

swift crag
#
MyClass x = null;
x.foo = 1; // error
x.Bar(); // error
high cobalt
#

I put a debug.log into the part after private.void StartRoll() and it doesnt show up so maybe theres something wrong with that part?

swift crag
#

That sounds relevant, yes!

#

If the log message is the very first thing in the method, and the log message doesn't appear, then the method isn't being called at all

bright grail
swift crag
#

I don't understand what you mean by that.

#

If the function returns null, and you try to access a member from the resulting null reference, you get an error

bright grail
#

wait i see what you mean

bold plover
high cobalt
#

okay so actually it stops working at if (Input.GetAxisRaw("Roll") > 0), 1 line before it sends a message after it doesnt

bold plover
#

Will this hurt me long term or nah?

bright grail
#

im thinking i try for the null first then see if the tag is water

#

IM SO STUPID

bold plover
#

It fixes the error though I'm not sure why it happened to begin with.

cosmic dagger
swift crag
#

I'm guessing you declared AnimationTriggerType as an enum inside of Player

#

using static lets you access things from a type without explicitly using its name (much like using lets you use stuff from a namespace)

cosmic dagger
swift crag
#

If they're meant to be the same thing, then you should not be declaring them inside of other types.

#

you should declare the enum once

high cobalt
bold plover
swift crag
#

as there is no reference to the Enemy in my Player script.

#

That has nothing to do with what I said

#

I think you need to show us your code here. You're probably doing something wrong here.

bold plover
#

gotcha

swift crag
#

!code

eternal falconBOT
high cobalt
#

hey guys is something wrong with this lin e
(Input.GetAxisRaw("Roll") > 0)

swift crag
#

presumably you meant to put an if somewhere in here

high cobalt
#

oh yeah there's an if it didnt copy

#

if (Input.GetAxisRaw("Roll") > 0)

wintry quarry
high cobalt
#

before all's alright

wintry quarry
high cobalt
#

doesn't run, debug.log doesnt show

wintry quarry
high cobalt
#

yes

wintry quarry
#

Do you have errors?

high cobalt
#

no

wintry quarry
#

You sure? What Debug.Log are you expecting to show?

swift crag
#

Code doesn't just "stop running" silently

wintry quarry
#

If the code after that line doesn't run that usually means you have an exception happening

#

for example maybe you didn't define an axis called "Roll"

#

that would show as an error in your console at runtime

#

Show the rest of the code and show your console window when the code runs

swift crag
#

Share the entire script.

high cobalt
#

i removed the debug.logs already tho

wintry quarry
#

add them back

high cobalt
#

aight

wintry quarry
#

it's important to know which logs are not running as you expect

swift crag
#

Always show the code you were running

#

don't remove things

#

(especially don't try to "simplify" your code)

high cobalt
#

Okay I just got 2 errors after waiting

wintry quarry
bold plover
#

Apologies my code is a bit of a mess. 😔

swift crag
#

I don't see why it wouldn't be able to find the AnimationTriggerType enum. The enum is a nested type inside Player, and the function is also a member of Player

high cobalt
#

oh right, but still only things ive got

wintry quarry
#

what is this in reference to?

swift crag
#

It sounds like you might have three of them

wintry quarry
high cobalt
wintry quarry
swift crag
#

the entire point of an if statement is to guard a block of code based on a condition, yes

bold plover
#

THE TEST CUBE.

wintry quarry
swift crag
#

C# is unaware of what objects exist in your scenes

tulip parrot
#

Someone could help me with a problem with a terrain generation?

wintry quarry
#

put it BEFORE the if statement obviously

bold plover
#

No I have a third script that applies that cube where I tested the code to begin with. It also has that AnimationTriggerType.

swift crag
high cobalt
#

Roll axis value = 0

wintry quarry
swift crag
#

Right now, these are three completely unrelated types:

  • Player.AnimationTriggerType
  • Enemy.AnimationTriggerType
  • AnimationTriggerType
#

They are not interchangeable.

wintry quarry
#

0 is NOT greater than 0

high cobalt
#

how can I fix that

swift crag
swift crag
#

Where and how?

wintry quarry
high cobalt
#

the button is R and i press it doesnt work

wintry quarry
high cobalt
#

Input manager

wintry quarry
high cobalt
#

removed it by accident rn

#

but it was

#

i was rolling to get to the debug logs no

#

pressing r

wintry quarry
#

also wouldn't you jsut do GetButton("Roll") if all you want is a button?

high cobalt
bold plover
#

Yeah I have 3 different ones. Test Cube wasn't at all related.

#

Thank you. Noob question it feels like.

tidal remnant
#

Quick question, instead of Navigation(Obsolete)
How should I reference Navigation?
Is it the same or have some values been replaced?

swift crag
#

It sounds like you want to delete the AnimationTriggerType types from Player and Enemy, so that everyone can use the same enum type

bold plover
#

Yeah I understand that now. Completely wrong assumption on my end. But I appreciate you reiterating so I don't misunderstand going forward in the future.

wintry quarry
high cobalt
bold plover
#

Almost took the wrong lesson from it. So again, thank you!

wintry quarry
#

Just giving advice

high cobalt
#

Where do I place the GetButton

wintry quarry
#

instead of GetAxis

high cobalt
#

what do i do

wintry quarry
#

if (Input.GetButton("Roll"))

high cobalt
#

everything goes red after that

wintry quarry
#

you did some basic syntax error

#

¯_(ツ)_/¯

verbal dome
#

Input.GetButton

wintry quarry
#

oh my bad lmao

#

I'm not playing Baldur's Gate while I talk or anything

high cobalt
#

just like this, ya?

swift crag
#

and now i flee

wintry quarry
high cobalt
#

Okay it works after that line but still isnt propelling my character forward

#

debug log shows everything works but still it doesnt

wintry quarry
#

Time to add more logs and see which of them is running and when

#

Seems like this would certainly do it:

        if (wallJumpCooldown > 0.2f)
        {
            body.velocity = new Vector2(horizontalInput * speed, body.velocity.y);```
#

I don't see how rolling could work when that code is running

high cobalt
#

I mean wall jump cooldown will be <0.2 no? so it wouldnt be running

#

cause you dont wall jump before rolling

#

or am i missing something here

#

oh shoot you were right it works without the code but when I delete it I can't movexd

keen palm
#

there are any way to make charactercontroller.SimpleMove to jump or i have to switch to .Move 🥺

high cobalt
swift crag
#

To switch from SimpleMove to Move, you need to make two changes:

  • Add a negative number to characterController.velocity.y to calculate the new vertical velocity
  • Instead of passing a velocity, pass a change in position. You can do this by multiplying your final velocity by deltaTime
#
float verticalVelocity = characterController.velocity.y + Physics.gravity.y * Time.deltaTime

This would do the trick.

high cobalt
#

what should I do with this line:
body.velocity = new Vector2(horizontalInput * speed, body.velocity.y);
it interferes with the rolling

#

what can I switch it out to

#

// Normal movement
if (wallJumpCooldown > 0.2f)
{
body.velocity new Vector2(horizontalInput * speed, body.velocity.y);

        if (Input.GetKeyDown(KeyCode.Space))
            Jump();
    }
    else
    {
        wallJumpCooldown += Time.deltaTime;
    }

this is the full

swift crag
#

perhaps you can stop setting the velocity during a roll

high cobalt
#

what should I do instead then

#

?\

strange hazel
#

hey yall so I'm working on moving a clicker game I made in Javascript to unity, and for once trying to organize the code. I'm new to unity though and I'm not sure how the best way to handle upgrades would be. I want to have a scrollable list of buttons to buy upgrades with a simple function like buyUpgr(tier), but how would I go about making the upgrades in a succinct way, I don't need separate objects for the upgrades I don't think, I just need a way to store the price, name, tier, and amount. this should be simple but I have no idea and have been stumped lol

strange hazel
#

in Javascript I literally just had an endless list of integers for prices and how much the player had and it worked but it was so clunky for no reason

swift crag
#

Rather than using a formula to calculate them

strange hazel
#

well once you buy the upgrade, it's gonna be formulaic for the next price as part of the function

#

but all the starting values would be manual, unless there's an easier way

swift crag
#

Will all upgrades use the same sort of formula?

#

e.g. they all double in cost for each tier

strange hazel
#

no so I could probably also store the multipliers they use

#

but it would be a simple multiplier

#

like some being 1.7, some being 1.5

swift crag
#

As long as you aren't using totally different formulas for different upgrades, then it'll be pretty simple

#

So, I'd suggest creating a class like this:

[System.Serializable]
public class Upgrade {
  public string name;
  public float baseCost;
  public float costGrowthMultiplier;

  public int level;

  public float CurrentCost => Mathf.Pow(costGrowthMultiplier, level) * baseCost;
}
#

you can now create a List<Upgrade>

#

CurrentCost is a property, so it gets calculated each time you use it

strange hazel
#

oooh alright, and then just how would I go about getting and setting data from that, just make a new() and do that[tier].price?

swift crag
#

You wouldn't create any new Upgrade instances at runtime

#

you'd just set this up in the inspector

#

How are you going to actually use this upgrade data, though?

#

Right now, this is just a list of "upgrade" objects, each of which has a:

  • name
  • level
  • cost to upgrade
strange hazel
#

whenever i click one of the assorted buttons in the upgrade shop, i would want to run a function like buyUpgr(tier of upgrade)

swift crag
#

Who else is going to use this upgrade data?

#

I imagine it's not solely used by the upgrade button

strange hazel
#

cuz like in Javascript how I had it as buyUpgr(0-whatever for index) I figured it would be the same

swift crag
#

other parts of your game care about the upgrades too

strange hazel
swift crag
#

right, but you use these upgrades somewhere else, right?

strange hazel
#

but other than that I'm not sure off the top of my head, more just trying to plan for the future

strange hazel
swift crag
#

You can't drag them into fields in the inspector

#

But you could adapt it a little.

#

For example, you could create a Dictionary<string, Upgrade> that's stored in the game manager

#

When the game starts, you do this:

radiant frigate
#

does someone know why the math doesnt activate?

swift crag
#
Dictionary<string, Upgrade> upgradeMap = new();
[SerializeField] List<Upgrade> upgradeDefinitions;

void Awake() {
  foreach (var upgrade in upgradeDefinitions) {
    upgradeMap[upgrade.name] = upgrade;
  }
}

public Upgrade GetUpgrade(string name) {
  return upgradeMap[name];
}
#

This would be in your "Game manager" class

#

An upgrade button could store the name of the upgrade it's for

#

It can then ask the game manager for the Upgrade

strange hazel
#

alright I think I've got it now

swift crag
#

The only problem here is that you could use the wrong name

#

e.g. you could have a typo

polar acorn
radiant frigate
radiant frigate
regal basalt
#

i need help with my player movement, it doesn't recognise the keys, and i'd like to know why is that happening and how am i suppost to fix the error (i've set comments in the lines with an error to help identify)

eternal falconBOT
regal basalt
cosmic dagger
#

Only very few people can see your code (it doesn't appear on mobile) . . .

regal basalt
regal basalt
#

i've only sent the base movement block

#

i will break it down for you

#

before i send the code, these are the 3 errors i kept getting

rich adder
#

you gotta use the link.

regal basalt
#

collab?

rich adder
rich adder
#

sending only a snippet when showing null references we can't see lines accurate anyway.

regal basalt
#

im new to this mb

rich adder
#

whatever is on line 145,294, 390 is null

regal basalt
#

let me get this straight

#

are you asking for the complete code?

#

the 700 lines?

rich adder
#

thats what the websites are for

#

so you can send whatever size they are

cosmic dagger
rich adder
#

and yes why is an editor script in another script..

regal basalt
rich adder
#

anyway looks like you got multiple things that are null so fix it

rich adder
# regal basalt auch

doesn't look like crosshairObject was found on whatever object has that script FirstPersonController

#

and sprintBar, sprintBarCG

#

this code also handling UI notlikethis

rich adder
#

but its code beginner so you are forgiven 🙂

regal basalt
#

from now on i am doing a script for every single function

#

"every"

rich adder
#

not every fuction, that would be insanity

regal basalt
#

hahah

rich adder
#

ideally for every " purpose "

regal basalt
#

that's one word for it yes

#

i'd call it intention, but

#

your fits better

rich adder
#

"Im just responsible for this "

#

anyway you understand the original issue though you had ?

regal basalt
#

insanity

regal basalt
rich adder
regal basalt
#

i will be back with more news

rich adder
regal basalt
regal basalt
#

how so?

regal basalt
summer stump
#

There is a reason it is the single most quoted and followed principle in software engineering

regal basalt
summer stump
#

Do you mean the singleton referencing other things, or other things referencing the singleton?

Start is generally used for external references, awake for self-reference
The issue that can pop up is when using it in DDOL, when awake and start will not be called when a new scene is loaded

rich adder
#

assign singleton instance in awake while everything else should at least wait Start to use instance of it , yes

regal basalt
#

@random dirge when you have a singleton with serialized fields, they are typically used to hold references to other objects in the scene

summer stump
#

As said twice, use start
Awake only for self-reference

fallen ember
#

!code

eternal falconBOT
summer stump
#

Like getting a component reference to the same object as the singleton, or initializing values. Never for getting a reference to a different object or values in a different script

Even that is not foolproof though, but it is a start

cosmic dagger
#

Awake is used for (inside) self-initialization. Start is used for outside initialization . . .

summer stump
#

Where is that from?

rich adder
#

not accounting for a singleton

cosmic dagger
#

Because Start is called only once when the script is first enabled (which is when a GameObject first becomes active) . . .

summer stump
#

Weird. Well, getting a reference to a SCRIPT could be fine in awake. Not to a value IN the script though

slender nymph
#

those commends also do not contradict what was told to you

cosmic dagger
#

They mean references between scripts (on the same GameObject). They just weren't specific . . .

#

You reference scripts from other (outside) GameObjects in Start . . .

fallen ember
summer stump
rich adder
#

not just for null too, imagine this scenario

//script1
void Awake()
{
    number = INeedSomeValue();//9
}
//script2
void Awake()
{
    Debug.Log(script1.number);//logs 0 or whatever initialized field was
}
void Start()
{
    Debug.Log(script1.number);//logs 9
}```
summer stump
#

It gives you two different times. The first start (of objects existing when the scene is loaded) is guarenteed to be after all awakes

summer stump
#

Instantiating obviously doesn't work that way though

magic panther
#

I have this part in my update function inside my player, and though I press the keybind it seems to do nothing (fullscreen is a public bool). Is this just me not knowing at all how to use Screen stuff?

        if (Input.GetKeyDown(fullscreenKey)) {
            fullscreen = !fullscreen;
            Screen.fullScreen = fullscreen;
        }
slender nymph
#

are you testing in a build? because the editor will not play game mode in actual fullscreen

magic panther
#

yes, testing. Is there a way to see this in action while testing?

#

I mean not test build, testing the game as in during development of it

#

is there a game file I should launch via file explorer?

slender nymph
#

put a log there to print when it does its thing and what it changes to

#

otherwise build it

magic panther
#

whenever I press the keybind it switches on or off (not while holding)

#

which is the desired behavior

regal basalt
#

my friend, paste the code here:

#

!code

eternal falconBOT
regal basalt
wanton otter
#

@slender nymph sry to bother again but i basically replaced Vector2.up with transform.up like you told me and it doesnt really seem to work

#

i mean like it wont even add the force to begin with so i cant really tell which direction its facing

slender nymph
#

have you made any other changes to the code? also you can select the object in the hierarchy and set the tool handle to Local instead of Global to see the direction its axes are facing

wanton otter
#

pretty much the only change i did to the code

#

gimme a sec

#

like this?

slender nymph
#

the upper left buttons in your scene view window are the tool handle buttons. your rotation one (the second one) needs to be set to Local

wanton otter
#

how can i set it to local 😅

slender nymph
#

i just told you how

wanton otter
#

1 second

slender nymph
#

there you go. so as long as the component with the code you showed is actually attached to that object it will add force in the correct direction

wanton otter
#

nice but it still wont apply the force for some reason

slender nymph
#

was it adding the force previously

wanton otter
#

yea

slender nymph
#

then what else did you change

wanton otter
#

i didnt change anything

#

i can double check that it applied the foce previously

#

gimme a sec

slender nymph
#

you had to have changed something if it was working before and it isn't now

wanton otter
#

my bad ive accidentally changed the type of force to vector instead of float

#

it probably works now ill give it a quick check

#

ayy works like a charm

#

thx again 🙂

#

its a bit weaker now that its angeled though

#

even turning up the force still mostly pushes the character up rather than to the right

slender nymph
#

that's likely due to how you move the player

wanton otter
slender nymph
#

no. you can share your code and send a screen recording or screenshots here though

wanton otter
#

good enough, give me a second

spice breach
#

I'm currently trying to improve a maze generator I made by giving it the ability to generate multiple floors on the same maze

#

my idea is is to mark the exit/goal node of the previous level as the starting node for the current level, by removing the floor

#

Am I able to use a 2D array to store all the nodes in the mazes, 1 storing the number of that node, relative to its level

#

this may sound like absolute waffle but i feel like it'll be easier in my head if i say it

#

stupidest question ever, yes i can

spice breach
#

how would I go about assigning an entire row to a list, from this 2D array?

rich adder
#
int rowIndex = //pick a row
int numberOfColumns = levels
for (int col = 0; col < numberOfColumns; col++)
{
    currentFloorNodes.Add(nodes[rowIndex, col]);
}```
spice breach
#

I could use a for loop

#

ah

#

yeah

#

cheers my friend

#

I've seen you talk here quite a lot, you are a life saver for a lot of people my brother 💙

modest dust
#

Or use a jagged array and pass the intire row into the list

rich adder
#

true, directly access the whole row is good

dry spruce
#

can any one help me on this

timber comet
#

Try creating one first (I mean, try adding in your scene a TextMeshPro text in the editor)

#

It should prompt you to import the package

dry spruce
#

thanks for your help

timber comet
dry spruce
#

where i can share u my code

timber comet
#

!code

eternal falconBOT
timber comet
dry spruce
#

got it?

timber comet
#

I’m trying to find the error

dry spruce
#

ohk

timber comet
#

Ok so

#

The error is trying to tell you that in line: 3 you have a
using System.Diagnostics.Contracts;
Which doesn’t exist

#

You need to remove that line

cosmic dagger
#

line 3 is using System.Diagnostics.Contracts;. does this exist? if not, remove it . . .

dry spruce
#

ohk

#

new error

#

i want to build n run

languid spire
dry spruce
#

no one is responding there

sly lake
languid spire
languid spire
sly lake
#

I just show the error

languid spire
dreamy dune
#

maybe dumb question but why do some people use namespace in their scripts

languid spire
dreamy dune
#

so its easier to find?

lean sedge
#

I been trying to access and modify a mesh on a gameobject through a scriptable object. But I'm a bit confused, do I pass a mesh to a meshfilter to change the form of the object?

#

I've declared a mesh variable on my scriptable object and picked the capsule mesh. Then I declared a mesh on my object I want to change the mesh of. But on that I get a type mismatch. I can't select the gameobject in the inspector.

eager spindle
eager spindle
lean sedge
eager spindle
#

youll need to test it tbh

#

try referencing the meshfilter first and see if anything bad happens

#

im not sure if the SO will allow you to reference a scene variable

lean sedge
#

I can reference a meshfilter to my scriptable object but it results in a type mismatch in the inspector

#

So I cant really do anything with it

river quiver
#

how do i change color of the text by script?

#
price.color = new Color(15, 30, 247, 255);```
#

this doesnt work for me

keen dew
#

Color values are between 0 and 1. If you want 0-255 use Color32 instead

river quiver
#

aaa okay

dreamy dune
#

i am making a inventory system is it reliable to use a system where it has a databse based on names

modest dust
#

Based on names for what? Looking them up in the database?

#

There can technically be duplicate names

#

It's better to give a unique id to each item instead

languid spire
#

Also, should you want to implement language localization using any string descriptor would break your database

dreamy dune
#

is it possible to change your project to urp ?

mild mortar
#

So I have a base class for AI general stuff that sort of looks like this

public class Hostile : MonoBehaviour, IDamageable, ITriggerCheckable
{
    [field: SerializeField]
    public float maxHealth { get; set; }
    [field: SerializeField]
    public float currentHealth { get; set; }
    [field: SerializeField]
    public bool IsAggroed { get; set; }
    public bool IsWithinAttackRange { get; set; }

    [HideInInspector]
    public Navigation navigation;
    [HideInInspector]
    public LineOfSight lineOfSight;
    public GameObject target { get; set; }

    #region State Machine Variables
    public EnemyStateMachine stateMachine { get; set; }
    public EnemyIdleState idleState { get; set; }
    public EnemyChaseState chaseState { get; set; }
    public EnemyAttackState attackState { get; set; }
    #endregion

    void Awake()
    {
        stateMachine = new EnemyStateMachine();
        idleState = new EnemyIdleState(this, stateMachine);
        chaseState = new EnemyChaseState(this, stateMachine);
        attackState = new EnemyAttackState(this, stateMachine);
        navigation = GetComponent<Navigation>();
        lineOfSight = GetComponent<LineOfSight>();
        stateMachine.Initialize(idleState);
    }

I want different types of course, so 've made a class called Zombie that inherits from Hostile. I want Zombie to set the sightRange of the lineOfSight component to 15.

But it keeps telling me it has a null reference for the object.

I assume it's because the child is trying to call before the parent sets up properly. Anyone know how to generally fix this?

modest dust
#

Where does your assumption come from?
When does the subclass of the Hostile class tries to use the lineOfSight component?

hexed terrace
#

your awake needs to be a virtual method

modest dust
#

If it's in awake then just as Carwash said ^

#

virtual, override, call base and then do your stuff

hexed terrace
#

protected void virtual Awake() { }

and then in your Zombie class, override it

protected void override Awake() 
{ 
  base.Awake(); 
  // other code
}```
mild mortar
#

Oh okay, thanks a ton guys!

mild mortar
modest dust
#

Yeah, then do as Carwash said

mild mortar
# modest dust Yeah, then do as Carwash said

So just something as simple as this?

public class Zombie : Hostile
{
    private float sightRange = 15;
    protected override void Awake()
    {
        if (lineOfSight != null)
        {
            lineOfSight.distance = sightRange;
        }
    }
}```
#

Gonna remove the if check now

languid spire
modest dust
#

You forgot the base call

mild mortar
#

Oh right yeah

#

My bad

#
protected override void Awake()
    {
        base.Awake();
        lineOfSight.distance = sightRange;
    }
#

Like this?

modest dust
#

Try it out

mild mortar
#

No luck
"Zombie.cs(10,29): error CS0115: 'Zombie.Awake()': no suitable method found to override"

distance within lineOfSight is just a getter/setter if that matters

languid spire
modest dust
#

Show your Hostile class, the Awake method needs to be marked as virtual

mild mortar
#
protected virtual void Awake()
    {
        stateMachine = new EnemyStateMachine();
        idleState = new EnemyIdleState(this, stateMachine);
        chaseState = new EnemyChaseState(this, stateMachine);
        attackState = new EnemyAttackState(this, stateMachine);
        navigation = GetComponent<Navigation>();
        lineOfSight = GetComponent<LineOfSight>();
        stateMachine.Initialize(idleState);
    }
#

Huh, just hit play again, it works now.
No worries then

#

Guess it didn't update the file properly

#

Thanks again guys

#

Hmm, actually, there's something I'm still missing somewhere I think
Doesn't seem as though that distance is changing on play.
The vision cone remains the same even though I am overring 🤔

safe radish
#
{
    private VoxelData voxelData;

    private void Start()
    {
        voxelData = NewChunkManager.Instance.GetVoxelData();
       
        if (voxelData == null)
        {
            Debug.LogError("voxelData is null");
        }
        else 
        {
            Debug.Log("voxelData is not null");
        }

    }   

    public void GenerateVoxelMesh()
    {    
                    VoxelCell cell = voxelData.GetCell(x + chunkCoord.x * chunkWidth, y, z + chunkCoord.y * chunkDepth);```  my voxelData.GetCell is giving me a null reference. im getting the voxelData from my manager instance, can i not use .GetCell on it from this script or is there something else going wrong?
#

i got the debug.log that it is not null

modest dust
#

When do you call GenerateVoxelMesh()

safe radish
#

its in the generate chunks method

modest dust
#

Then show the GenerateChunk() method instead.

safe radish
#
    {
        ClearChunks();

        int chunksX = gridSize.x / chunkWidth;
        int chunksZ = gridSize.z / chunkDepth;

        chunks = new NewChunk[chunksX, chunksZ];

        for (int x = 0; x < chunksX; x++)
        {
            for (int z = 0; z < chunksZ; z++)
            {
                Vector2Int coord = new Vector2Int(x, z);
                GameObject newChunkObj = new GameObject("Chunk_" + x + "_" + z);
                newChunkObj.transform.parent = this.transform;

                NewChunk newChunk = newChunkObj.AddComponent<NewChunk>();
                newChunk.Initialize(coord);
                newChunk.GenerateVoxelMesh();
                newChunk.UpdateMesh();

                chunks[x, z] = newChunk;
            }
        }
    }```
modest dust
#

Just replace Start() with Awake()

#

In the NewChunk class

safe radish
modest dust
#

But it wouldn't be a bad idea to just pass the voxel data in the GenerateVoxelMesh() method

#

Instead of getting it through a static instance in Start/Awake

mild mortar
#

Anyone know how to get rid of this error?

NullReferenceException: Object reference not set to an instance of an object
UnityEditor.Graphs.Edge.WakeUp () (at <f94752164e14499c83c250d9839d9e96>:0)

I thought restarting Unity would do it, but it just never leaves

verbal dome
#

Can try to reset your layout and see if it helps

mild mortar
#

No way to set an ignore for that particular error I imagine?

verbal dome
#

Did you clear the console though?

mild mortar
#

I did yeah

verbal dome
#

What is your unity version?

gilded kiln
#

Okay guys i have a big problem, my unity wont launch

#

Yesterday it worked

#

I have no idea for what it doesn't work today

#

I must work rn but I can't omg

eager spindle
#

well we dont know why your unity isnt launching either

#

got a screenshot?

#

@gilded kiln

#

usual tech questions: have you tried restarting your pc, reinstalling unity, did you do any funky stuff with your project files?

gilded kiln
#

No I do nothing wrong with Unity

eager spindle
#

do you have a screenshot of what happens when you try to boot up unity

gilded kiln
eager spindle
#

unity hub or unity editor?

gilded kiln
#

And I think I can't take a screenshot of nothing lmao

gilded kiln
eager spindle
#

uninstalling hub shouldnt remove editor

gilded kiln
#

I know how to start Unity I do it a lot of time

eager spindle
#

plus you might be able to start editor without hub

gilded kiln
eager spindle
#

C:\Program Files\Unity\Hub\Editor\2022.3.19f1\Editor
this brings me here, theres a unity.exe you can use

#

change the version accordingly

#

dumb plan but yeah

#

secondary plan is to find out directly whats wrong with unity hub by launching unity hub from a command line

#

but theres a point where you just reinstall unity hub

#

on a differrent note is unity hub installed on a different drive?

gilded kiln
#

No it's not working

#

Nothing work

#

OMG i think i will reinstall

#

LMAO

#

The first worked but the second not

late burrow
#

my class has implicit string conversion, why cant i string.join it?

late burrow
#

i dont seem be able write conversion for class array only for class

slate haven
#

I have written a code for facing the player in the direction it moves, but it behaves very weirdly and causing the player to move in unwanted directions. Please help!

    {
        PlayerControls();
       
    }

    void PlayerControls()
    {
        float xInput = Input.GetAxis("Vertical") * moveSpeed * Time.deltaTime;
        float yInput = Input.GetAxis("Horizontal") * moveSpeed * Time.deltaTime;
        playerTransform.Translate(xInput, 0, -yInput);
        


        //for rotation
        Vector3 direction = new Vector3(xInput, 0, -yInput);
        playerTransform.forward = Vector3.Slerp(playerTransform.forward, direction, Time.deltaTime);
        
    }```
amber nimbus
#

Hello, I was wondering, where should I declare interafaces. For example if I have an IDamageable interface I would use it in my Enemies script, my Players script and any items that could be damagable. Do I declare it in one of the objects scripts? Should I have one big script for just declaring different interfaces?

slate haven
cosmic dagger
#

All of your types should be in their own script . . .

slate haven
amber nimbus
#

So each new interface I make should have a different script?

slate haven
amber nimbus
cosmic dagger
slate haven
#

if u can imagine that

slate haven
#

not face the direction it moves

amber nimbus
late burrow
#

why cant i write operator for class array error says i must convert from exact type and its array fails to count as one

safe radish
#
    {
        ClearChunks();        
        chunks = new NewChunk[numberOfChunksX, numberOfChunksZ];

        for (int x = 0; x < numberOfChunksX; x++)
        {
            for (int z = 0; z < numberOfChunksZ; z++)
            {
                Vector2Int coord = new Vector2Int(x, z);
                GameObject newChunkObj = Instantiate(chunkPrefab);
                newChunkObj.name = "Chunk_" + x + "_" + z;
                newChunkObj.transform.parent = this.transform;    //< This line gives the error

                NewChunk newChunk = newChunkObj.GetComponent<NewChunk>();
                if (newChunk == null)
                {
                    newChunk = newChunkObj.AddComponent<NewChunk>();
                }

                Vector3 chunkPosition = new Vector3(coord.x * chunkWidth * scale, 0f, coord.y * chunkDepth * scale);
                newChunkObj.transform.position = chunkPosition;

                newChunk.Initialize(coord);
                newChunk.GenerateVoxelMesh();
                newChunk.UpdateMesh();

                chunks[x, z] = newChunk;
            }
        }
    }```  im getting these warnings but no errors
slate haven
amber nimbus
slate haven
#

like in this it didnt subtract the target and transform position

slate haven
amber nimbus
polar acorn
slate haven
#

like direction.normalize

late burrow
#
    {
        public static implicit operator string(test[] thing)
        {
            return "";
        }
    }```
#

cant use array

polar acorn
#

So you're trying to cast an array of test to a string? That's not going to work. You can't implicit something that isn't this type

#

test is not test[]

late burrow
#

well idk whats difference can use explicit as well

#

i just want convert it to string without additional functions

late burrow
#

because messy

polar acorn
#

What's the problem with public string SomeFunction()

polar acorn
#

This is unfathomably more messy

#

than just having a function that returns a string

late burrow
#

having 20 functions for conversions is not cool and when i found out about implicit its amazing

#

just it dont work for arrays for some reason

#

even chatgpt says it supposed to work

amber nimbus
languid spire
#

oh, well if gpt say so it must be wrong

polar acorn
polar acorn
late burrow
#

and i cant define class of test[] either

polar acorn
polar acorn
late burrow
#

i cant literally do anything with arrays

polar acorn
#

so stop trying to use implicit here

#

It's a bad plan to make bad code for no reason

slate haven
# amber nimbus I do not think it would work, normalizing changes the length of a vector, not it...
    {
        float zInput = Input.GetAxis("Vertical") * moveSpeed * Time.deltaTime;
        float xInput = Input.GetAxis("Horizontal") * moveSpeed * Time.deltaTime;
        playerTransform.Translate(xInput, 0, zInput);
        


        //for rotation
        Vector3 direction = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
        playerTransform.forward = Vector3.Slerp(playerTransform.forward, direction.normalized, Time.deltaTime * 10f);
        
    }

I did this, now the player looks in the direction I move, but now my movement is messed up, like it wont move in the same direction when I added the rotation logic

slate haven
late burrow
#

well it wrote entire server for webpage for me so

amber nimbus
slate haven
polar acorn
slate haven
#

Vector3 direction = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
I did input the actual values without multiplying speed but still the same problem

amber nimbus
#

Beacuse I think in your zInput you forgot the negative sign

slate haven
#

its like combining the rotation with movement

#

so If I press W for instance, it starts revolving or some shit

amber nimbus
amber nimbus
#

The transforms are applied in local space, this means that they are affected by your players rotation

#

Which means that as your player rotates it tries to go forwards, where the player rotated

slate haven
#

yes

#

so what do i do?

amber nimbus
#

you need to set the relativeTo parameter (which is optional) to world

#

It is written in the documentation I showed you above

slate haven
#

than it shall be

slate haven
polar acorn
#

Stop trying to use your fancy new hammer on every fixture in the house. Sometimes, you're gonna need a screwdriver

late burrow
#

bruh i tried to use string.join in the first place and its not able convert it to string

#

that why i wanted implicit cast

amber nimbus
# slate haven i will read it

If you dont want to mess around with local and world space, transform.position is always in world space, meaning you can also replace playerTransform.Translate(xInput, 0, zInput) with playerTransform.postion += new Vector3(xInput, 0, zInput)

polar acorn
#

If not, then you can use Linq to map ToString over it

late burrow
#

i do have it

#

and string join still fails to convert

polar acorn
amber nimbus
late burrow
#

ambiguous call

late burrow
#

i can type its class but then it just prints class name without actual data

summer stump
slate haven
late burrow
#

The call is ambiguous between the following methods or properties: 'string.Join(string, params object[])' and 'string.Join<T>(string, IEnumerable<T>)'

summer stump
#

Ok, perfect. So it IS able to, you just made a mistake. Show exactly what you wrote

polar acorn
#

It's unsure if you want to pass in the list as a list or as params, so it's ambiguous

#

you don't need implicits at all

#

You just need to tell it "No this is supposed to be a completed list, not params"

#

See how easy it is to fix when you actually give us the fucking information as to what you are doing

late burrow
#

noone mentioned object array conversion till now

polar acorn
#

Turns out this whole time it was a stupidly simple solution and you just kept stepping on rakes because you assumed we "didn't need to know what you were trying to do" to help

#

well fuckin look at that, turns out once we did get it it was an easy problem

late burrow
#

i havent touched arrays till now implicit cast for type is still useful

#

just arrays were issuing

polar acorn
late burrow
#

though i see object[] cast still doesnt solve issue

polar acorn
late burrow
#

its logs as script+test

#

still not loggingg data just the type name

polar acorn
#

Does your test class have a ToString?

late burrow
#

no

polar acorn
#

The default ToString of every object is just their name

late burrow
#

why doesnt it use implicit

polar acorn
#

so if you want it to do something different, you have to have told it to do that

polar acorn
#

Every object has ToString. That is, in fact, one of the only things that can be said of the type object. That's just about the only shared function on it

#

So you've been spiraling into madness when the solution was ToString and casting to object. Something that basically anyone on this server could have answered in five minutes if you had actually said what you were trying to do from the beginning

olive lintel
#

hey guys, pretty embarrassing but for some reason visual studio doesn't seem to reference exceptions? I'm not quite sure whats going on. I put "NullReferenceException" in the catch statement and it doesn't even seem to recognise the syntax for it. Does anyone know what I'm doing wrong here?

swift crag
#

What is the error?

olive lintel
olive lintel
#

oh wait

#

wow

swift crag
#

That is not an exception being thrown.

olive lintel
#

thats embarassing

languid spire
swift crag
#

At least, it doesn't have to be one.

#

You can write an error to the console with Debug.LogError.

olive lintel
olive lintel
#

thanks guys that was confusing me for a while 😭

swift crag
#

Figure out where the NaN is coming from when calculating the force.

west flax
#

@swift crag

#

Omg I forgot to commit the new changes

swift crag
#

is there a reason you're editing this on your phone...?

west flax
#

I don't have discord on my laptop

olive lintel
#

which has me super confused

west flax
#

Under axis.Normalize(), I added axis*=Math.Deg2Rad;

swift crag
#

perhaps the wheel has already gone to space, so that transform.forward is full of NaNs

swift crag
#

you convert the angle, not the axis..

west flax
#

Oh my god lmfao

#

That's funny as hell

#

I'm an idiot xD

swift crag
#

That will slow you down

#

you should ask about the problem code first next time :p

west flax
#

I wasn't thinking about how it interacted with the code, just the results.

#

That's why I was confused.

olive lintel
swift crag
#

Just log all of the values.

#

Importantly, I don't think float.NaN compares equal to anything

#

You'd have to use float.isNaN()

west flax
#

Are you multiplying by excessively high numbers?

olive lintel
#

it was the wheel.thrust value

#

I'm not quite sure what is making it NaN I think the engine simulation thingy needs a frame at the start

#

it accounts for the velocity of the previous frame etc etc

#

I see now

#

thank you very much

hushed hinge
#

I have a problem that when I pause the game to change the volume by using the slider in unity, when I turn down the volume, and after I unpause to resume the game, the volume changes bak to full when I move the player to the right, and the volume turns down when I move the player to the left, by using the "a" button for moving left and the "d" button for moving right, that only happens when I pause the game to change the volume, how do I fix that so the volume doesn't change when I move the player?
this is the volume setting
https://gdl.space/ahujifaced.cs

and the pause script

https://gdl.space/delixivuze.cs

slender nymph
#

your slider is still selected by the EventSystem because you aren't setting the canvas's GameObject inactive, you just disable the canvas component. so either set the currently selected gameobject to null in the EventSystem or completely disable the object(s)

mild mortar
#

Am I blind? Unity is giving me this error:
error CS0122: 'State.lineOfSight' is inaccessible due to its protection level

It's inheriting a protected so it should have access right?

public class State : MonoBehaviour
{
    public LineOfSight lineOfSight;
    private void Awake()
    {
        lineOfSight = GetComponent<LineOfSight>();
    }
    public virtual State Tick(StateManager stateManager)
    {
        return this;
    }
}
public class IdleState : State
{
    PursueState pursueState;
    [Header("Detection Layer")]
    public bool hasTarget;

    private void Awake()
    {
        pursueState = GetComponent<PursueState>();
    }
    public override State Tick(StateManager stateManager)
    {
        if (lineOfSight.objects.Count > 0)
        {
            return pursueState;
        }
        else
        {
            return this;
        }
    }
}```
slender nymph
#

have you saved the State class

hushed hinge
sharp abyss
#

I'm making a 2d football game. When characters hit the ball it never goes up when its on the ground what can I do about that?

slender nymph
mild mortar
languid spire
mild mortar
#

Okay, I restarted Unity twice and now it works all of a sudden
First restart still had the problem

mild onyx
#

what am i doing wrong here? im trying to click the text and have it take me to another scene (the game)

swift crag
#

add a Debug.Log statement to find out if the function is being called at all

mild onyx
#

from what ive seen its not acting like a button at all, my curser doesnt change when i hover over it and the colours dont change, neither of which are even in the code

fading seal
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class bedScript : MonoBehaviour
{
    public GameObject inticon, bed, bedText;
    
    
    void OnTriggerStay(Collider other){
        if(other.CompareTag("MainCamera")){
            inticon.SetActive(true);
            if(Input.GetKey(KeyCode.E)){
                bedText.SetActive(true);
                bed.SetActive(true);
                inticon.SetActive(false);
            }
        }
    }
    void OnTriggerExit(Collider other){
        if(other.CompareTag("MainCamera")){
            bedText.SetActive(false);
            inticon.SetActive(false);
        }
    }
}```  how can i get my dialogue to look like this?
languid spire
polar acorn
slender nymph
fading seal
mild onyx
polar acorn
#

Third one, it's a checkbox on all UI renderer components like your TMP Text

mild onyx
swift crag
#

Not on the button.

#

Somewhere in the scene.

#

You can search the hierarchy for t:eventsystem

languid spire
mild onyx
polar acorn
languid spire
#

yep, no event system, add one

swift crag
#

you can find a template in the GameObject > UI menu

polar acorn
#

GameObject -> UI -> Event System

#

It gets created automatically when you add your first canvas, it's important, don't delete it

hushed hinge
mild mortar
#

Trying to work with a simple state machine, currently getting a consistent error message of NullReferenceException: Object reference not set to an instance of an object
IdleState.Tick (StateManager stateManager) (at Assets/Scripts/Enemy/IdleState.cs:15)
which is this

if (lineOfSight.objects.Count > 0)
Anyone have any ideas? Not sure what I'm missing

using UnityEngine;

public class State : MonoBehaviour
{
    protected LineOfSight lineOfSight;
    private void Awake()
    {
        lineOfSight = GetComponent<LineOfSight>();
    }
    public virtual State Tick(StateManager stateManager)
    {
        return this;
    }
}
using UnityEngine;

public class IdleState : State
{
    PursueState pursueState;
    [Header("Detection Layer")]
    public bool hasTarget;

    private void Awake()
    {
        pursueState = GetComponent<PursueState>();
    }
    public override State Tick(StateManager stateManager)
    {
        if (lineOfSight.objects.Count > 0)
        {
            hasTarget = true;
            return pursueState;
        }
        else
        {
            return this;
        }
    }
}
slender nymph
#

i'm guessing line 15 of IdleState.cs is that if (lineOfSight.objects.Count > 0) since you don't assign to lineOfSight with that class?

languid spire
mild mortar
languid spire
#

you could have just searched this discord

mild mortar
#

I lost a bit more than just that one bit, so it slipped my mind

languid spire
#

amazing, it didn't slip mine and it's not my code

idle ginkgo
#

what does this new keyword do?

#

i dont get it

slender nymph
#

the new operator is used to invoke an object's constructor. which creates an instance of that object

languid spire
summer stump
# idle ginkgo

Vector3 is an object (a struct specifically)
You are creating one (as the others said) with the values you want.

fading seal
#

how can i use a script inside of another script

polar acorn
#

Are you talking about referencing?

fading seal
polar acorn
fading seal
slender nymph
#

all of your components will be attached to gameobjects

fading seal
#

nvm

dense root
#

!code

eternal falconBOT
tiny schooner
#

hello guys

#

i have a problem

#

everytime i write a code in visual studio it appears in unity like nothing happened

slender nymph
#

it appears in unity like nothing happened
what do you mean by this

tiny schooner
#

i make a new script

#

i write my code

#

i finish

#

i go to unity

#

i dont see my work

slender nymph
#

please fucking finish a thought before pressing enter

slender nymph
# tiny schooner i dont see my work

and again, this is not clear what you mean. provide some actual details about what you are talking about. do you mean that the code just doesn't work? or do you mean that you didn't bother saving the code so unity does not see the changes to the file and has not attempted to compile it

tiny schooner
#

i mean when i finish a code on visual studio and click save then go back to unity i see the code but i cant drag stuff to the code

#

idk how to say it tbh

swift crag
#

you can't "drag stuff to the code"

frosty hound
#

Do you have compiler errors?

tiny schooner
#

no

swift crag
#

so i really do not understand what's going on here

swift crag
tiny schooner
#

i can't send here for some reason

#

come dm

#

@swift crag

swift crag
#

You can send screenshots in this discord server.

#

so I don't know what you did wrong

tiny schooner
#

oh it js worked

swift crag
#

Your console window is not open.

gaunt ice
#

there should be a compilation error

#

at least one

swift crag
#

You are currently selecting a script asset. You can't do anything with this. You need to actually add the component defined by the script asset to an object if you want to assign things in the inspector.

#

That's my best guess of your problem right now, assuming you don't have a compile error.

slender nymph
#

those serialized fields would actually show up there if they didn't have compilation error(s)

swift crag
#

true

tiny schooner
#

how do check if i have errors?

rocky canyon
#

Console

slender nymph
#

look at your console. and also make sure that your !IDE is configured

eternal falconBOT
swift crag
#

Click on the tab.

rocky canyon
#

compile error should show as a Red error.. or sometimes a Popup window directly telling u

tiny schooner
#

oh

#

i do have an error

slender nymph
#

yes we saw that from the code you shared

rocky canyon
#

lol

tiny schooner
#

lmao sry

#

im new

rocky canyon
#

dont be sorry for learning something new 😉

tiny schooner
#

thx man

swift crag
rocky canyon
#

this no ones judging you for getting familiar and learning the editor

tiny schooner
#

ok thank you guys ill learn how to remove the error from google or yt

slender nymph
#

you can fix the error by getting your IDE configured then re-typing that line since you'll have auto complete preventing you from making silly spelling mistakes

swift crag
slender nymph
#

CS0246: The type or namespace collider could not be found (are you missing a using directive or an assembly reference?)

summer stump
#

Accessing the TYPE Transform on line 12, and perhaps trying to get a reference to transform from player (which is already a transform) are two that I see

slender nymph
#

ah yeah that one too

summer stump
#

C# is case sensitive
Things being capitalized or not make them quite different

slender nymph
#

gonna be honest, i completely missed the second one

swift crag
#

your IDE should be highlighting all of these errors for you

summer stump
rocky canyon
#

in ur face kinda squigglies.. make the world a better place

#

and all is right in the world lol

west sonnet
#

How can I do a 'While' loop in Unity?

#

People don't seem to like using 'while' with unity

languid spire
#

what?

while (condition) { }
swift crag
#

you use it exactly like you would anywhere else

#

I have fewer of them than foreach loops, sure

#

I use them when I need to do something until a condition is no longer true.

west sonnet
#

So when would you use a CoRoutine and not a while loop?

swift crag
#

those are two unrelated concepts

west sonnet
#

I'm trying to slowly change the size of a box collider over a period of time. Would a while loop or CoRoutine be better?

polar acorn
swift crag
#

again, two unrelated concepts

languid spire
#

generally you would use a while inside a coroutine. With a yield in the whille

swift crag
#

a coroutine lets you run code that spans several frames

polar acorn
#

All loops always run to completion.

west sonnet
polar acorn
#

It's a loop

swift crag
#

vitally, no code ever has the concept of running "over time"

polar acorn
#

it runs until the condition is false

swift crag
#

including code inside a coroutine

#

it's not like there are a thousand little virtual machines all running a single script's code, running in parallel

#
while (true) {
  // ...
}
#

if you hit this code, your game freezes

#

(assuming that nothing happens to make you exit that loop)

summer stump
# west sonnet Couldn't a while loop do that too?

A while loop will run as fast as possible if you don't do it in a coroutine or some other asynchronous method

Coroutines and while loops are not different ends of the same spectrum. They are completely different, and should not be compared the way you are

swift crag
#

to clarify: it takes zero in-game time for the code to run. Time does not pass at all in the game as your code is running.

#

it's not that the while loop runs really really quickly

#

it's that nothing else happens while your code is running

#

Unity makes a gigantic to-do list of every single thing it needs to run per frame, then runs through it in order

west sonnet
#

!code

eternal falconBOT
west sonnet
#

What am I doing wrong here? The code seems to go on forever until the collider is flat

polar acorn
#

so I'm not sure what you're expecting to happen

west sonnet
#

I'm trying to reduce the height of the collider

polar acorn
#

if that condition is true, it sets them to -0.1

#

then waits 2 seconds and checks again

west sonnet
#

Ok shit

#

how can I minus them by 1?

polar acorn
#

Subtract 1 from their current value

wanton kraken
#

yo, fellas. i'm working on a top-down tank game, and i'm having a good amount of trouble coding the cannon to stop rotating past a certain point. how would you guys go about it?

west sonnet
polar acorn
#

You're doing the math but not doing anything with it

west sonnet
#

minus them by 1 each frame

polar acorn
#

This is subtracting 1 from them. What do you want to do with that new value

west sonnet
#

Make that the new value of the collider size and offset

polar acorn
#

So do that. Set the collider size and offset to the new value

west sonnet
summer stump
#

You need to use an = somewhere in that line

polar acorn
#

You're doing subtraction and then not using that for anything

swift crag
#

C# forbids you from writing a useless statement like that, which is why it's giving you an error.

polar acorn
#

This isn't going to modify the variable. Numbers are passed by value, it's going to give you the value that is 0.1 less than size.y

swift crag
#

For example, 4; is an invalid statement

west sonnet
#

This is correct, right?

thin river
#

Hello when I decide to use DOTS - does it mean - that all parts - that needs to communicate with each other - must be also converted (baked) to ECS.

For example:
I have Camera and Character in my main scene - and One Entity that want to read data from that camera and character.
Does it mean - that I need to move and convert camera and character into Subscene (and therefore convert it to ECS) ? Or there is possibility to somehow read data from gameObject from main scene from subscene ISystem?

swift crag
#

You should ask about this in #1064581837055348857 -- but I'd say the answer is "no". You can pass information back and forth just fine.

polar acorn
thin river
west sonnet
#

Man, I hate IEnumerators 😄

#

but thanks for the help everyone

polar acorn
#

None of this had anything to do with IEnumerators

#

this was just setting a variable

west sonnet
#

I don't even know what I hate lol

summer stump
west sonnet
#

It would seem like it

fading seal
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class fridgeScript : MonoBehaviour
{
    public GameObject inticon, fridge, fridgeOpened, fridgeClosed;
    
    
    void OnTriggerStay(Collider other){
        if(other.CompareTag("MainCamera")){
            inticon.SetActive(true);
            if(Input.GetKey(KeyCode.E)){
                fridgeClosed.SetActive(false);
                fridgeOpened.SetActive(true);
                fridge.SetActive(true);
                inticon.SetActive(false);
            }
        }
    }
    void OnTriggerExit(Collider other){
        if(other.CompareTag("MainCamera")){
            inticon.SetActive(false);
        }
    }
}``` how can i make the fridge close if i press e again
polar acorn
#

Instead of setting each object to specifically true or false, set it to whatever value it currently isn't

polar acorn
polar acorn
#

yes

fading seal
#

no i dont think then

polar acorn
#

Next: Do you know how to invert a boolean?

fading seal
#

no

polar acorn
#

Now you know. Put those all together and you have the recipe to toggle an object instead of setting their SetActive to a specific value

fading seal
#

i dont get what any of those sites mean

polar acorn
#

It's called "documentation" and you're gonna need to get used to reading it

#

because that's like 60% of what programming is

summer stump
fading seal
summer stump
fading seal
summer stump
#

The dot before an item in a list

fading seal
fading seal
summer stump
fading seal
polar acorn
#

That's why I linked it

#

because it explains things

fading seal
#

ok i read it

#

now what

fading seal
summer stump
#

Using what you learned to negate the current value of the bool

summer stump
polar acorn
fading seal
polar acorn
fading seal
polar acorn
#

you're supposed to read it

#

and see how it works

#

and apply it to your own project using a thing we like to call "thinking"

fading seal
summer stump
polar acorn
#

You currently know:
A) How to set an object's active state to a boolean
B) How to invert a boolean
C) How to get the object's current active state as a boolean

From there, it should be straightforward to:
Set the object's active state to the inverse of its current active state

summer stump
#

Google more examples if needed

fading seal
polar acorn
fading seal
#

what does "console" mean

summer stump
polar acorn
#

and has absolutely nothing to do with anything right now

modest dust
#

I feel like there's a severe lack in general C# programming knowledge and that should be dealt with before even coming near Unity

polar acorn
summer stump
#

The example is meant to show you how to use !
That is the important part here

fading seal
polar acorn
#

Specifically

#

A, B, or C

summer stump
modest dust
#

Honestly, depending on the course, you not only learn programming but it also changes your mindset on how to approach different problems

fading mountain
#

I recommend taking gamedev.tv's unity2d C# course on udemy

river quiver
#

i want to check with the if function if the System.DateTime.Now.Hour which returns current hour is later than hour 21

#

is it like a special boolean or something?