#💻┃code-beginner

1 messages · Page 754 of 1

sand dagger
#

and what do I do with "var number in _numbers" in the foreach?

rich adder
#

similar to a for loop except you dont iterate with an index

#

some basic c# courses would probably do you good here tbh

sand dagger
#

Okay so uh

#

Visual Studio seems to be dying

rich adder
#

you wrote some nonsense and crashed your intellisense xD

polar acorn
sand dagger
#

Great question

#

Nav, why am I trying foreach

rich adder
#

idk cause you're copying blindly lol

polar acorn
sand dagger
#

I'm doing what y'all are telling me

polar acorn
#

Why are you using foreach

sand dagger
#

I have no idea, it was suggested, so I'm using it

polar acorn
#

Why are you looping over anything?

rich adder
#

we're just showing example what each thing does, you don't have to copy every line to shuffle it randomly around

#

if you only need to do something once, there is no need for loops..

polar acorn
#

You should actually try to learn what these functions and keywords mean

#

I sent you the documentation for foreach

rich adder
#

I should've used explicit types to not confuse things more var 🥲

polar acorn
#

You should learn what it means

rancid tinsel
#

how do you do this? I know there should be some way of extracting stuff from the interface object but I can't remember how

#

EntityHealth implements IEntity

#

wait no it doesn't ignore me

#

rubber ducky moment

naive pawn
#

also consider entity is EntityHealth healthComponent as a condition

rich adder
#

defensive coding standards

rancid tinsel
naive pawn
#

what does the error say

rancid tinsel
#

turns out I got my classes confused, EntityHealth doesn't implement IEntity

#

it was a different one

naive pawn
#

yeap make sure to actually read the errors

#

if it's a syntax error, you wrote it wrong

rancid tinsel
#

this, but yeah it's literally just because the class never implements the interface 🤣

naive pawn
#

if not, you're using it wrong

rich adder
#

jfc

gaunt pasture
#

can somebody help me on what this is?

rich adder
#

bro really posted a mobile screenshot of GPT code

naive pawn
#

what what is, exactly?

rich adder
gaunt pasture
naive pawn
#

don't use genai

#

it is a bullshit generator

rich adder
gaunt pasture
rich adder
#

though take the info with a grain of salt 🤷‍♂️

naive pawn
#

and then pray you hit the 50/50 that it isn't lying

gaunt pasture
rich adder
gaunt pasture
#

Ok

polar acorn
#

It appears to be a screenshot of code

#

hope this helps 👍

gaunt pasture
#

Yooo can somebody help me make this game? DM it’s for VR

polar acorn
#

No

radiant voidBOT
# naive pawn !collab

:loudspeaker: Collaborating and Job Posting

We do not accept job or collab posts on Discord.
Please, use Discussions to promote yourself as job-seeking, advertise commercial job offers, or look for non-commercial projects to participate in:
• ** Collaboration & Jobs**

gaunt pasture
#

Am ok

naive pawn
#

if you have specific questions you need help with, you can ask in the appropriate channels. but don't come here with genai as a source lmao

gaunt pasture
young marten
#

I need to reference UnityEngine.CoreModule to allow for this line:

if (PerkMemory.lastGeneratedPerk != null)

to work. because It references a scriptable object.

Doing so causes:

Debug.Log($"Test1");

To throw an error because "Debug" Exists in both UnityEngine and UnityEngine.CoreModule.

So I'm in kind of a loop where;
If I have "using UnityEngine;" At the top of my cs file it causes mentioned error. Removing it causes Debug to "not exist".
In my csproj file I added a reference to UnityEngine.CoreModule. Removing it fixes the duplicate issue but then my if statement doesn't work as it references a scriptable object.

Lost on what to do

#

here's the proj file. I'm just building off the template plugin bepinex has in it's documentation

#

If you need any specific information from the plugin file just lmk

young marten
#

I tried that already, tbh I'm kinda stumped why that doesn't work

polar acorn
#

What does the error say when you use it

young marten
#

Debug.Log
&
UnityEngine.Debug.Log

Give the same error
CS0433: The type 'Debug' exists in both 'UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' and 'UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'

polar acorn
#

Okay so this isn't some basic IDE ambiguity, this is actually the same namespace in both which is a problem. Why do you need CoreModule? From looking at it, it should just be included

young marten
#

Removing:
<Reference Include="UnityEngine.CoreModule">
<hintpath> [Truncating for brevity]</hintpath>
</Reference>

From the csproj file causes the following error:
CS0012: The type 'ScriptableObject' is defined in an assembly that is not referenced. You must add a reference to assembly 'UnityEngine.CoreModule, Version=0.0.0.0,

polar acorn
#

Unity generates that

young marten
#

I am not making a unity game directly I am making a mod for a game that I only have decompiled. I am sorry I didn't mention sooner. The game is White Knuckle.

polar acorn
#

We don't do mods here

young marten
#

weird

polar acorn
#

specifically because they impose these kinds of nonsense problems that never come up in normal unity contexts

young marten
#

Ah.

reef dirge
#

I wanted to get into Unity so I could make a 2d turn based strategy game, any advice for the first things I should be doing?

radiant voidBOT
reef dirge
#

I'll check that out, thanks

#

anything in particular that I should look at?

rich adder
#

start with essentials then junior programming etc.

reef dirge
#

Alright, how long should getting through this take..? I know it all takes time, but I am generally someone that lacks motivation, so I'm running purely on willpower to make this game

rich adder
#

no idea. that depends on you

solar hill
#

game development requires a lot of motivation

#

imo

reef dirge
#

I get that

solar hill
#

especially when it comes to learning

rich adder
#

normally I'm motivated by learning something new then put it into reality

reef dirge
#

I guess my motivation would just be that I want to make this concept for a game actually real

solar hill
#

yeah but

#

do you have any prior game dev experience?

rich adder
#

learn more generalized concepts for your project instead of trying to do it all at once

solar hill
#

if you have prior experience you could immediately start working on your game right off the bat once you familiarize yourself with unity

reef dirge
#

Barely any, I did some stuff with scratch.

I am pretty good with ideas and thinking of what to do, but my actual technical skills like coding and stuff are poor

solar hill
#

but otherwise youre going to need to learn some fundamentals

rich adder
#

learning c# is already its own thing, throw Unity and its concepts ontop of that.. there is a LOT to do

solar hill
#

yeah

reef dirge
#

I tried getting into Luau a while back, but got over it since my friends who were supposed to help me with the game gave up

reef dirge
#

I'm guessing making this game would probably take like... 2 or 3 years if im lucky

solar hill
#

depends on the scope

rich adder
#

learn pathways will give you a little taste of what the processes are

reef dirge
solar hill
#

legends of runeterra?

reef dirge
#

Not as big of, or as high quality of a story, but something similar to it

reef dirge
#

Turn based strategy, story driven game

solar hill
#

well both of those things are 2 seperate beasts to conqure

reef dirge
#

Yeahhh

solar hill
#

you should start working on a basic strategy system, tinker with that and then see what you can do with it

reef dirge
#

The only leg up I have at the moment is knowing what I want for the game design

solar hill
#

after you go over the fundamentals

reef dirge
solar hill
#

i mean thats nice but its pretty much useless right now, because you dont actually know yet what you can pheasibly do

reef dirge
#

True

solar hill
#

i say focus on the fundamentals and try and tinker with individual systems, start very small and see where you end up

#

you never know what this concept might later turn into

#

it could be something completely different, for better or for worse

#

most game design docs dont get realized until some development overhead was made

reef dirge
#

Yeah, that makes sense.

solar hill
#

its rare for someone to hit the ground running with a fully realized concept because its pretty common that you will hit roadblocks you cant overcome meaning you will have to adapt, and so will your idea

reef dirge
#

The biggest issue will be incorporating gun mechanics. As I plan for different guns to have unique functions

solar hill
#

thats something a lot more specific

#

but trust me as you learn the basics the knowledge for creating the more complex systems will come to you naturally

#

good luck :)

reef dirge
reef dirge
red shore
#

eyy anyone that could help me with this im trying to make so u can cut down tree and after it falls to cut it even more for smaller pieces and stuff but im stuck haha

rich adder
#

generally:
make two version of tree, one solid
another with already chopped pieces / possibly physics based (hidden/disabled)
when you chop it down, activate the second version

red shore
#

ye so i made it kinda work when u start chopping a line appears on faces of tree (its just cube for now but im thinking of sticking for cubed trees and lowpoly) that line is like progress bar fills as u chop when u chop tree falls stump appears down but when i try to cut on smaller pieces that fallen tree those lines arent coming or arent on tree good positioned

solar hill
#

sounds like a more technical question then

#

can you show us the function you use to create those "lines"

radiant voidBOT
#
<:error:1413114584763596884> Command not found

There's no command called paste.

red shore
#

those lines are cubes that spawn around tree and scale to fill

rich adder
#

why not use decals ?

red shore
#

idk im new to this more complicated stuff haha it lets me cut down tree lines come stump spawns but doesnt let me cut it when its fallen and to split it (i also want to add to grab and lift up tree with press e to rotate it in air and stuff) https://paste.mod.gg/gewamtvblwxp/0 idk u can see code here

lucid prairie
#

Hi all - I'm trying to use the first person character set up from com.unity.charactercontroller. I've been following the get-started docs on it but having an issue of the character "falling through" the ground plane. The plane has a box collider as do the components on the first person character set up. I first person character set up is also a little above the plane. Any idea what could be causing the issue?

solar hill
#

does it maybe use some kind of ground check layer?

rich adder
solar hill
#

oh nvm

lucid prairie
solar hill
#

what tutorial has you using the character controller from the ecs package?

#

unless you think that page is the tutorial

umbral hound
#

What bin do you guys recommend for code dumps?

radiant voidBOT
rich adder
outer wigeon
#

Oh shoot sorry didn't notice this was the code specific channel - thought I was in the normal unity talk. Ty nav.

languid pagoda
#

is there a way I can get the dll generated from the assembly definition file copied to a specific path?

languid pagoda
teal viper
teal viper
#

Might need to hook to some editor events and do the copy in your code. On assembly reload or something.

languid pagoda
#

Would be awesome if they let us define post build cmds in the assembly definition file 😭

fierce shuttle
# languid pagoda the ones unity builds yes

AFAIK the Library folder is used for cache, nothing get built there - when you create a assembly definition file, it creates a .csproj file in the root of your project folder (just outside the "Assets" folder), where "Assembly-CSharp.csproj" exists and if you have editor scripts, "Assembly-CSharp-Editor.csproj" exists - those are what shows up in VS, unless your talking about a completely different file?

languid pagoda
#

I was just wondering if a copy to feature was built in

teal viper
#

UnityEditor.Compilation namespace, especially compilation pipeline class, contain events related to assembly compilation. You can hook to on assembly compilation complete, check the name of the assembly and do whatever you want from there.

teal viper
fierce shuttle
#

Ah I see, that makes sense

normal copper
#

Good morning fair folk of the Unity persuasion 🌅 I've got a question regarding UI architecture and mindset.

I'm currently learning how to set up multiplayer functionality, and first iteration of the lobby functionality is done. Naturally, i want to see the results reflected in a basic UI. Now, i'm curious how you guys and gals think about your UI when you set it up. Do you make it a singleton and update it via events? Do you create different UI documents for different sections of the UI? For example, would you keep the UI doc for a "Inside Lobby" separate from one that handles, say, "Create Lobby"? I like singletons and events, but I would very much like to move towards more decoupled patterns. Now, UI might be one of those instances where a singleton fit like hand in glove, but even if i just think back on the last project i did, keeping the UI elements for the "Outside of game"-stuff in the same Visual Tree Asset as "Inside the game"-stuff quickly felt bloated.

Any pointers? 😄

floral garden
normal copper
#

Apologies, that was poorly worded. By outside, i mean the layout and controls you see before starting a game, such as a "Start Game" button, and the inside would be for example and NPC dialogue box. I'm not sure what the correct terminology is to differentiate between these two game states.

floral garden
#

oh i have never done ui for multiplayer but for solo
you can create a global struct then create Button function that link to your game (decoupled is good but not everything can be decoupled)
As multiplayer , you can try to preload the UI in async you will need like when I start game
preload ui for Start, Setting UI
then if I press Start -> change to UI
then preload Pause, setting , etc
This is what i would do if you don't want to preload all layer
But if you load all at once then
you can use a enum to know where you are in the UI

public enum ePanelType
{
    NOT_DEFINE,
    DIALOGUE,
    MAINMENU,
    HUD,
    SETTINGS,
    ENDGAME
}

Something like that and you setup all layer in dontdestroy
(ps: i am also a beginner , there must be better way)

tender mirage
#

I had to install the new visual studio since 2022 was retired but now my updates and awakes don't work!?

#

what do you mean, there's 0 references?!

#

it's an monobehavior

naive pawn
#

that's correct

tender mirage
#

it's just that it's greyed out.

naive pawn
#

you shouldn't be calling unity messages in your own code, so they shouldn't be referenced in your codebase

#

ah. ok, yeah that shouldn't be happening

#

!vs

radiant voidBOT
# naive pawn !vs
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)

naive pawn
#

make sure it's configured

tender mirage
#

that was the issue

sonic mesa
#

Hello, I've a question, today I start to code my item and inventory system so I start with Item system, first I've created scriptableObject ItemData and after 3 other class WeaponItem, QuestItem and ConsumableItem, inherited from the itemData class, after I'ce created the abstract class ItemEffect for create special effect for my Item, like healthEffect for potion, or chargeEffect for batterie etc etc, my question is : Do I create a class for each Item Effect, or do I create several functions where each function represents an effect in my ItemEffect class ?
What is your advice

wintry quarry
#

Just give ItemData a List<ItemEffect>

sonic mesa
#

Oh okay, and I create all the Item with the ItemData ?

tired python
#
public abstract class Shape
{
 public abstract float CalculateArea();
} 
public class Rectangle : Shape
{
 public float width;
 public float height;
 public override float CalculateArea()
 {
 return width * height;
 }
}
public class Circle : Shape
{
 public float radius;
 public override float CalculateArea()
 {
 return radius * radius * Mathf.PI; 
 }
}

instead of doing things like above, can't i just do it like this instead:

public class circle
{
    public int radius;
    public int GetArea()
    {
        return radius * 3.14F;
    }
}

public class square
{
    public int side;
    public int GetArea()
    {
        return side * side;
    }
}
#

I don't understand the benefit of having a base class which has an abstract method if you end up having to specify what the method has to do in the derived classes anyways

sour fulcrum
#

things that know about just the shape as a shape can call that function knowing some intentional implementation will exist

wintry quarry
#

You would need to write two functions, one for a square and one for a circle

tired python
wintry quarry
#

The abstract class eliminates that need

tired python
wintry quarry
#

If it's just based on the area, you can use the abstract GetArea function

sour fulcrum
wintry quarry
# tired python but i did do it though?

You had to write different GetAreas yes but code that depends on the area of a shape shouldn't have to care about what kind of shape it is. You don't want to have to write such code over and over for every shape

tired python
sour fulcrum
#

yes but the thing using the function doesn't need to know that

tired python
sour fulcrum
#

if you had eg.

Employee : class


abstract void DoWork()

there might be many different employees with many different representations of what DoWork should entail, but all employees do work. and if say a boss finds a Employee instance, it doesnt need to know if its a Cashier : Emplyoee, ShelfStocker : Employee etc. it just needs to know its an Employee for it to tell it to do work

tired python
#

i need an example to understand why it would be better to create an abstract class in such a scenario

thorn holly
sour fulcrum
#

abstract means "i dont know how your going to do this but you do need to do this". it's basically a promise

thorn holly
#

You can also just make a variable with the type Shape that can hold any type of shape and then call any Shape method, specific to the type of shape it’s holding

sour fulcrum
#

another random example is if i had a bunch of random toy wooden shapes in a big box

#

and i wanted to iterate over them to find the biggest one

#

i dont need to know if the Shape is a Cube or Sphere because i can just get the GetArea() function knowing whatever it is will give me the right answer

#

but that shape does need an answer to that question in order for it to be a valid shape

wintry quarry
#

n * the work instead of n * m times the work

tired python
#

could one of you code out the main part of the code? i think i will be able to understand why your points are valid if you do so

tired python
wintry quarry
# tired python i need an example to understand why it would be better to create an abstract cla...

With abstract parent (just a single function that works for all shapes):

float CalculatePaintAmount(Shape shape) {
  float area = shape.GetArea();
  return area * PaintPerSquareMeter;
}```

Without (You need a separate function now for each shape):
```cs
float CalculatePaintAmount(Square s) {
  float area = s.GetArea();
  return area * PaintPerSquareMeter;
}

float CalculatePaintAmount(Circle c) {
  float area = c.GetArea();
  return area * PaintPerSquareMeter;
}

float CalculatePaintAmount(Triangle t) {
  float area = t.GetArea();
  return area * PaintPerSquareMeter;
}
tired python
#

lemme try coding this out

scarlet pasture
#

Hey can sombody help me, i want to reference a Dust Particle from a Script. Everthing is working, but i wantet to programm a small fallback for a GameObject search. (just to get a better feeling of Getting Components etc.) but my Code cant find the Gameobject with the name "ShootDust": This is my Code private void InitliazeVFXShootDust() { if (VFX_ShootDust == null) { GameObject target = this.transform.GetComponentsInChildren<Transform>().Select(t => t.gameObject) .FirstOrDefault(go => go.name == "ShootDust"); } }

scarlet pasture
#

the Dust GameObject lies under the Player. i wanted to search throught every Transform and use the searchohne "ShootDust" and get his Component

wintry quarry
#

(This isn't good practice btw)

scarlet pasture
wintry quarry
scarlet pasture
#

palying the game, search in the Inspekor. it was empty and also the dust didnt Spawned

wintry quarry
scarlet pasture
#

it does, i search the Script Reference for the VFX Manager. It updatetet the Reference field in the Inspektor

wintry quarry
#

The code you showed simply creates and immediately discards a local variable

#

it cannot and will not be useful for any purpose the way you have written it

polar acorn
scarlet pasture
#

!Code

radiant voidBOT
scarlet pasture
wintry quarry
scarlet pasture
wintry quarry
#

InitThe InitliazeVFXShootDust() function does absolutely nothing of worth

wintry quarry
polar acorn
#

You didn't leave anything out you just simply are not doing that

scarlet pasture
wintry quarry
polar acorn
wintry quarry
scarlet pasture
#

yeah

scarlet pasture
wintry quarry
#

you would need to actually do VFX_ShootDust = something;

#

it you want to update that

#

this target variable is completely unrelated to it and will not affect it

polar acorn
scarlet pasture
#

hmmmm u right ofcors

wintry quarry
#

Notice for example this other function:

    private void InitliazeShootOringn()
    {
        if (shootOrigin == null)
        {
            shootOrigin = GetComponentsInChildren<Transform>().FirstOrDefault(c => c.name == "ShootOrigin");
        }
    }
tired python
# wintry quarry With abstract parent (just a single function that works for all shapes): ```cs ...
using System;
using System.Security.Principal;

public static class Shape
{
    public abstract float GetArea();    
}

public static class Circle : Shape
{
    public int r;
    public override float GetArea()
    {
        return r * 3.14F;
    }
}

public static class Square : Shape
{
    public int side;
    public override float GetArea()
    {
        return side * side;
    }
}

float CalculatePaintAmount(Shape shape)
{
    int PaintPerSquareMeter = 10;
    float area = shape.GetArea();
    return area * PaintPerSquareMeter;
}

public static class Program
{
    public static Main()
    {
        Circle c = new Circle(r = 4);
        Square s = new Square(side = 5);
        Console.WriteLine($"The Paint required for the Circle: {CalculatePaintAmount(c)}");
    }
}

this is showing the error Top-level statements must precede namespace and type declarations.

wintry quarry
#

it is updating an existing shootOrigin variable

scarlet pasture
#

but the GameObject is not a transform,

wintry quarry
scarlet pasture
#

i cant search only a Transform,

polar acorn
tired python
#

i didn't know that

wintry quarry
scarlet pasture
#

this time i only want search a GameObject

wintry quarry
#

You're going from the Component to the GameObject here already anyway

scarlet pasture
#
    {
        if (shootOrigin == null)
        {
            shootOrigin = GetComponentsInChildren<Transform>().FirstOrDefault(c => c.name == "ShootOrigin");
        }
    } ``` u said i should look at this method
wintry quarry
#

which is not happening at all in your other function

scarlet pasture
#

AHHHHHHH

#

yeah ofcorse

#

u right i know understand what u mean

polar acorn
scarlet pasture
#

why slow?

polar acorn
# scarlet pasture why slow?

Get component is slow. Linq is slow. You're getting way more results than you'll ever need and throwing them out which causes garbage collection which is slow.

scarlet pasture
#

so what should i use?

polar acorn
#

Find is still slow but it's way better than this mess

polar acorn
scarlet pasture
#

okay i will read it

#

is linq bad? i saw it on the Internet i thought this would be good

#

and why does it exesit if its slow?

wintry quarry
#

that's the best practice

scarlet pasture
polar acorn
scarlet pasture
#

thanks @wintry quarry @polar acorn

#

for u help didnt know that

scarlet pasture
#

thank u

tidal shuttle
#

tuff

glass summit
#

@scarlet pasture yo are you the ytuber?

rough granite
glass summit
#

was wondering if he was him or someone entirely different

rough granite
polar acorn
#

If you're spawning a prefab, spawn it as the component you want to get

rough granite
polar acorn
rough granite
polar acorn
#

You spawn the object, set whatever references it needs from the thing that spawned it

#

If other things need to know about the object that was spawned, you pass those references to those

slender nymph
# rough granite Wouldn't that in the end require at least one get component call?

you can assign a component reference in the inspector and pass that to Instantiate which will then copy the entire gameobject and also return the same type of component that was initially passed to the method like so:

[SerializeField] private MyComponent _prefab;
//in some method:
MyComponent instance = Instantiate(_prefab);
instance.InitializationMethod(data);
instance.someField = otherData;
rough granite
polar acorn
slender nymph
rough granite
slender nymph
#

that would be the class that inherits from Component, yes

#

it's not just any class that works like that, because you can't just have any class attached to a gameobject (and also can only pass UnityEngine.Objects to Instantiate), it must be a component

rough granite
slender nymph
#

MonoBehaviour inherits from Component

#

but it's not just MonoBehaviours that you can do this with because it's any component. Including things like Rigidbody which inherit directly from Component and not from MonoBehaviour

scarlet pasture
#

lol didnt know that a youtube exist with this name. but he makes great videos tbh

glass summit
scarlet pasture
#

hahah

umbral hound
#

So when we get raycast hit normals, let's say we walk on a slope, the normal will be equal to the slope angle, correct?

polar acorn
grand snow
#

how normal

umbral hound
polar acorn
#

angles are not involved

#

It's a direction vector, not a rotation vector

umbral hound
#

Oh okay

cunning rapids
cunning rapids
#

Or that lol

wicked venture
#

Hi guys I am at the point in my game where I want to create boss enemies (2D bullet hell type of game) and in these types of games sometimes or most of the time bosses have attack indicators like where they gonna use an explosion and how much time it will take for it to explode , like the indicators for bosses in MMORPGS , how do I create those indicators I cannot find useful resources online

hollow slate
# wicked venture Hi guys I am at the point in my game where I want to create boss enemies (2D bul...

Are you asking from a game-design standpoint?
For programming one, you'd generally want some kind visual representation of an attack. Some game use a disk that slowly fills into a circle when the attack is executed, so let's use that an as example.
You'd summon one of these either in UI or world-space depending on desired visuals/behaviour, and initiate them with parameters regarding attack size, delay, etc.

#

then handle the visual's appearance from another script that updates it accordingly with the parameter of time or something.
There's a ton of ways to do it though, so this question seems extremely open-ended.

glass summit
#

`using System;
using UnityEngine;

public static class NewMonoBehaviourScript : MonoBehaviour
{
#region - Player -

[Serializable]
public class PlayerSettingsModel
{
    [Header("View Settings")]
    public float ViewXSensitivity;
    public float ViewYSensitivity;

    public bool ViewXInverted;
    public bool ViewYInverted;
}

#endregion 

}`

#

@polar acorn

slender nymph
#

three back ticks, not just one. and you need a variable of that type

glass summit
#

what's the issue here?

hollow slate
#

yo that region is a little too small to need one no?

polar acorn
slender nymph
#

oh yeah that too

glass summit
polar acorn
#

Either it shouldn't be static or it shouldn't be a monobehaviour

glass summit
polar acorn
#

Is there a particular reason you've added either

#

What is this supposed to be doing

hollow slate
glass summit
#

it fixed the issue

#

thanks

hollow slate
polar acorn
#

It'll compile now but I've still got no idea what you're actually trying to do with this

hollow slate
#

yeah, making it both static and Monobehaviour suggests some shenanigans might be happening

rich adder
#

NewMonoBehaviourScript.PlayerSettingsModel ?

polar acorn
wicked venture
rich adder
wicked venture
#

so basically i just make a UI effect that goes ups

#

up

#

and when it finishes it summons an explosion

rich adder
#

thats just visuals representing whats going on with a number you increase, basically sounds like you want a timer

wicked venture
#

yeah

rich adder
#

mhm make the timer first, then you simply map that to the ui

wicked venture
#

yee i got the general idea

#

i guess i will finish my first boss first and after that attach the indicators after all its spells and mechanics are ready

glass summit
#

I'm getting more of these errors?

wicked venture
#

no point in looking how to do it before the enemy itself is not 100% ready

rich adder
glass summit
#

!code

radiant voidBOT
rich adder
tired python
#

can someone explain the Liskov substitution principle part of the level up your code book. I can't understand what it means

rich adder
#

again ?

#

we literally spent all the time explaining it to you

glass summit
tired python
#

you explained liskov substitution principle to me?

#

are you sure?

tired python
#

oh! this is liskov substitution!

rich adder
#

I asked you why did you define that class inside a static class?

glass summit
rich adder
# glass summit so i'm not supposed to?

well first of all if you waned to refrence that class its nested inside so it would be
src_Models.PlayerSettingsModel playerSettings not PlayerSettingsModel playerSettings

rich adder
#

its pretty simple tbh

tired python
#

it's just a bunch of overriding bruh

polar acorn
rich adder
tired python
#

@rich adder another thing, wouldn't using an abstract class and an abstract method be better in the long run?

rich adder
tired python
#

i guess i will need to figure this stuff out later on then...

rich adder
#

abstract has its own limitations, where interfaces are similar but could offer better benefits in some cases

tired python
#

ya, i ain't gonna ask what does that mean

rich adder
tired python
#

yes

rich adder
#

which is very similar to how interfaces work

tired python
#

oh

rich adder
#

except interfaces cannot have fields but abstracts can . etc
but inheritance is not always the best because you're constrained to the base class no matter what , so interfaces offer more modular approach

glass summit
#

but now have a new error

wintry quarry
#

That error is self explanatory

rich adder
#

this has nothing to do with the code itself but unity specific

glass summit
#

oh?

polar acorn
# glass summit

The variable cameraHolder of scr_CharacterController has not been assigned. You probably need to assign the cameraHolder variable of the scr_CharacterController script in the inspector.

rich adder
#

cameraHolder is not assigned

rich adder
glass summit
rich adder
#

okay so assign it , the second line gives you a hint to how

rich adder
# tired python yes

a very basic example where interfaces fit a situation bettercs public abstract class DamageableBase { public abstract void TakeDamage(int amount); } //error because we cant inherit multiple classes public class Player : MonoBehaviour, DamageableBase { }
instead of

public interface IDamageable {
    void TakeDamage(int amount);
}
public interface IHealable {
    void Heal(int amount);
}
//we can have as many interfaces as we need
public class Player : MonoBehaviour, IDamageable, IHealable {
    public int health = 100;

    public void TakeDamage(int amount) {
        health -= amount;
        Debug.Log("Player took " + amount + " damage. Health: " + health);
etc..
glass summit
#

i always keep running into errors

polar acorn
radiant voidBOT
scarlet pasture
#

Hey, does sombody knwos how to detect the raycast distance is to short?

rich adder
tired python
polar acorn
scarlet pasture
#
    {
        if (shootOrigin == null) return;

        dir = PlayerMovement2DScriptRef.facingRight ? Vector2.right : Vector2.left;

        RaycastHit2D hit = Physics2D.Raycast(shootOrigin.transform.position, dir, shootMaxDistance, EnemyLayer);
        if (hit.collider != null)
        {
            //VFX Spawnen
            StartCoroutine(VFXManagerScriptRef.SPAWN_ShootDust());
            this.VFX_ShootDust.transform.position = this.shootOrigin.transform.position;
        }
        else
        {
            Vector2 endPos = 
        }
    } ``` i try it many times but it dont work, i try to spawn at the end of the ray a bullet, so the Player know "AHH i need to upgrade my wepon"
scarlet pasture
scarlet pasture
rich adder
#

why not at shoot origin..

scarlet pasture
#

YEA! exactly, so the Player know his distance is to bad

scarlet pasture
# rich adder why not at shoot origin..

i do, the dust say the player "i Shooted" so if the enemy in the distance he get killed but is the enemy to far away the bulletr soawn and falls to the Ground, so the player knows he didnt hit a enemy

#

do u understand what i mean?

rich adder
polar acorn
#

The end position of a raycast is the start position plus the direction times the distance

tired python
#

is this an instance of function prototyping?

rich adder
#

ah yea forgot about that too
much simpler
shootOrigin + dir * maxDist

rich adder
scarlet pasture
tired python
#

not the c# instance but like, english instance

#

is this an example of ...

rich adder
tired python
#

wait

#

oh shiii i forgot

rich adder
tired python
#

functions can't exist without a type in here

polar acorn
scarlet pasture
polar acorn
#

The "Interactable interface" is usually the go-to example of how to utilize it in a game development sense

tired python
#

it's just a term in cpp....

rich adder
scarlet pasture
#

u right

#

but know i need how to see the end distance of the ray. im sure i will need that in the future

tired python
#

you can define functions in there without actually coding what it does and then just write it in a later part of the code for the compiler to find out at compile time

rich adder
#

what like header files ?

tired python
#

not rly

#

header files access a diff file

#

lemme give an example

rich adder
#

I mean the concept is the same though

#

separating implementation vs definition

tired python
#
int add(int x, int y);

int main(){
  return add(3, 4);
}

int add(int x, int y){
  return x + y;
}
#

you define it beforehand, but write it anywhere other than the main block of code which uses it

polar acorn
#

That sounds incredibly annoying

tired python
#

here's the thing, am i stupid or is it that the level up your code ebook is not beginner level stuff to start with unity?

#

it's talking about concepts i have never encountered...and i am supposed to understand the context somehow?

rich adder
#

I wouldnt say that, imo level up your code ebook assumes you already been coding a while

tired python
#

oh no

rich adder
#

or at least know the very basics of c#

tired python
#

oh

rich adder
#

differences between abstract classes, interfaces etc.. it assumes you kinda familiar with these but shows HOW they can make you write more SOLID patterns

gaunt pasture
#

Can somebody pretty please help me make a game? It’s called whispering apes

radiant voidBOT
# rich adder !collab 👇

:loudspeaker: Collaborating and Job Posting

We do not accept job or collab posts on Discord.
Please, use Discussions to promote yourself as job-seeking, advertise commercial job offers, or look for non-commercial projects to participate in:
• ** Collaboration & Jobs**

tired python
#

it's not that i can't understand what most of it means, i just don't feel any connection to these subjects cus they are all very abstract concepts for me rn

rich adder
#

its okay to write shit code, thats how we learn

#

this way you better understand WHY we want to use these patterns

tired python
rich adder
#

you cannot see a benefit if you don't do it wrong first

tired python
#

aight, i will try following a tutorial for a game or smth then

#

can you suggest one?

#

2d if possible

#

also, not outdated unity

rich adder
#

there's plenty of stuff on the Learn site

tired python
#

lemme check it out then, i will ping you back if i find one

rich adder
#

check the stuff pinned too

tired python
rich adder
tired python
#

i can check videos well enough on other sites, it's just a problem for unity

#

someone did tell me it could be because of my shitty ISP or smth

rich adder
#

im sure you can probably find more text based tutorials all around

#

to learn I'd start with a very basic project, very minimal graphics. not much logic.
something like flappy bird and such

tired python
#

i know that, i couldn't find guides that's why i asked...

#

i did kinda make a few games on pygame so i know basic is the way to go at first

rich adder
#

yeah cause you have to basically learn two things at once..
You have concepts specific to general c#, and then you mix that in with unity specific concepts (Components, GameObjects, Monobehaviors, Mono Events)

#

and the manual / docs has really good info

tired python
#

or is it outdated?

rich adder
#

I mean nothing really is outdated in sense, not much changed in the past 7+ years

tired python
#

ya...it is outdated

rich adder
#

maybe some UI

tired python
rich adder
#

and very specific API changes, like rigidbody.velocity vs linearVelocity

tired python
#

that's a diff headache altogether

#

imagine trying to learn what stuff and then spending an hour trying to find the right stuff

rich adder
#

the reason I say Learn pathways is they usually introduce you to the basic concepts

#

if not lookup 1 thing at a time then..
"how to move an object in unity" also works if you wanna go that route etc.

tired python
dull grail
#

How should i do menus? I have an idea how to do so with 1 category (like screen -> screen resolution, window type) but what should i do if there's more categories, just make multiple panels and disable every but selected one?

rich adder
dull grail
#

Thank you

rough granite
rich adder
#

every time you change something on canvas it has to redraw everything, so if you have more static items that don't need to be refreshed they should not be on the same canvas that say needs to make a change often and so on

#

eg. Dont mix healthbars with settings UI etc.

hexed terrace
#

Redraw everything in that tree, up to hitting a canvas. It doesnt redraw the entire UI ..iirc

rich adder
#

ahh dang its been a while I gotta find that video it was pretty old Unite or GDC I saw it on, probably unite where they talked about canvases thing

hexed terrace
#

Unite 2017, top 10 tips for UI optimisation or something

rich adder
#

ayee an OG Unity dev ^ 😄

hexed terrace
#

A v.useful and informative talk , one I've watched many times

rich adder
#

ya it was really good, I wonder if that stuff is still the same or they optmized it a bit

#

also never fully tried UIToolkit for game, i wonder the benefits there

hexed terrace
rich adder
#

ah okay good my memory still workin.. lol yeah I recall something like that , at the time I was basically making a lot 2D games on canvases

#

(mainly like card game and stuff)
so much easier to deal with scaling resolutions. no physics or anything

reef bramble
#

im trying to write a Foliage shader, like that supports wind. Is this the right place?

#

I made one but it doesnt have shadows.

reef bramble
grim sorrel
#
using UnityEngine;
using UnityEngine.InputSystem;

public class clickhandler : MonoBehaviour
{
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Vector2 worldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            RaycastHit2D hit = Physics2D.Raycast(worldPos, Vector2.zero);

            if (hit.collider != null)
            {
                Debug.Log("Clicked" + worldPos);
            }
        }
    }
}

I made this script to print the locations to where I click, when I put the script inside of the map and run the game, this happens

radiant voidBOT
# polar acorn !input
How to Set Input

To set Active Input Handling, go to:
Project Settings > Player > Active Input Handling

• Input Manager (Old): Use the original Input settings.
• Input System Package (New): Uses the new input system package.
• Both: Use both systems.

scarlet pasture
#

Hey, i wanted to ask. if i shoot a raycast? can ui get the Components of my Enemys?

grand snow
scarlet pasture
#

I Mean i use this => ``` private void Shoot()
{
if (shootOrigin == null) return;
dir = PlayerMovement2DScriptRef.facingRight ? Vector2.right : Vector2.left;

    currentBullet--; 
    RaycastHit2D hit = Physics2D.Raycast(shootOrigin.transform.position, dir, shootMaxDistance, EnemyLayer);
    if (hit.collider != null)
    {
        //Treffer
        this.VFX_ShootDust.transform.position = this.shootOrigin.transform.position;
        LocalSoundManagerScriptRef.PLAY_Miss(1);
        
    }
}```
#

can i just say => hit.collider.GetComponenty<BaseHealthManager>(); , beacuse u said "get some component from what you hit and then do something with this". Did i understand u correctly?

grand snow
#

physics 2d raycasts only hit 2d colliders so unless you put some on some world space UI then no

rich adder
grand snow
#

sorry what do you actually want to know 😆

scarlet pasture
#

TryGetComponent? would it be false if i only said => GetComponent?

scarlet pasture
#

but know i know it

rich adder
grand snow
#

you know what gameobject was hit, therefore you can do normal things with this gameobject

#

such as... get components!

scarlet pasture
scarlet pasture
rich adder
scarlet pasture
#

so only on GameObject i cant say ?

#

not

rich adder
#

anything Unity that inherits UnityEngine.Object so gameobject is one of them

grand snow
scarlet pasture
#

ahh so i dont need to search the Tag Enymore

grand snow
#

No

scarlet pasture
#

thanks didnt know that all

#

and sorry for my bad englisch. im Currently working on it

rich adder
#

just make sure the camera does indeed have MainCamera as the tag

scarlet pasture
#

did

#

unity gived me one per default

rich adder
#

mhm just incase you make other scenes / brand new cameras

vernal rock
#

how diffrent is c# to java

#

bcz i feel its like the exact same bassicaly

polar acorn
#

Different enough that C# doesn't suck.
Similar enough you can probably use both if you know either.

vernal rock
#

ah thanks

scarlet pasture
#

Hey, i wanted to ask. Why cant i reference a Transform from the Scene?. I try to say to my Script "Hey u need to take the "ChemberBulletOrigin" in the Scene"

#

but every time i try there is "Type missmatch"

#

i guess i need to search my Transforms in Runtime?

polar acorn
#

Prefabs cannot reference objects in the scene. You will need to set that reference after spawning an instance of the prefab.

scarlet pasture
#

i understand, so if i catch it in the Awake call? and the Player would move... would Unity register the new Positions? i did it now lilke that => ``` void Awake()
{
if (!playerMovement2DScriptRef) playerMovement2DScriptRef = GameObject.FindGameObjectWithTag("Player")?.GetComponent<PlayerMovement2D>();

    if (!ChemberOrigin)
    {
        // Spieler suchen
        var player = GameObject.FindGameObjectWithTag("Player");
        if (player)
        {
            ChemberOrigin = player.transform.Find("---Combat---/ChemberOrigin");
        }
    }
}```
#

i didnt test it out, but maybe u know the answer

grand snow
#

didnt we tell you about ? earlier?

scarlet pasture
#

yeah i thught i can use it but only if i search a Gameobject i cant search it

grand snow
#

er sorry say again?

scarlet pasture
#

okay sorry

#

wait

#

i need to think

#

i thouhgt u said to me, i cant use ? if i search a "GameObject". in my case i searched the ScriptReferences. That would be fine?

grand snow
#

you should do this:

MyCoolScript coolScript = FindFirstObjectByType<MyCoolScript>();
if(coolScript != null)
//stuff
#

find and store in a variable
then check if its null or not

scarlet pasture
#

rob why cant i use ? it works in the Game?

grand snow
#

? is incompatible with special unity overrides so is not safe to use with gameobjects/components/assets

#

It works but there are situations where it will not work

#

Much easier for a beginner to avoid using it due to this

#

Trust us

scarlet pasture
#

i do, i will know use u method. is u like the same? but safier?

rich adder
#

FindFirstObjectByType will allow you to capture the component at runtime

scarlet pasture
#

this is what i need

rich adder
#

right so you can store it and then do whatever

scarlet pasture
#

and if i do this in Awake, and the Player moves. would Unity register the new Positions?

rich adder
#

if the reference is the same, it will always be the same object

scarlet pasture
#

NICE!#

rich adder
#

cache it in awake, use it in update

#

refrain from calling Find methods in update

scarlet pasture
#

so now i only need to referenc with the new Method rob gived me and use it for the Bullets shoot remaining

scarlet pasture
rich adder
#

yes, because it scans all your objects

#

if its something that is being spawned though in most cases people pass the references through a method

scarlet pasture
#

One last Quastion, i understand that robs method is better, i try it like "how i currently know the thinks" i did it like that => if (!ChemberOrigin) { // Spieler suchen var player = GameObject.FindGameObjectWithTag("Player"); if (player) { ChemberOrigin = player.transform.Find("---Combat---/ChemberOrigin"); } } nav just of interests. would that work?

rich adder
scarlet pasture
#

like in Roblox Studio, i navigate throught the Objects

rich adder
#

dont use find method like that especially string versions

scarlet pasture
#

because i can change the name in the Editor? right?

rich adder
#

yes if you change name everything breaks

#

plus its slower

scarlet pasture
#

and then it would crash. i hat that experience also in Roblox

rich adder
#

you will catch a null refrence it wont crash

scarlet pasture
#

but my Game frezzes of a null references

rich adder
#

correct because "Pause on Error" is toggled

grand snow
#

💡 Try to avoid using any kind of Find() and make use of serialized variables. You can also maually setup and provide dependencies to spawned objects to avoid Finds!

rich adder
#

you pretty much never need to use GameObject as a return type in 99% of the time

scarlet pasture
#

what do u mean?

#

return? like dont run the code?

rich adder
#

well for example..
GameObject.FindGameObjectWithTag("Player");
this returns a GameObject

#

not very useful

scarlet pasture
#

ahhhh i know what u mean

rich adder
#

more useful to just grab the component you want directly

#

if you wanna find the player, and we assume it has a Player script on it (aka a component)
Player player
you use player = FindFirstObjectByType<Player>();

#

then in Player you can store whatever else you want

scarlet pasture
#

okay, i ask u then, u definettly better than me. i give my Prefab a Script that gives him a random force to the right and left. but i need to Instantiate it from the Weapon Chember

#

how would u do that, so i know it in the future, and the Transform Spawn Position lies on the Scene

rich adder
scarlet pasture
#

yeah i instantiae the Bullet use his Rigidbody but i also need to find the Transform positon in the Scene. What is a "universall" use of case to find References in the Scene via Runtime

#
        {
            ChemberOrigin = FindFirstObjectByType<Transform>();
            if(ChemberOrigin != null)
            //stuff
        }``` because this would not work
rich adder
scarlet pasture
#

yeah, i need to filter it down to the Name of the gameObject?

rich adder
#

You need to provide your setup / explain it better

#

what is Chamber origin?

#

lets say its a Bullet prefab

BulletScript bulletInstance = Instantiate(bulletPrefab, barrel.position, Quaternion.identity)
bulletInstance.DoOtherStuff()

scarlet pasture
#

okay this i have currently also

rich adder
#

your Gun spawns it or whatevr already has the barrel referenced as a transform

scarlet pasture
#

exactlly i use a Origin pos also but unity dont find "barrel" because it is in the Scene

#

and the Script is in the Prefab, in the Project Folder

#

so i need to search it throught Awake. so i used that

#
        {
            ChemberOrigin = FindFirstObjectByType<Transform>();
            if(ChemberOrigin != null)
            //stuff
        }```
rich adder
#

wait before you keep posting the same code

#

can you show what your setup looks like

#

like in the scene

grand snow
#

FindFirstObjectByType<Transform>(); this wont do anything useful because all gameobjects have a Transform

scarlet pasture
#

my Scene

grand snow
#

its good to use when we know a script WE made has only 1 instance

scarlet pasture
#

my bullet

rich adder
#

why does the bullet have to care about chamber origin

scarlet pasture
#

because it need to spawn at the right weapon position

rich adder
#

then make the script that spawns the bullet hold that reference

#

not the bullet

#

you're doing it backwards

scarlet pasture
# rich adder then make the script that spawns the bullet hold that reference

i do => ```? using UnityEngine;

public class BulletChemberLogic : MonoBehaviour
{
[Header("References")]
[SerializeField] private PlayerMovement2D playerMovement2DScriptRef;

[Header("Bullet Chember Ref")]
[SerializeField] private GameObject bulletPrefab_001;

[Header("Bullet 001 Settings")]
[SerializeField] private Transform ChemberOrigin;
[SerializeField] private float upwardsRandomness = 2f;
[SerializeField] private float torqueRandomness  = 2f;
[SerializeField] private float shootForce = 15f;

void Awake()
{
    if (!playerMovement2DScriptRef) playerMovement2DScriptRef = GameObject.FindGameObjectWithTag("Player")?.GetComponent<PlayerMovement2D>();

    if (!ChemberOrigin)
    {
        ChemberOrigin = FindFirstObjectByType<Transform>();
        if(ChemberOrigin != null)
        //stuff
    }
}

public void SPAWN_Bullet001(float DestroyAfter)
{
    ChemberOrigin = transform.Find("Player/---Combat---/ChemberOrigin");

    if (!bulletPrefab_001 || playerMovement2DScriptRef == null || ChemberOrigin == null) return;

    GameObject bullet = Instantiate(bulletPrefab_001, ChemberOrigin.position, Quaternion.identity);

    Rigidbody2D rb = bullet.GetComponent<Rigidbody2D>();
    if (!rb) return;

    Vector2 dir = playerMovement2DScriptRef.facingRight ? Vector2.right : Vector2.left;

    float randomUp = Random.Range(-upwardsRandomness, upwardsRandomness);
    Vector2 force = (dir + Vector2.up * randomUp).normalized * shootForce;

    rb.AddForce(force, ForceMode2D.Impulse);

    float randomTorque = Random.Range(-torqueRandomness, torqueRandomness);
    rb.AddTorque(randomTorque, ForceMode2D.Impulse);

    Destroy(bullet, DestroyAfter);
}

}```

rich adder
#

jesus

scarlet pasture
#

wait?

#

is that bad

rich adder
#

just make a Transfrom field in this script

#

public Transform chamberOrigin

#

assign it in the inspector

scarlet pasture
#

did, but i cant use it because this Script lies in the Prefab

#

prefab cant get references to the Scene

rich adder
scarlet pasture
#

no its in the Project folder for the Bullet

rich adder
#

so this is the bullet script ?

scarlet pasture
#

ja

rich adder
#

these names are confusing af

scarlet pasture
#

i mean yeah

rich adder
#

why is the bullet spawning itself

scarlet pasture
#

? is that not normal

rich adder
#

no lol

#

you dont have like a Weapon script ?

#

something that actually spawns projectiles on the player

scarlet pasture
#

yeah! and i want to use the public method from the bullet code

#

to instantiuate the bullets in the right moment

rich adder
#

where is the weapon script

scarlet pasture
#

posteted, u said "jesus"

#

oh wait u mean my Combat Scriupt

#

!Code

radiant voidBOT
rich adder
#

this is why proper naming is important lol

scarlet pasture
#

look this is my Combat Script, i want to Instantite Bullets in the Right Moment, but currently i dont know how to find the right TransformOrigin in the Scene

#

dayumn this all is hard

rich adder
#

this is the most over engineered script I've seen in a while

#

i can barely tell whats going on

scarlet pasture
#

really? i coded it my self beside of the #if Unity Editor

rich adder
#

So you have a ray to shoot but then want to spawn a bullet?

scarlet pasture
#

a bullet that flys to the sky, like u would shoot with a gun and the bullet is Emphty now and flys to the ground

#

u understand what i mean?

scarlet pasture
rich adder
scarlet pasture
#

ofcorse im not the best tbh

#

i dont even know how to find thinkg

rich adder
#

its fine dw. Im just trying to understand it

scarlet pasture
#

withs linq i would find it so easy

#

i learnd the Syntax from Linq

rich adder
#

what does linq have to do with anything here lol

scarlet pasture
#

i mean findinf the Spawn Position of the bullet

#

my only problem is that

#

i dont find the pos via runtime

rich adder
#

brother.. I understand what you want, I just dont understand why you are doing it a certain way

#

thats why Im trying to understand what the bullet needs to do and why you are not directly spawning and setting position from this combat script

#

its hard to give a solution without understanding the full usecase / context

scarlet pasture
#

for me it does alot of sense, i have a prefab, a Script thats under the Prefabs. in that Script a public method that Manage diffrent bullets in my Game (this is why its calle bullet_001) and know my Goofy ahh Combat Script should Spawnt the right Bullets

scarlet pasture
#

i try to make everthing in Methods

#

i heard that is a good practies

#

if i ever need to change somthing i know "Okay just go the the Method and change it"

rich adder
#

Bullet is a prefab, you want to spawn the prefab from the Combat script , Assign the barrel position from there

#

the language barrier is probably causing some misunderstanding

scarlet pasture
#

ofrcorse

scarlet pasture
scarlet pasture
#

but i want alot of bullets and costum settings

wintry panther
#

i drew some tiles in a 2d scene then dropped in a couple prefabs but the tiles are aligned to the center of grid cells while the prefabs are aligned to the corner of the grid cells. how do i make both tiles and prefabs align the same?

rich adder
scarlet pasture
#

i mean if i had 5 Bullets, and i would diffrent Settings for each one, i would need to make 5 Methods... in Combat Script

rich adder
#

what exactly do you mean with "different settings"

wintry panther
scarlet pasture
#

Damage, Speed, penitration, FireAmo

rich adder
#

let me make a quick example

scarlet pasture
#

yeah pls

rich adder
# scarlet pasture Damage, Speed, penitration, FireAmo
public class Bullet : MonoBehaviour
{
    [SerializeField] Rigidbody rb;
    public int Damage;
    public int Speed;
    public bool FireBullet;

    public void InitBullet(Vector3 shootDir, int damage, int speed, bool fireBullet)
    {
        rb.AddForce(shootDir * speed, ForceMode.Impulse);
        Damage = damage;
        FireBullet = fireBullet;
    }
}

public class WeaponScript : MonoBehaviour
{
    [SerializeField] Bullet bulletPrefab;
    [SerializeField] Transform shootOrigin;

    void Update()
    {
        //lets assume we press the input to shoo
        {
            var bullet = Instantiate(bulletPrefab, shootOrigin.position, Quaternion.identity);
            bullet.InitBullet(Vector3.right, 12, 10, true);
        }
    }
}```
scarlet pasture
#

this is literlly what i have

#

2 diffrent Scripts

rich adder
#

not though?

#

you're inside of bullet script looking for origin of barrel..

#

bullet should not care about any of that..

scarlet pasture
#

is that not the same like my => and thant spawning the method in the CombatScript?

#

bro im to dumb

#

and yess i will change the ?

rich adder
#

and most of that shit is not needed..

scarlet pasture
#

shit?????#

#

dayumn

rich adder
#

its an expression I dont mean literally

#

"stuff" whatever

#

why does Bullet need to search the player for the facing direction?

#

you see my example you can pass the direction directly when you spawn it ?

scarlet pasture
#

i want to have it random

#

somtimes, left, somtimes

#

right

rich adder
#

but its not right now..

#

its based on playerMovementScript.facingRight

scarlet pasture
#

yeah, if the player looks left the bulletr should come right out

rich adder
#

so how's that i want to have it random

#

its not random if its based on where player is facing lol

#

make a thread btw so we dont flood this chat

scarlet pasture
#

i dont know man, my code is hella chopped

#

i just do somthing

#

hoping for the best

rich adder
#

I think you overcomplicated it , thats all.. very easy to do in the beginning and even with experience

#

simplify it, make it easier on yourself

scarlet pasture
#

okay, so im try to make it easier, i just delete the bullet Code, spawning the Bullets from the Chember in the COmbat Script?

rich adder
#

look at my example
Combat Script spawns the Bullet and sets all its settings..
Bullet script just handles getting that info and execute it, it DOES NOT search for anything

#

anyway, if you wanna keep discussing it further I'll help where I can but make a thread so we dont flood the chat

scarlet pasture
#

okay, u the expericend man. i will just use u example thats it

#

we can close this dicussin, nav really thank u for u timr

rich adder
#

np.
use the example as Base, no need to copy line by line.

mint imp
#

Quick question:
Wondering how i might compare the rotation of an object to that of an approaching object
Trying to check if the incoming objects movement direction is parallel to the stationary one's rotation.

For context image a runway, and checking if a plane is parallel to the runway or is it not.

wintry panther
#

im trying to snap a gameobject to the grid using this code:

{
    float offset = 0.5f;

    Vector3 rounded = new Vector3(
        Mathf.Round(transform.position.x),
        Mathf.Round(transform.position.y),
        0f
    );

    Vector3 snapped = rounded + new Vector3(offset, offset, 0f);

    rb.MovePosition(snapped);
    blockBounds.center = snapped;  // Update for next time
}```

But since the gameobjects pivot is at its center, i tried  adding a 0.5f offset, but now it doesnt snap to the correct grid position. it IS offset but just not the right grid position. maybe its got something to do with my other code?
solar hill
fast relic
rich adder
#

Vector3.Angle also works

wintry panther
fast relic
solar hill
wintry panther
solar hill
#

oh

fast relic
wintry panther
#

this is what it looks like

#

everything is aligned there

#

but when i move the red squares (the prefab) they snap to the middle of grid slots

scarlet pasture
#

nav i did what u mean

fast relic
#

is it an editor tool?

scarlet pasture
#

it finally work

rich adder
#

is working now ?

#

🥳

scarlet pasture
#

yeah but i did a own simpler methode

rich adder
#

good simpler is always best 😛

#

the KISS principle always important

scarlet pasture
#

KISS?

solar hill
#

keep it simple silly

rich adder
#

KISS, an acronym for "Keep it simple, stupid!", is a design principle first noted by the U.S. Navy in 1960. First seen partly in American English by at least 1938, KISS implies that simplicity should be a design goal. The phrase has been associated with aircraft engineer Kelly Johnson. The term "KISS principle" was in popular use by 1970. Variat...

solar hill
#

i dont like calling people stupid

#

:(

mint imp
# rich adder you can use Dot product

Okay i looked that up but not quite sure how to apply that
So im comparing the dot product of both vectors?
If its zero, they are parallel?
but what if i wanted it to be within 5 degrees of being parallel

fast relic
rich adder
scarlet pasture
rich adder
grand snow
#

If you understand Dot product and unity its easy

scarlet pasture
#

did u every maked a commercial game?

rich adder
#

they are really handy, like if you need to know if a player is sneaking behind an enemy and perform a Sneak Kill etc.

scarlet pasture
#

but i think the hardest part is drawing tbh

rich adder
#

Dot product is a math function, I actually only officially learned it because of untiy

#

my school math was not very good lol

#

once i put all the school math into unity it made more sense for me, I learn that way :p

solar hill
#

theres a lot of people who know what for loops are but dont know what a sum operator is

#

even though its practically the same thing

rich adder
#

yeah i was talking about this the other day with a Freira tweet I found

solar hill
#

yeah this one

#

its what made me think of it

rich adder
#

yeah exactly

solar hill
#

i got statistics in college and knowing this litterally saved me* lol

rich adder
#

big scary math symbols

solar hill
#

sigma

rich adder
#

I can do nested loops (multi dimensional arrays etc.) but then I see those real math symbols and I'm suddenly getting humbled rq

solar hill
#

its such a wildly different application of math

#

that sometimes you dont even realized how much of math you know

#

because you learned learning to develop

#

its great because its self teaching through practical effort

rich adder
#

some people just learn differently I suppose

#

I'm also more visual, I need to see whats happening visually to really "get it"

solar hill
#

its great programming allows you to iterate easily and quickly

#

"shit i have another error time to open up another project"

warped sierra
#

Unity isn't capable of supporting VP9 videos on desktop platforms? I've heard about WebRTC, but I'm not sure if it's possible.

rich adder
#

why not just tryitandsee

warped sierra
mint imp
warped sierra
#

umm I'm looking at WebRTC and I see some logs that use TCP or UDP to stream video from the camera, could that be useful?

timber tide
#

Don't think WebRTC is TCP

#

WebSockets is

#

But yeah (live) streaming stuff you would use WebRTC or any type of UDP usually

warped sierra
#

umm This WebRTC example refers to the VP9 codec

swift warren
#

what is a vector chat

polar acorn
#

According to googl, "Vector Chat" is some random pointless LLM no one will ever care about or use

cinder trout
#

i set my thing to opera wwhen it asked what i wanted to code with and i pressed use this choice alwayse and opera doesnt work so i dont now how to fix it

radiant voidBOT
cinder trout
#

yes but how do i switch it i dont need a coder i need to switch it

wintry quarry
#

You follow the guide for the one you want to use

#

Idk what you mean by "I don't need a coder"

teal viper
#

Is "opera" some kind of new ide? I thought it was a browser. 😅

naive pawn
#

anything can be an IDE if your standards are low enough

soft ibex
#

Hi guys, so i have a .jpg file which contains several game icons. Then i use a sprite editor to split them into a single icon.

Now my problem is: how can i reference to a single icon by using Resources.Load()? i want to load a specific icon and stores the texture in a variable.

naive pawn
#

why not use serialized references

safe root
#

!code

radiant voidBOT
safe root
#

I need help with a issue, both spawners I have are going at the same time. I am not sure why, they should be going different times. Each one focusing on different things. I also wanted to see how I can make my code better, cause I know it's quite bad

https://paste.mod.gg/trkdlehlkaeu/0

wintry quarry
polar acorn
safe root
safe root
polar acorn
safe root
polar acorn
safe root
#

Sorry 5

polar acorn
safe root
polar acorn
#

So, at the start you kick off a loop that'll spawn a basic thing every 5 seconds. You also have a countdown that will kick off one rare spawn every 10 seconds.

#

So, 5 seconds in, basic. 5 more seconds, basic and rare. 5 more seconds, basic. And so on

safe root
polar acorn
safe root
polar acorn
safe root
#

Thankyou

visual pond
#

why does this not work

#

in fixed update

#

the only other lines of code are movement and it shouldnt affect this

sour fulcrum
#

what does it say

visual pond
#

tjos

#

this'

sour fulcrum
#

have you looked at the documentation page for AddForce online?

visual pond
#

im following brackeys tutorial

#

the 8 years ago one

thorn holly
visual pond
#

then what do i use?

visual pond
thorn holly
sour fulcrum
#

What's the difference between whats on that page's examples vs. yours?

visual pond
#

no forcemode

#

or whatever that means

sour fulcrum
#

🙂

visual pond
#

it had x y z

sour fulcrum
#

you need that additional forcemode argument to explain how the force is done

#

if you click ForceMode's documentation it explains the options

#

you probably want force or impulse

thorn holly
visual pond
#

okay why is the first addforce still red

sour fulcrum
#

what does it say

visual pond
#

hold on

sour fulcrum
#

you can mouse over it btw

#

dont need unity to tell you

visual pond
#

huh?

#

that was 4

sour fulcrum
#

that is odd

visual pond
#

hold on lemme post the whole code

sour fulcrum
#

ahh

#

rigidbody2d

#

that matters

thorn holly
visual pond
#

fuck

#

right

#

im used to doing 2d not 3d

visual pond
#

yeah okay that fixed it

#

thanks

thorn holly
#

nice

sour fulcrum
#

No worries

sour fulcrum
# visual pond that was 4

just a small nitpick/heads up btw, it having "4 arguments" isn't a reason why you shouldnt be getting that error, that just means for that Type it can't find a valid Function that matches those Parameters your trying to give with it

visual pond
#

oh

sour fulcrum
#

As you've seen with the AddForce it has different ways you can give it information even though it's the same function. that error is just saying "hey whatever your chucking in here isn't something this function is built to handle"

visual pond
#

i see

#

okay now

#

why cant i give it delta time

#

fixed it just gave fixed delta to the z value instead of the mode

thorn holly
rich adder
#

mixing addforce with translate 🤔

visual pond
#

it was just autofill from vs code

#

the movement works

#

as intended

#

im tryna find out whats tranform.translate

#

in the documentation

rich adder
#

you're essentially teleporting

visual pond
#

ae

thorn holly
# visual pond the movement works

those two things can cause issues down the line
Specifically, not doing the first one makes your physics calculations proportional to delta time squared instead of delta time, which can cause issue
Not doing the second one will make it so running the game on a higher framerate has no effect on input snappiness (i dont think thats the right word but you get the point)

rich adder
#

translation on transform is skipping the physics so it could at some point phase through walls , colliders are physics

visual pond
#

oh

#

so what do i replace it with

rich adder
#

linearVelocity or AddForce , depending on feel

thorn holly
thorn holly
visual pond
#

addforce seems to fit

rich adder
#

one thing to keep in mind is AddForce will keep increasing velocity

#

unless you set limit / clamp velocity

cosmic dagger
#

You'll need to clamp it to keep a set speed, and apply force in the opposite direction to stop . . .

short gust
#

if I want to make "chunks" for my single-scene world (it's not randomly generated chunks, only for loading/unloading parts of it): loading a prefab with all the stuff and enable/disable it after the first load - will it bite in my ass by huge RAM usage of disabled prefabs scattered around the world and I'm better unloading them completely instead of just disabling within some sort of pool?

timber tide
#

if they all share similar resources then technically the cost is that of a gameobject/transform

#
  • w/e component data that's unique to each object
#

larger issue is textures and model data usually

short gust
#

so holding them as disabled all the time is not very good, I suppose.
maybe I can use some sort of "inactivity timer" to unload prefab which is disabled for too long, lol. kinda convoluted solution, but maybe it will work nicely/okay-ish.

scarlet pasture
#

hey

#

I used LINQ yesterday to find components, and some people said it's a bad practice.
After researching, I found that since Unity 2022, LINQ performance has actually improved a lot — especially with IL2CPP and the Incremental Garbage Collector.

Using something like ```FirstOrDefault(l => l.name == "ShootLight");

The real issue only happens when you use LINQ inside Update() or FixedUpdate(), because it allocates memory every frame.

Still, I built a zero-alloc alternative for cases where performance really matters: ```ShootLight = FindUtil.FindInChildrenByName<Light2D>(this, "ShootLight", includeInactive: true);
``` This method uses the GetComponentsInChildren(includeInactive, List<T>) overload and reuses a static buffer list, so it creates no garbage.

So yeah — LINQ is not evil anymore, it just depends on where and how often you use it. 🙂
grand snow
#

you are searching for something with a name which 99% of the time can be done a better way

#

Linq is best avoided and we tell this to beginners so they dont do crazy things when a simpler approach is better

scarlet pasture
#

😭😭😭

#

So okay I don’t use linq I understand that BUT u wanna tell me that my other method is also bad?

#

Atp im just quiting hahaha

keen dew
#

Instead of spending time building elaborate machinery to find components by name, you should use that effort to fix the project code structure so that you don't need to find components that way

scarlet pasture
#

what do u mean?

#

project code?

grand snow
#

Make components and prefabs that already have references assigned and required logic ready to go

keen dew
#

If you need a method to find components by name you're doing something wrong. There shouldn't ever be a need to find components by name

sour fulcrum
#

And yeah linq is fine unless it’s in pretty heavy update loops

scarlet pasture
keen dew
#

I believe this was explained to you multiple times yesterday

sour fulcrum
#

Have a serialised field for the light and connect them in the inspector

vernal rock
#

im so proud of myself

keen dew
#

[SerializeField] Light2D ShootLight and drag the light there, or if you can't do that, public Light2D ShootLight and the component that instantiates the thing will set the value

scarlet pasture
#

i didnt really understand HOW i can find a Spzifical Object in the Scene

keen dew
#

That's a silly reason

scarlet pasture
#

u mean a dumb reason?

keen dew
#

Well yes, if you want to put it bluntly

scarlet pasture
#

but why?

naive pawn
#

so you get an error explicitly telling you that you forgot to set a reference

#

you don't really need a fallback

keen dew
#

"the Game cant find it for what ever reason" – this is not something that happens. If you assign the value correctly then it'll always work.

scarlet pasture
keen dew
#

If you expect the game to just randomly break, how can you be sure that your fallback doesn't also randomly break?

naive pawn
umbral bough
#

Hey, how can I check if any of the mouse buttons other than scrollwheel are being held down here?

private static void OnSceneGUI(SceneView sceneView)
{
    var e = Event.current;
    if (e.type == EventType.ScrollWheel &&
        e.button == 0 &&
        e.modifiers == EventModifiers.None)
    {
        Zoom(e.delta.y);
        e.Use();
    }
}

e.button == 0 didn't work sadly.
The reason I wanna do this is when you hold right click, scroll is supposed to adjust the movement speed.
My script cancels that rn.

sour fulcrum
scarlet pasture
#

okay, i understand that know, i dont need to make the fallbacks.. okay. BUT can u tell me how to search a Spezifcal Object without a Tag. So i just know how to do that if i ever need that

naive pawn
#

ok imma be blunt. what you're thinking of is called "magic strings" and it's a pattern that should be avoided because it's very fragile and mistake-prone

#

you should never "need" that, period.

#

you should have better, more resilient, easier to work with systems in place

#

this is what serialized references achieves

scarlet pasture
#

Okay, got it now!

#

thanks