#💻┃code-beginner

1 messages · Page 321 of 1

summer stump
#

When it does, it's because it stole the code of course

polar acorn
#

Most professional programmers can't even make scaleable code

wicked cairn
#

All of it ran on the first try and worked, connected from unity to node on the host machine and printed the logs correct. No errors

rich adder
#

exactly, it can run basic checks on its own code but not actual systems connected together

polar acorn
#

It's not just a process of writing, it's a process of documenting, training, and refactoring that a LLM simply is not designed to do

rich adder
#

at least github copilot type of extensions, train on your own code

#

but those are cute fluff

polar acorn
#

Even if you buy into the LLM hype and don't assume it's just copy-pasting snippets it stole from the questions on StackOverflow, an LLM is not a knowledge base. If even one hallucination makes it into your documentation, every single bit of knowledge added after is potentially tainted and would need to be thrown out and rewritten

wicked cairn
#

Theres a right way to use and ask for things with gpt. Ive learned to describe well what you need and to treat it like its capable. It ends up giving very great code that is totally understandable and commented. If you do not like what it gave you, just ask it to rewrite the previous script using a different method and it will

rich adder
#

"Will AI replace my coding job"

Future Coding Jobs:

Must go through thousands lines of code to fix AI code

wicked cairn
rich adder
polar acorn
#

Because it does not store that information anywhere

wicked cairn
polar acorn
#

It literally cannot

rich adder
timid hinge
#

can someon help

wicked cairn
rich adder
#

I still use it to this day, just not for coding takss..

scenic saffron
#

Has anyone watched this tutorial an knowes if it also applies too Unity?

https://youtu.be/GhQdlIFylQ8?si=Xh6Eaj6wu8vvZk_Z

This course will give you a full introduction into all of the core concepts in C# (aka C Sharp). Follow along with the course and you'll be a C# programmer in no time!

⭐️ Contents ⭐️
⌨️ (0:00:00) Introduction
⌨️ (0:01:18) Installation & Setup
⌨️ (0:05:03) Drawing a Shape
⌨️ (0:17:23) Variables
⌨️ (0:30:06) Data Types
⌨️ (0:37:17) Working With S...

▶ Play video
rich adder
#

at most maybe writing boilerplates
but I already know what to look for in that

slender nymph
timid hinge
#

yes but i have attack animations

polar acorn
willow scroll
rich adder
languid spire
polar acorn
#

It's programmed to pretend like it remembers you

slender nymph
wicked cairn
rich adder
timid hinge
#

the problem is that i dont know what animator controller

polar acorn
willow scroll
wicked cairn
# polar acorn

because you created a new chat, intentionally erasing your history

languid spire
willow scroll
# polar acorn

The questions apart from the current chat aren't saved.

polar acorn
rich adder
polar acorn
elfin nacelle
#

Does anyone know how to make a good looking script because I’m pretty new to coding and I was able to make a walking script for the player but I don’t really know how to make a script for the player to look around?

rich adder
wicked cairn
# polar acorn Yes that is exactly my point

Which is a awesome thing, because in one chat you may want to talk all about unity, in one chat you may want to talk all about food, in separate chats it learns that topic and about you so it can better help in that field

languid spire
#

I think he meant good, looking

slender nymph
elfin nacelle
rich adder
#

yeah ik just being a smart ass

elfin nacelle
#

Oh

rich adder
#

did you look around?

#

best you follow a proper tutorial that covers both, or better yet build your own

polar acorn
#

Are you ChatGPT

rich adder
#

almost

wicked cairn
polar acorn
wicked cairn
polar acorn
rich adder
#

this reminds me of nam and this is like the new recruit coming in with the fresh gear after the academy

wicked cairn
#

My use is when I actually am lost on something I paste my code into gpt and ask it how I might add a feature into this script, and it sends back that feature. This example is great as a learning tool

#

Learn! not product

polar acorn
#

Scaleable means it needs to know everything that came before it in order to ensure everything is consistent with existing documentation and standards and that cannot be done with a chatbot that has no working memory or presence of thought

wicked cairn
#

Everything requires learning. For unity, quite some time. Im trying to say that its great to have a tool such as gpt which can show you awesome samples

polar acorn
#

Every time I bring up a reason why it doesn't work for the thing we are talking about you bring up "But it works for this other unrelated thing!"

#

That's not the conversation right now

wicked cairn
polar acorn
#

Here's another thing a chat bot can't do: Stay the fuck on topic

wicked cairn
willow scroll
rich adder
#

or saying we simply don't know how to ask it, to get good results? thats mental gymnastics

polar acorn
#

I've written LLMs. I know how they fucking work

#

They can not do this sort of high level project management

#

Programming is not hard because of typing the functions. It can help you do the literal easiest and most trivial parts of programming and is absolutely worthless to do anything difficult

wicked cairn
rich adder
#

I bet they never used a Vector database before either

#

they have no clue how results get composed

polar acorn
#

ChatGPT is, at best, an intern who can't even get you coffee

#

Programming is 90% documentation and meetings. Typing the lines into a text document is a pittance of the job.

wicked cairn
#

Youtube and google cant give you coffee...

rich adder
#

by that logic youtube and google can do the same on "suggestion how to obtain"

fickle plume
#

Let's not get sidetracked here

wicked cairn
polar acorn
#

Yet you continue to act as if I was

rich adder
#

This started by connecting database in Unity via Node

#

who said anything about learning

wicked cairn
#

Well you made it seem as if it were completely useless. So I wanted to provide a little bit of perspective. I dont mean to be way off topic, but just wanted to say that its a neat tool and its wonderful that it is capable of providing code.

#

Youtube and google have been long used, but theres quite a lot of wrong information. Either way, its all about learning

rich adder
#

just a reminder , also yes this is wayy offtopic at this point. I said my peace , you use whatever you think is good for you

languid spire
#

Classic

rich adder
#

Sparklez using it too much xD

polar acorn
# languid spire Classic

"Hey I was just typing your symptoms into the computer here and it says you might have 'Network Connectivity Problems'"

languid spire
#

All I asked it to do was add a break; statement into a for loop

wicked cairn
#

Sorry if I misunderstood. To me it is great because I do not know much about backend, but if you dont like it thats ok. However, you should not call it useless, it is very helpful when learning.

rich adder
#

No one said it was useless though ? at least me personally, said the code isnt scalable. Maybe lookup what scalable code/ systems means

fickle plume
wicked cairn
#

Ok. I wont again. There are a lot of fair points in all directions. I see public posts can be helpful sometimes but always arguments on whos code is better, seen that on stackoverflow and stuff. Unity takes a lot of learning no matter how advanced you are, so I wanted to put it out there another tool that may be a option.

timid hinge
#

When i start the game this sprite appear but i dont select that sprite to appear there

wintry quarry
timid hinge
rich adder
honest haven
#

if (currentHP <= 0)
{
return;
currentBattleState = BattleState.GameOver;
gameOverPanel.SetActive(true);
gameOverText.gameObject.SetActive(true);
} does return execute code underneath once even if its in update?

rich adder
honest haven
rich adder
#

it returns out of the whole function

honest haven
#

wasnt 100% sure

short hazel
nova wagon
#

nvm

#

figured it out

honest haven
#

Yh it is grey out. but just wanted to 100% confirm this

rich adder
#

it grays it out a bit yea

honest haven
#

yh

rich adder
#

oh wow Rider grays it out completly

wicked cairn
# nova wagon nvm

Based on your function name and comment by it that you have not gotten the second delay yet, you can research "unity Coroutines" it works with float delays

honest haven
nova wagon
#

it was working fine, i was just pressing the key in the scene window instead of the game 😂

honest haven
#

have used jetbrains for years .

rich adder
#

but still keeps the colors

honest haven
#

oh i would find that hard to spot

rich adder
#

yeah prob bad for those who are not sensitive to color changes :p

honest haven
#

lol

#

but its free

nova wagon
#

oh what theme is this

honest haven
#

cant win at every thing

rich adder
nova wagon
#

looks cool

viral creek
#
using System.Collections.Generic;
using UnityEngine;

public class EnemyFollower : MonoBehaviour
{
    public GameObject playerPrefab;
    private Transform playerTransform;
    public int speed;

    private void Start()
    {
        // Find the player's transform
        playerTransform = playerPrefab.transform;
    }

    private void Update()
    {
        playerTransform = playerPrefab.transform;
        FollowPlayer();
    }

    private void FollowPlayer()
    {
        // Calculate the direction from the enemy to the player
        Vector3 directionToPlayer = playerTransform.position - transform.position;

        // Rotate the enemy to face the player
        transform.rotation = Quaternion.LookRotation(directionToPlayer);

        // Move the enemy towards the player
        transform.position += transform.forward * Time.deltaTime * speed;
    }
}
rich adder
rich adder
viral creek
#

ye the code no worky

#

it only goes to the players spawn origin rather than the location every frame

#

@wintry quarry here you go

#

i was thinking it wasnt updating position possibly

rich adder
#

you're setting position to a prefab

#

set position to the spawned transform

wintry quarry
viral creek
#

i need to set position to the clone?

#

how would i do that if it hasnt spawned when it starts...?

wintry quarry
#

No you need the enemy to refer to the clone

viral creek
#

im sorry im like really new

wicked cairn
wintry quarry
#

You just pass the reference on your code for the enemy spawner

viral creek
#

i thought i referenced the prefab already?

#

oh i see my issue

wicked cairn
rich adder
#

yeah but not the object Cloned from it

viral creek
#

i referenced the prefab not the one ing

#

how would i reference the one ing?

rich adder
viral creek
#

so i need it in the enemy spawner script?

rich adder
#

yea dont u have one that spawns enemies?

viral creek
#

i do

rich adder
#

so in there reference the player that was spawned

viral creek
#
using UnityEngine;

public class ZombieSpawner : MonoBehaviour
{
    //Defines All needed for script to run
    public GameObject prefab;
    public Transform spawn1;
    public Transform spawn2;
    public Transform spawn3;
    public Transform spawn4;

    private void Start()
    {
        StartCoroutine(SpawnPrefab());
    }

    private IEnumerator SpawnPrefab()
    {
        while (true)
        {
            SpawnPrefabAt(spawn1.position);
            SpawnPrefabAt(spawn2.position);
            SpawnPrefabAt(spawn3.position);
            SpawnPrefabAt(spawn4.position);
            yield return new WaitForSeconds(30f);
        }
    }

    private void SpawnPrefabAt(Vector3 position)
    {
        Instantiate(prefab, position, Quaternion.identity);
    }
}
#

so i can use the public GameObject Player:

rich adder
#

yea but you drag the one spawned in scene, not the prefab again

viral creek
#

so i would have to do that everytime i hit play?

#

or is there a way for it to happen automatically

wicked cairn
viral creek
#

I SEE

rich adder
#

if your player is spawned at runtime you need a method that finds it

viral creek
#

i have a player tag

wicked cairn
viral creek
#

okay so

#

what i understand is this

rich adder
viral creek
#

my issue was that i did not reference the Player clone i referenced the prefab, prefab doesnt spawn in a clone of it does

wicked cairn
rich adder
#

if its Null assigning a null to a null is pointless

viral creek
#

hence why it just goes straight

#

is that correct?

rich adder
#

they are just blueprints to how gameobject will be constructed

viral creek
#

so it couldnt find an object

wicked cairn
#

prefab is only a gameobject once its in the scene

viral creek
#

and it was like well just go straight since there is no person to lock onto

wintry quarry
#

Prefabs are definitely objects

polar acorn
wintry quarry
#

and they definitely are GameObjects

#

And they have a position

#

whatever position is set in the prefab

wicked cairn
rich adder
#

oh myb then

#

never really thought of them as gameobjects

#

makes sense though they do have position

polar acorn
#

It's weird because they are GameObjects but they also don't exist

viral creek
#

lol

#

they are and arent at the same time

polar acorn
#

Schrödinger's Thing

viral creek
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyFollower : MonoBehaviour
{
    private GameObject Player = GameObject.FindGameObjectWithTag("Player");
    private Transform playerTransform;
    public int speed;

    void Start()
    {
        if (Player == null)
        {
            Debug.LogError("Couldnt find it");
            return;
        }
        playerTransform = Player.transform;
    }

    private void Update()
    {
        playerTransform = Player.transform;
        FollowPlayer();
    }

    private void FollowPlayer()
    {
        // Calculate the direction from the enemy to the player
        Vector3 directionToPlayer = playerTransform.position - transform.position;

        // Rotate the enemy to face the player
        transform.rotation = Quaternion.LookRotation(directionToPlayer);

        // Move the enemy towards the player
        transform.position += transform.forward * Time.deltaTime * speed;
    }
}
#

so this is what i have now

rich adder
#

oh god no..

viral creek
#

and it couldnt find the object

#

oh what did i do now qwq

rich adder
#

this is compile error

viral creek
#

actually it didnt error on compile

polar acorn
viral creek
#

i see

rich adder
#

You can't run a method in initializer

wicked cairn
#

Read the code I sent again lol!

viral creek
#

okay sparklez

#

i mean wont it say that playerPrefab doesnt exist?

rich adder
#

dont just blindly copy code, you have to understand why you need the code you need

wicked cairn
rich adder
#

Assuming that Start function runs AFTER player prefab was spawned

viral creek
#

okay so if i copy that to the code it says tjos

rich adder
#

otherwise ur back at square one

viral creek
polar acorn
rich adder
#

should configure ur IDE first

viral creek
#

in this case it was defined as the playerPrefab earlier

eternal needle
#

!ide

eternal falconBOT
viral creek
#

but i took it out perhaps if i readd the definition

wicked cairn
# viral creek ```cs using System.Collections; using System.Collections.Generic; using UnityEng...
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyFollower : MonoBehaviour
{
    private GameObject playerPrefab;
    private Transform playerTransform;
    public int speed;

    void Start()
    {
        playerPrefab = GameObject.FindGameObjectWithTag("Player");
        if (playerPrefab == null)
        {
            Debug.LogError("Couldnt find it");
            return;
        }
        playerTransform = playerPrefab.transform;
    }

    private void Update()
    {
        playerTransform = Player.transform;
        FollowPlayer();
    }

    private void FollowPlayer()
    {
        // Calculate the direction from the enemy to the player
        Vector3 directionToPlayer = playerTransform.position - transform.position;

        // Rotate the enemy to face the player
        transform.rotation = Quaternion.LookRotation(directionToPlayer);

        // Move the enemy towards the player
        transform.position += transform.forward * Time.deltaTime * speed;
    }
}
```Should be like this
viral creek
#

yeah i just saw that

#

and did that rn lol

rich adder
polar acorn
#

Is playerPrefab a prefab or an object in the scene?

viral creek
#

whats an ide...

wicked cairn
polar acorn
#

It's named prefab but you're getting a scene object

rich adder
polar acorn
wicked cairn
#

they can name it whatever they want

viral creek
#

okay sparklez it wokrs now

#

but id like to see if i understand what i did wrong earlier

#

so, in short i referenced a prefab which isnt ing, so we defined the prefab instead of the prefab as the gameobject that gets spawned in

#

and from there my code runs normal

#

oh

#

and it finds an object with the tag Player and goes to that

rich adder
viral creek
#

so thats why they went to the middle

#

since that was the location i created it

rich adder
#

yes most likely going to 0,0,0

#

which is typically world pos default

wicked cairn
# viral creek but id like to see if i understand what i did wrong earlier

in a brief explanation, stuff like public GameObject stuff will create a empty field. Unless of course its going to use a asset instantiated. What we are trying to do is find a object in your scene that is newly created. In the start() function it will be run for each enemy once they spawn in, thats when they need to find your player active in the scene

viral creek
#

and by chance anyone know what causes this?

#

my wall is fine ing

rich adder
viral creek
#

heres what it looks liek

#

only thing negative is position

polar acorn
rich adder
#

maybe during rintime this happens

viral creek
#

OH I SEE

#

its because i mirrored the original hosue

#

okay thanks!

#

how can i mirror the house wihtout just turning the numbers negative?

rich adder
#

you shold prototype using Probuilder

#

using unity cubes is a bitch an a half to make levels

viral creek
wicked cairn
viral creek
#

miror across the y axis

#

so across the street

#

im making a zombie survival game

#

hence why zombies move to player

rich adder
#

you could Probuilderize the house and use the mirror tool

viral creek
#

i have no idea how to use that or where that even is

wicked cairn
viral creek
#

he does!

#

the zombies beat him up for his donuts

polar acorn
wicked cairn
# viral creek miror across the y axis

Other than probulder, CTRL+D to dupe it and change the rotation to 180 degree, then use the arrow to move it across the street. If you want to make more of multiple objects at the same time you can hold CTRL and click several objects in the hierarchy to select them

rich adder
#

unity also has a FBX exporter package if you want to make the house a whole object

viral creek
#

yeah but when i do the dupe thing the door is on the wrong side

#

i wanted the doors to all be in the center like its just mirrored

wicked cairn
viral creek
#

yeah look

#

and if i flip across the y using 180 it does the same thing where the door is the same spot

viral creek
wicked cairn
#

Hm. strange, hard to tell without messing with it. If you are going to model everything in unity, go for the links they sent (probuilder)

viral creek
#

can i put the house i made into there?

wicked cairn
#

its just a extra set of tools in unity to model stuff

rich adder
#

if you probuilderize it you can use the Probuilder tools on exisiting mesh

viral creek
#

so currently i have this version of unity

#

this is the one my professor told us to download and use

rich adder
#

its in package manager, the version is irrelevant

viral creek
#

how do i acces package manager?

wicked cairn
#

^ in unity Window -> Package manager

viral creek
#

thanks

rich adder
#

I would also grab the FBX exporter incase the house needs to be one whole mesh

wicked cairn
#

Looks like his house is made of a ton of cube objects

viral creek
#

it is lol

viral creek
rich adder
viral creek
#

its not one of the options here

rocky canyon
#

its also in the package manager

cinder crag
#

could i perhaps do this in a better way and not have this mess in one void?

viral creek
#

found it

#

help this man

rich adder
wicked cairn
cinder crag
#

nah meh

#

idk

#

jsut gonna let it be like this idek

cinder crag
rich adder
#

i just pass it an object

cinder crag
#

how can i cahnge the my project into my games name lmao

viral creek
#

where is the option for the mirror at

rich adder
rich adder
viral creek
#

also is it possible to turn it night in the unity setting

#

okay how do i do that?

rich adder
#

its no longer code

cinder crag
viral creek
#

oh yeah my fault thank you navarone!

#

can you help me there navarone?

quaint anchor
#

Hello, I have a question! I am currently attempting to create a rhythm game esq gameplay loop, I'm currently trying to attempt to work out a way to spawn a projectile object that I have and then have it be destroyed upon being hit by the main player, then for the system to check how close the projectile was to being destroyed to a certain point, would anyone know how to do this ?

#

I have this scene set up, I want the projectiles to spawn from the enemy and then travel towards the player, then if the player swings at it, it gets destroyed and depending on the timing award a certain amount of points

fickle plume
#

check the distance to the player at collision event point

quaint anchor
#

how would i make it spawn and fire off in the first place ?

#

I created this script for the behaviour of the projectile itself

wintry quarry
quaint anchor
#

but I want to create a randomly generated pattern spawning system from the enemy object to the player

wintry quarry
#

The physical objects in the scene are more just for presentation

quaint anchor
wintry quarry
#

Using physics definitely isn't the way to go for a rhythm game

quaint anchor
#

what would be the best method then ?

#

would it be best to have say like a circle point that indicates the place where youre meant to hit the note, then upon pressing space or something it checks that area for if a note is overlapping ?

buoyant knot
#

physics is mostly when you have shapes, and need to know when shapes are touching, and exactly by how much, what angle, etc

#

what you are looking for is a system that manages timings of notes, and separately draws a visual representation of said notes/timings to the screen

#

but no physics is needed, because you do not need to ask if the note and relevant note-hitting-object are touching. You just know based on the timing, and the shapes are just graphics.

#

in the case of a rhythm game, a physics engine would make everything sooo much more complicated for no reason

hallow girder
#

I'm making a game where I'm procedurally generating a terrain. I have it all down and it looks good, but I want to make it so that when the player hovers over the cells, it highlights. To do this, I'm trying to create an empty gameObject on top of each cell to handle those highlights, or any other colors. For debugging purposes, I'm trying to make all the gameObjects over the cells some random material, but they never show up. I'm super confused, all of my terrain is generated great, and the mesh's work, but it doesn't work for these game objects??? Ill send my fucntion in the next message

I also have another function that draws the textures for the terrain, but I don't think that should be a problem when just creating game objects? idk im confused lol pls help

#
void DrawTerrainMesh(Cell[,] grid) {
        Mesh mesh = new Mesh();
        List<Vector3> vertices = new List<Vector3>();
        List<int> triangles = new List<int>();
        List<Vector2> uvs = new List<Vector2>();
        
        // Loop through the grid to generate vertices, triangles, and UVs
        for (int y = 0; y < size; y++) {
            for (int x = 0; x < size; x++) {
                Cell cell = grid[x, y];
                
                // Check if the cell is not water
                if (!cell.isWater) {
                    // Create vertices for the cell
                    Vector3 a = new Vector3(x - .5f, 0, y + .5f);
                    Vector3 b = new Vector3(x + .5f, 0, y + .5f);
                    Vector3 c = new Vector3(x - .5f, 0, y - .5f);
                    Vector3 d = new Vector3(x + .5f, 0, y - .5f);
                    Vector3[] v = new Vector3[] { a, b, c, b, d, c };

                    // Create UVs for the cell
                    ...


                    // Add vertices and UVs to lists
                    ...

                    // Add a tag to the cell GameObject
                    GameObject cellObject = new GameObject("Cell_" + x + "_" + y);
                    cellObject.transform.position = new Vector3(x, 0, y); // Adjust position as needed
                    cellObject.transform.localScale = new Vector3(1f, 1f, 1f);
                    cellObject.transform.SetParent(transform); // Set the parent to your terrain object

                    // Add a tag to the cell object
                    cellObject.tag = "Land";
                    
                    // Optionally, you can add a collider to the cell object if needed
                    cellObject.AddComponent<BoxCollider>();
                    cellObject.AddComponent<MeshRenderer>();
                    cellObject.GetComponent<MeshRenderer>().material = highlightMaterial;
                }
            }
        }

        ...
    }
deft grail
hallow girder
# deft grail which is the part of creating the hover

So I have a seperate script that's doing raytracing to figure out if the mouse is hovering over the game object, but I can't even get the game objects to show up in my game. Like they're all there in the hierarchy, but they dont have a mesh and are invisible

#

So I'm trying to really understand this game object stuff before I do the hovering

fossil tree
#

Hi i want make a game of life clone but i really dont see how i can make every square in my grid be editable like when i click on 1 square he become black how can i make that without making 500 gameobject (hope someone understand my request x))

fossil tree
deft grail
#

you change what you can instead of creating new game objects

fossil tree
deft grail
fossil tree
#

For making 500 square how i can without making 500 gameobject

deft grail
#

you would write code to create the objects and place them for you

#

but if your making any sort of maps, you have to create them
you cant just expect them to be done with a couple objects

fossil tree
#

This is what i want do

#

Every square become white when i click on

#

So i make a code who create all the black square ?

deft grail
# fossil tree Every square become white when i click on

then you just as an example you would have

void OnClick()
{
    SpriteRenderer.sprite = newSprite;
}
``` and thats all really it would take i mean if your just changing the sprite, or if you want just colour you can do that also
rich adder
deft grail
fossil tree
deft grail
rich adder
#

You can use tilemap but then you have less options for individual tiles data

deft grail
#

depends what specifically you are trying to do

rich adder
#

I did this recently for a virtual guestbook, honestly went with gameobjects. It was easier

fossil tree
deft grail
dusky pike
#

Hey guys i got a rly random/weird problem.
I generated an Object in Unity. Somehow its not visible in the Szene Renderer but it is in the Game.

#

im pretty sure the problem is here;

#

The MeshFilter only gets assigned after i start the game

deft grail
dusky pike
deft grail
#

so how can it be there before you run the code

fossil tree
dusky pike
#

I thought if i put it on "Awake" it would load before

deft grail
dusky pike
#

ah fucking hell

#

so there is no way to do that with code?

deft grail
#

you can make it so you generate with code through the editor while the game isnt running, im not sure how to do that specifically though

#

you need custom editor stuff i think

dusky pike
#

That makes not a lot of sense for my project tbh

#

but thank you

deft grail
dusky pike
#

yeah, gonna do it that way i guess

rich adder
#

You can also just use a context menu on the generate mesh method code and it will run in editor

dusky pike
rich adder
#

I use it often to generate lists, autoassign stuff before entering playmode

dusky pike
#

thank you!

rocky canyon
rich adder
rocky canyon
#

the only problem i have w/ it is sometimes I get editor errors.. like Null exceptions

#

from some hidden/ unseen part of NA

rich adder
#

yeah You can create it easily in a few seconds though and make your own attribute

#

I been meaning to do it but keep forgetting

rocky canyon
#

ya, i been meaning to look at the internals and see whats happening

rich adder
#

figure out the attributes part like getting the method reference and combined with GUI.Button = profit :p

#

ok yeah basically use this, grab script/method then run it thru button in a custom inspector.

rocky canyon
#

oops.. looks like I have some scripts to refactor now

rich adder
#

2022+ flex

rocky canyon
#

didn't appear until Unity6

rich adder
#

is it supposed to be more efficent or was there just naming change

rocky canyon
#

idk. i only have 1 instance.. so i use the FindAnyObject.. one

#

says faster so i just believe it

rocky canyon
rich adder
rocky canyon
#

lol. ya ur right.. FindFirstObject.. thats basically what FindObject does

#

just realized that

rich adder
#

we cant even see the sauce code so who knows if its just the same thing in a diff name

rocky canyon
#

gotta wait for that next repo dump i guess

vapid lintel
#

Hello guys im working on AR game and since tutorials on youtube are old some things changed, how do i add an AR camera is it included in the XR origin ??

rich adder
#

the only way it would be efficient if we finally get new .net anyway lol

ivory bobcat
#

Differences relative to name:
FindObjectOfType
FindFirstObjectByType

rocky canyon
#

lol.. that raises even more questions for me

rich adder
#

I'd love to do a performance comparison but not even at workstation

vapid lintel
#

Ok thanks man

rich adder
rocky canyon
#

Verrry nice

#

i wouldn't know how to do it.. im very novice when it comes to editor scripts

rocky canyon
rich adder
# rocky canyon works just by including a namespace?

its basically

[AttributeUsage(AttributeTargets.Method, AllowMultiple =false, Inherited =true),]
public class ButtonAttribute : PropertyAttribute
{
}
```and another class i'm doing
```cs
  var extractedMethods = TypeCache.GetMethodsWithAttribute<ButtonAttribute>();
  foreach (var m in extractedMethods)```
#

one problem is TypeCache is UnityEditor class only so I need to figure out how to run that function

rocky canyon
#

wheres the Alias get defined?

#

is it just xxxxAttribute?

rich adder
#

Yeah Attribute gets Remove ig automagically

#

wait no

#

wdym

#

alias?

rocky canyon
#

like [xxxxx]

slender nymph
rocky canyon
#

wheres you saying Button means,

slender nymph
rich adder
rocky canyon
#

oh okay.. soo .TextWindowAttribute would equate to [TextWindow] ?

slender nymph
#

yes

rocky canyon
#

ahh okay gotcha 👍

rich adder
slender nymph
#

i'm not 100% certain since I don't have a lot of experience with custom editors, but i don't think it would actually draw anything for the method with that attribute on it

rocky canyon
#

Im interesting in the drawing part

#

im more interested in the Method calling

rich adder
#

says in the Docs for PropretyAttribute

A custom attributes can be hooked up with a custom PropertyDrawer class to control how a script variable with that attribute is shown in the Inspector.

#

but how dammit..

rocky canyon
#

lol

rich adder
#

or just variables? how does naughty do this..might have to 👀

rocky canyon
#

cheater!

slender nymph
#

naughty attributes has a custom inspector for the MonoBehaviour class to handle that rather than using a property drawer

rocky canyon
#

lol

#

im going to import naughty real quick.. see if theres any issues w/ Unity6

rich adder
#

damm. this might be too much work for just a button..

#

lol

rocky canyon
#

probably why people just use Naughty 😉

#

or ur beloved context window

rich adder
#

ikr . I just dislike being at mercy of third party volatility

slender nymph
rocky canyon
#

im fine with context menu's
there is something spicy about a physical button ofc

rich adder
#

speaking of which I did find a forum post of someone doing it with uitoolkit

rocky canyon
rich adder
rocky canyon
#

lol.. my discord be glitching 😄

rich adder
rocky canyon
#

its a less featured NA but a more customizeable Button

rich adder
#

button with parameters is kinda nice

rocky canyon
#

oh yea. thats my only complaint about Naughty's button.. which isnt a deal breaker..
b/c i usually use a public variable the Button method will use

#

and just populate it as i need when testing w/ a button

rich adder
#

these are only great to spend the time when you're working with Designers

rocky canyon
#

yea, more of a curiousity than a requirement

viral creek
#

how would I make it so that I have the on trigger from a hitbox but I can go through it? I am making a zombies survival 3d game but the zombies can kinda just trap you and insta kill you, I want to avoid that by the zombies allowing players to pass through but still damage them

rocky canyon
#

by marking a collider isTrigger you can pass thru it..

deft grail
rocky canyon
#

instead of detecting it with OnCollisionEnter.. you just swap over to use OnTriggerEnter

hoary yacht
#

!code

eternal falconBOT
viral creek
#

on another note

#

i have a script called BaseZombieScript which is a child of BaseEnemy prefab, I want to reference damage from there what would htat look like?

deft grail
viral creek
#

a variable called damage from the script BaseZombieScript a child of BaseEnemy prefab, to go to the script for my player so that on trigger enter it does damage

rocky canyon
#
    private void OnTriggerEnter(Collider other)
    {
        if (other.TryGetComponent(out BaseZombieScript zombieScript))
        {
            int damageAmount = zombieScript.damage;
            Debug.Log("Damage Amount: " + damageAmount);
        }
    }```
#

something as so

#

other is the collider..
TryGet trys to get BaseZombieScript from the collider's gameobject

viral creek
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyFollower : MonoBehaviour
{
    public GameObject playerPrefab;
    private Transform playerTransform;
    public int speed;
    public int health;
    public int damage;

    void Start()
    {
        damage = 1;
        health = 1;
        playerPrefab = GameObject.FindGameObjectWithTag("Player");

        if (playerPrefab == null)
        {
            Debug.LogError("Couldnt find it");
            return;
        }
        playerTransform = playerPrefab.transform;
    }

    private void Update()
    {
        FollowPlayer();
        HealthCheck();
    }

    private void FollowPlayer()
    {
        // Calculate the direction from the enemy to the player
        Vector3 directionToPlayer = playerTransform.position - transform.position;

        // Rotate the enemy to face the player
        transform.rotation = Quaternion.LookRotation(directionToPlayer);

        // Move the enemy towards the player
        transform.position += transform.forward * Time.deltaTime * speed;
    }

    private void HealthCheck()
    {
        if (health <= 0)
        {
            Destroy(gameObject);
        }
    }

    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "Bullet")
        {
            health -= 1;
            Destroy(other.gameObject);
        }
    }
}

Base Zombie script

rocky canyon
#

damage would be a public int thats accessable

viral creek
#
public class PlayerHandler : MonoBehaviour
{
    //defines important numbers and such
    public int health;
    public int ammo;
    public GameObject Bullet;
    public GameObject BulletSpawn;
    private int BulletSpeed;
    private float cooldown;
    private Rigidbody bulletRigidbody;
    public int kills;
    public GameObject BaseZombie;

    // Start is called before the first frame update
    void Start()
    {
        damage = BaseZombie.GetComponent<damage>();
        BulletSpeed = 20;
        bulletRigidbody = Bullet.GetComponent<Rigidbody>();
        ammo = 100;
        kills = 0;
        health = 100;
    }

    // Update is called once per frame
    void Update()
    {
        HealthCheck();

        Shooting();

        if (bulletRigidbody != null)
        {
            Vector3 direction = transform.forward;
            bulletRigidbody.velocity = direction * BulletSpeed;
        }
    }

    private void GameOver()
    {
        Debug.Log("You Lost");
    }

    private void HealthCheck()
    {
        if (health <= 0)
        {
            GameOver();
        }
    }

    IEnumerator BulletLifespan(GameObject bullet)
    {
        yield return new WaitForSeconds(3);
        Destroy(bullet);
    }

    public void Shooting()
    {
        if (Input.GetMouseButtonDown(0) && (ammo >= 1))
        {
            ammo--;
            GameObject bullet = Instantiate(Bullet, BulletSpawn.transform.position, Quaternion.identity);
            Rigidbody rb = bullet.GetComponent<Rigidbody>();
            Vector3 direction = transform.forward;
            rb.velocity = direction * BulletSpeed;
            StartCoroutine(BulletLifespan(bullet));
        }
    }

    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "Zombie")
        {
            health -= damage;
            Destroy(other.gameObject);
        }
    }
}
#

the script i want to reference from

eternal falconBOT
deft grail
#

and you already got the answer

viral creek
#

the script i want to reference to

deft grail
#

so idk what the code spamming is for

rocky canyon
#

another note.. instead of using other.gameObject.tag == use other.CompareTag("TagBeingUsed")

#
if (other.gameObject.tag == "Zombie")```
no need to even use a tag here.. if it has a script called `BaseZombieScript` then
```cs
if (other.TryGetComponent(out BaseZombieScript zombieScript))
{
         zombieScript.Foo(); // call function
         int damageAmount = zombieScript.damageAmount; // get variable
}``` would be plenty good enough..
#

it would act as a conditional.. (to know if you collided with zombie)
and it would automatically grab the reference to the script (so u can access variables/functions from it)

#

what is this?

#

u dont even have a variable defined for that, heres what i notice

#
  • no damage variable declared (unknown source)
  • is damage a variable from BaseZombieScript or is damage a script of its own..
  • rigidbody gets assigned in start (im assuming with a prefab's rigidbody)
  • it should be assigned to the new instance of the bullet after it gets instantiated (like you have now but no need to set it in Start like you have)
#

i also suspect that your !ide isn't configured.. since you would get errors provided the last script you sent..

eternal falconBOT
viral creek
#

i just wanted to reference that int

rocky canyon
#

then it would be damage = BaseZombie.GetComponent<YourZombieScript>().damage; <-- this would Grab YourZombieScript from the gameobject you assigned to BaseZombie in ur script.. and then access the damage variable... that is if its public

viral creek
#

oh so thats how it works

#

thank you

#

i was trying to find it out online but it wasnt much help

rocky canyon
#

you dont need to do any of that tho.. you can get the damage variable From the zombie script as soon as you collide with it..

if (other.TryGetComponent(out BaseZombieScript zombieScript))
{
         int damageAmount = zombieScript.damage;
         health -= damage;
         Destroy(zombieScript.gameObject);
}```
#

then you could remove public GameObject BaseZombie i dont see any reason for that..

viral creek
#

is zombieScript the class name?

rocky canyon
#

same thing with ur private Rigidbody bulletRigidbody; you could just access it when you need it (each time u spawn a bullet you need that Exact bullets rigidbody

deft grail
rocky canyon
#
  GameObject bullet = Instantiate(Bullet, BulletSpawn.transform.position, Quaternion.identity);
  Rigidbody rb = bullet.GetComponent<Rigidbody>();```
this is good enough for that..
deft grail
#

you really dont know any basics of C# tbh, should follow a tutorial

rocky canyon
#

i agree, no hate.. but the way that script is structured, its bound to give you lots of issues

viral creek
#

so basically what i used was this

EnemyFollower enemyFollower = FindObjectOfType<EnemyFollower>();
enemyDamage = enemyFollower.damage;
``` now that i know how to pull the script
#

and this works

#

i was just trying to learn how to reference another script

#

if i wanted to do it simple i could have used a return damage kind of thing

rocky canyon
#

ScriptName referenceName = theObjectYourSearchingIn.GetComponent<ScriptName>();

viral creek
#

yeah thats what i figured out when you sent the thing earlier!

rocky canyon
#

GetComponent w/o a prefix would search the gameobject the script ur working in is on

viral creek
#

it was a really big help

rocky canyon
#

and the . accesses the prefix so, script.MyVariable; would access MyVariable from the script thats refrenced by the name script

#

good luck.. referencing scripts and variables is a big hurdle for beginners.. once it starts making sense coding gets alot easier

viral creek
#

okay thank you!

#

also i think this was answered earlier but i didnt quite understand, I have this model of a zombie I made and I want to be able to passthrough it but still be able to detect collision

rocky canyon
#

set it the collider to isTrigger in the collider component..

#

u'll automatically be able to pass thru it (hence what a trigger is)

#

to detect it.. Instead of OnCollisionEnter like u'd do with a hard collider
its OnTriggerEnter

#

the rest of the stuff is basically the same

viral creek
#

i use on trigger enter

#

except for some reason i still get stuck inbetween them

rocky canyon
#

you have to actually mark the collider to be a trigger

#

not just change the code..

#

the code is only detecting

viral creek
#

i mean

#

oh

#

perhaps the parent needs it?

#

cuz right arm left arm head and torso all have colliders but the basenemy and arms dont

rocky canyon
viral creek
#

ye look

rocky canyon
#

each collider u want to be a trigger u have to mark every one

viral creek
#

okay so i want the arms to be a collider for damage and the torso to be collider for it to take damage from bullets

rocky canyon
#

some useful tips/hints in here about using multiple colliders

#

probably going to have to use multiple child objects for each collider.. and possibly with tags for each type so u can evaluate what type of collider it is after you collide with it

#
  • Torso Collider
  • Limb Collider
#

just depends on your setup.. and how you are interacting with the colliders.. (raycasts/ collisions/ triggers etc)

viral hemlock
#

should I call rigidbody2d refrences in the start or awake function

rocky canyon
#

Awake <- Set up self
Start <- Set up others

#

if you're setting up references to Rigidbody2D components that other scripts might depend on, do it in the Awake function to ensure they're initialized early in the object's lifecycle

#

if its only important to the script itself.. then it wouldn't matter which one you did it in

wild rivet
#

when i click play my charector i added wont render

#

i added sprite render

#

and added my sprite

rocky canyon
#

is it in front of the camera?

wild rivet
#

when im in scene view i can see my charecetor

wild rivet
#

and its in the camara area

rocky canyon
#

sprites usually are

wild rivet
#

idk why it wont work

#

its super frustrating

rocky canyon
#

press play and then click the sprite and hover the scene window and press F

#

it should focus on the object. and you'll be able to see if its off camera for some reaosn

wild rivet
#

i tried it

#

but it wong work

#

anything else you think of?

rocky canyon
#

nope, the only thing i can think of.. and usually the case is the sprite is either on the same Z coordinate as the camera.. or its behind the camera..
and then if not.. lowering the camera's clipping plane..
when you focus on the sprite it should atleast show you in the sceneview where it is.. after you press play check both the sprites Z value and the cameras Z value

wild rivet
#

ok

wild rivet
#

thx so much

#

it worked!

rocky canyon
#

camera usually uses a -10 z value

#

as long as ur sprites are > than that u'll be able to see em fine

wild rivet
#

i had to set the sprites z to 1

#

well keeping the camara at 0

rocky canyon
#

all good 👍

#

just keep an eye on the Z values if they go missing

wild rivet
#

thx so much

viral creek
#

do you know how I can make it so that my gun object from here can move up and down where the player is looking

rocky canyon
#

most times people have controllers that rotate the camera up and down.. Guns can be parented to the Camera.. and it will rotate as well.

viral creek
#

so drag the gun parent to the camera?

rocky canyon
#

if not u can write a script that can rotate up and down using the mouse..
you can also raycast from ur camera and get a hit point.. and then have the gun point at that point..

viral creek
#

the camera looks up and down fine just the gun doesnt move

rocky canyon
#

if ur camera already rotates.. u can just put the gun object as a child and it will also rotate

viral creek
#

nice

#

ye that worked perfect!

#
if (Input.GetKeyDown("escape"))
{
    Cursor.lockState = CursorLockMode.None;
}
if (Input.GetKeyDown("alt"))
{
    Cursor.lockState = CursorLockMode.Locked;
}
``` and for this how would i use left alt
#

just '''leftalt''' or is there a specific name?

#

i tried alt and it was like nuh uh i have no clue what that is

wild rivet
#

how do i assign/change the x and y position of a gameobject?

tiny wave
#

for moving in x and y, do transform.Translate(*xamount*, *yamount*, 0)
for setting it, do transform.position = otherGameObject.transform.position

rich adder
wild rivet
#

ok

rich adder
#

thats not how you add a new ConstraintSource object

rocky canyon
viral creek
#

i see

#

i used string for left alt i think that worked

rich adder
#

create a new ConstraintSource object

viral creek
#

but if i hit escape i have to click the game again to press alt for it to work

rocky canyon
#

when you use a string "likeyouhavenow" its either defined at the top of the script.. or its using a preset in the

rich adder
#

new () creates a new object

rocky canyon
#

like Input.GetKeyDown("Fire1") that works b/c its a preset

rich adder
#
var constraint = new ConstraintSource()
{
    sourceTransform = theTransform,
    weight = 1,
};```
rocky canyon
#

or Input.GetKeyDown(Keycode.LeftCtrl);

#

Input.GetMouseButtonDown(0);

rocky canyon
viral creek
#

ight thanks

rocky canyon
#

i usually use an alternative for Escape until im done working in the editor

#

back-tick works great

safe hull
#

idk if i'm saying this right, but I want to set the tile at a position in a tilemap based on perlin noise(last part is done). I have no idea how to get the tile and set it though

#

can anyone offer help?

#

I don't understand how to get use x and y to then get a tile from the tilemap and set it to a different tile based on the value the perlin noise returns for that position

safe hull
#

more research! I can't wait. . .

rich adder
safe hull
#

world.SetTile(What do I do here?);

#

I have this

#

but the issue is you have to input a tile

#

and I don't know how to get the tile

#

wait

rich adder
#

you dont have tiles in your project folder?

#

they are just assets
public Tile tile
you can drag one in the inspector for example

safe hull
#

nvm

#

does a ruleTile work?

rich adder
#

haven't played too much with rule tiles, just scriptabletiles (basically the same tiletype usually)

safe hull
#

alright

safe hull
#

alright

#

I got it working

edgy prism
#

When I use List.Count does my count start at 0 for example if I have a list with 5 elements the count is 4 or does it start at 1?

edgy prism
gaunt ice
#

index start at 0, count start at 1

deft grail
gaunt ice
#

or 0 if the list has nothing

inland latch
#

Hi does anyone know if there's a way to simulate lag in unity? i want to simulate lag to test how well my game handles it etc, but i can't find anything online about this. is there a simple way to do it in unity? i know there's the frame step but that isn't exactly what i want, does it have to be done in code by limiting the framerate?

strong wren
inland latch
wintry quarry
#

Single player games don't experience "lag"

#

If you mean a framerate/performance issue, you can use Thread.Sleep

inland latch
#

isn't that lag?

wintry quarry
#

No

#

Lag is a network term

inland latch
#

how do i use thread.sleep?

wintry quarry
#

You just call it

#

And it waits as many milliseconds as you ask it to

eternal needle
#

You wont really get the results you want by doing this though

gaunt ice
#

thread.sleep will sleep the whole editor iirc

wintry quarry
#

I don't really understand what the point of such an exercise would be

inland latch
#

im trying to make a rhythm game and it uses timescale for the beat etc, and im trying to make sure that lag etc doesn't cause it to come out of sync

wintry quarry
#

You mean low framerate

inland latch
#

or sorry, "framerate/performance issue"

wintry quarry
#

Use thread.sleep

teal viper
wintry quarry
#

You can use a random range if you wish or put it behind a button press

#

Or Application.targetFramerate

strong wren
#

These are fine ways to test how logic behaves at different framerates, but this isn't a way to test performance in general.

inland latch
#

im not trying to test performance in general more how my game handles lag spikes which doesn't always mean the game has bad performance

#

frame dips*

teal viper
#

The solution is not to have lag spikes in your game.

inland latch
#

so if someone decides to suddenly extract a zip bomb mid game it means my game has a performance issue

strong wren
#

Hooking Thread.Sleep to input or Random will probably do the job then

viral creek
#

when I turn is trigger on my capsule collider for my player to on it sinks through the floor, how can i prevent this

wintry quarry
deft grail
viral creek
#

it needs to be tho for my player to detect collision with the enemy

wintry quarry
#

It seems you don't understand what a trigger is

#

A trigger doesn't physically collide with things

#

That's the point

viral creek
#

oh i see

#

so on collision would work better?

#

but when i did that earlier my player would get stuck inbetween zombies and not be able to move

deft grail
coarse frost
#

I got bullets with rigidbodys I want to make it so that they dont interact with each other but they interact with everything else

wintry quarry
deft grail
viral creek
#

would using raycast be the better option here?

coarse frost
#

alright ty

deft grail
viral creek
#

for collision between my player and zombies

deft grail
#

your still going into your player

wintry quarry
rich adder
viral creek
#

i see

#

will my pill still collide even though its collider isnt a trigger?

summer stump
viral creek
#

OH WAIT I SEE

#

triggers is for passing through objects

#

but detecting collisions works great for non passing through

#

but what if i get trapped between them they just constantly drain hp and theres no way of getting out

viral creek
#

okay im sorry im like extremely slow

rich adder
#

that would make you phase through them

viral creek
#

on collision would?

#

i thought you just said that triggers what makes passthrough

deft grail
#

again, OnCollision OnTrigger Raycast, does ABSOLUTELY nothing for the collision

viral creek
#

okay

rich adder
#

if you disable collisions betwen layers (player/enemy) they wont collide

viral creek
#

i understand that

#

how would i disable the layer collisions

#

and put them on different layers?

#

its a 3d game

gaunt ice
#

the physics engin will handle all "overlap events" for all colliders (but the callback depends on the rb/layer)

coarse frost
#

if i want a bullet (OnCollision) to bounce off a wall do both need rigidbodies or can i remove it from the wall? they both already have colliders

deft grail
#

that doesnt make sense

wintry quarry
#

If it doesn't move, it doesn't need one

frosty lantern
#

my bad, everything is in vector3int

#

from the moment I saw there was an int version I used it for essentially everything except worldpace transforms

abstract finch
#

I saw this done one time but forgot how, how would I be able to predefine an animation curve to be Linear?

abstract finch
#

ah nvm it does but i still would like to know if I could predefine what type of curve it is

teal viper
teal viper
frosty lantern
#

So I seem to be able to capture the king, but it's not calling the hidden method. do I need to ensure I am calling the king script that inherits from shesspiece or smth?

timber tide
#

Hidden method?

#

if you're doing new on a derived method it's probably breaking polymorphic relations if you're calling it as a less derived type

slender nymph
safe hull
#

@rich adder I did your method and I found that the textures weren't lining up properly. any idea why?

frigid sequoia
#

I am kinda messing with the camera of my game now cause I not sure if I am really happy with it just floating on top of the player for a cenital view. So I am trying something more typical 3rd person behind your back. And now I am wondering... how the heck do I make the inputs now relative to the camara position?

safe hull
#

I tried mirroring and rotating it and it didn't do anything

frigid sequoia
#

Is this just by parenting or how?

safe hull
#

wait nevermind it started happening with my other tile as well

odd mason
#

does anyone know what im doing wrong? trying to get the "elevator" the square thing to detect when its overlapping with object with the despawn tag and its just not working, even though i think i setup everything right, i know it isnt working cause yeah it isnt logging the yousuck string

summer stump
#

also no rigidbody

#

Both are required for OnTrigger messages

odd mason
#

hm alright mustve missed that where i found this thank you

frigid sequoia
# odd mason

Passing this again just cause I see it so usefull for these cases

rocky canyon
#

Kinematic RB will cause a collision event w/ a regular RB? interesting

slender nymph
#

yeah, it's the dynamic rb that sends the collision event there

#

modding discussions are not permitted here

iron steeple
#

Hey im making a movement physics based and i wonder which is the best at handling movement in general and overall

charred spoke
#

There is no best, each movement solution eventually hets fined tuned to the specific game it is meant for

timber tide
#

grab yourself a kinematic character controller and start developing your own

iron steeple
#

What do you guys usually use for general use physics movement

#

I do not know how many ways to move the character using physics

#

Could you tell me a few that usually used

timber tide
#

There's also kinematic rigidbody controller which I'd say is similar to the character controller, but more tied to unity's physics system.

#

they both have different APIs for the most part kinematic rigidbody will still use the related rigidbody methods for movement

blissful spindle
#

https://hatebin.com/tjdqlcmhvd Hi, this is my weapon script in my game and I want to implement some kind of weaponbobing so it moves up and down when I am walking, can someone please help me with that?

timber tide
#

If your weapon sway is working there, why don't you migrate some of that logic over

blissful spindle
timber tide
#

AngleAxis does seem like a good idea here, and you probably want to move it up and down the x axis (tilt)

#

maybe some z for the roll

blissful spindle
blissful spindle
blissful spindle
timber tide
#

I think you'd probably want to use slerp here too considering you're working with quaternion rotations

young fossil
#

Hi. So currently my design looks a bit like this:

  • Scene.cs are scripts that deal with specific functions inside each scene. (Example, MainMenu.cs PlayAdventureMode() )
  • MenuUI.cs / GameplayUI.cs are scripts associated with the game state that handle UI functions. (Example, healthbar changes, button press noises) Main menu has a MenuUI.cs but not a GameplayUI.cs for example.
  • AudioManager.cs manages audio sources aka creating, setting values, etc and puts them through AudioMixers.

So currently my AudioManager has a .Play() method which is called in Scene.cs and MenuUI.cs scripts.

Would it be better to have a SoundPlayer.cs script which deals with audio, then those other scripts depend on it?

topaz mortar
#

bawsi you around? I'd like to talk about designing a good client/server interaction that prevents cheating, but is also fast
my currently implementation is pretty slow, we talked about it a bit the other day

nimble apex
#

how to print list or array or any collections without iterating and concatting any values inside the collection

#

like calling a toString() and everything is printed nicely

#

which tostring() isnt working here

gaunt ice
#

impossible, even you own toString() need to iterate the whole collection
you can use debugger or format it by json

young fossil
nimble apex
#

yeah

#

json

#

it works

nimble apex
#

which is really trobulesome and time wasting

#

but theres really a way, without having to iterate anything inside the collection, just by calling a function and it does magic

 ["100-10000","150-15000"]```
young fossil
nimble apex
#

or

["Apple","Orange"]```
young fossil
nimble apex
#

you serialize the whole collection into json, unity treats all serialized json stream as string, thats why u can print them all out

young fossil
nimble apex
#

yeah i just forgot it

young fossil
#

Just so you know that isn't printing values, it is parsing the c sharp to json. So it doesn't read any values apart from the written text

nimble apex
blissful spindle
blissful spindle
#

can someone help me with this please?

blissful spindle
#

well if someone wants to help me just respond to my message I will be online again in like 3 hours from now THX

tawdry nymph
#

Does anyone know why this code returns pretty much the 32 bit integer limit, dropppoint: x: 2147483647 y: -2147483642

    private int x;
    private int y;
    private RectTransform Rect;
    void Start()
    {
        Rect = gameObject.GetComponent<RectTransform>();
        x = (int)(transform.position.x / Rect.rect.width) - 1;
        y = 6 - (int)((transform.position.y - Rect.rect.height) / Rect.rect.height);
        Debug.Log(transform.name + ": x: " + x + " y: " + y);
    }
eternal needle
tawdry nymph
#

it is on multiple objects and i want to get values for a 6 by 12 grid

eternal needle
tawdry nymph
#

it returns 0 for the width and height for some reason

young fossil
#

I want to know, if I make some scripts that handle different components of the engine, example: Sounds, UI, Animation, etc... Can I then use events to decouple them?

eternal needle
young fossil
#

An example is like an event/listener in UI then the Sound and Scene.cs methods subscribe to it

tawdry nymph
fierce shuttle
whole idol
#

yo guys, what happened to ProGrids in Unity 2024

eternal needle
whole idol
#

I got unity 2022 right?

young fossil
whole idol
#

Im trying to find out how the whole Grid thing works

#

does anyone know why I dont got the ProGrids thing on my window panel?

young fossil
#

I don't mind revising my design if the event approach is better

eternal needle
young fossil
#

It really depends on what is the most decoupled and practiced

fierce shuttle
# young fossil Yep I see your point. I am over engineering it by creating that script I guess. ...

At some point in your chain, a script is going to need to reference something, I often put those higher level systems into a namespace, it helps for organization, but also gives me a second moment to think "does this script REALLY need this system? If I have to go through the effort of referencing it, that means it depends on this namespace... Does it need to or is it trying to do too much?" - though I dont think in your use case an audio reference would be "doing too much", though I think events do sound like a good idea (maybe a bit bias, as I tend to use events to communicate between a lot of systems like UI and gameplay)

young fossil
#

Not that I intend to do it... Just considering every option

fierce shuttle
#

I wouldnt say "unrealistic", events are used in many projects, though at some point youll have to have a class reference something specific, even if you have global events/broadcasters, some script will need to reference those global classes, or pass data/objects through events for another system to respond correctly

#

Another option you could explore are interfaces, though I find they can be a bit tricky to understand and implement effectively, but it can allow a system to become multiple systems, like a IAudioListener, or a IMenuManager, if your various audio implementations/menus have more-or-less the same code in a different flavor

young fossil
#

I use Interface for my gameplay implementation

#

So it should be easy to understand if you could just expand a bit

fierce shuttle
# young fossil Could you expand a bit on the Interface solution? Also thank you massively for t...

Say you had functionality that would be similar in pretty much every menu you make, like public void ToggleUI(bool fadeIn), you could have that in a IMenu interface, and for everything that needs to act like a menu, it can inherit for example MainMenu : MonoBehaviour, IMenu, CharacterSelect : MonoBehaviour, IMenu, etc - some other system can just call IMenu.ToggleUI(true); and have that character, or main menu or whatever fade in, but that same menu could also have IAudioListener if it has common logic with playing audio or subscribing to something audio based, your audio manager could call IAudioListener.Play() without needing to know if its coming from a main menu, a character select page, etc, though in that specific example, it could be overkill compared to an event in your audio manager that other scripts can subscribe/unsubscribe themselves with

quaint anchor
#

Hello was just curious, I'm currently attempting to make a small game where projectiles are fired at a player and the player has to slash to destroy them, I have set up the projectile's behaviour alongside given the player an attack but have no idea how to go about spawning the projectile itself and laso randomising the spawn to say spawn 3 back to back and then maybe like 1 every second, could anyone help?

queen adder
#

hi there, i creating a game, for a school project, and i need help with adding a door, i want to add a door, and when i get close to it, it says " Press E to exit", and if we pressed the game end, i am new using unity, so i dont know how to do that, any help is welcome.

burnt mantle
nimble apex
#

in unity, UI will register an event , or listen to an event and call certain functions to do stuffs

onclick is an intrinsic event given , but can you invoke onclick by script, not clicking on the UI?

#

oh you can, NICE

eternal needle
quaint anchor
#

how would i go about spawning them and using addforce? im new to unity so have no idea how to do this

eternal needle
#

You also dont have to use rigidbody motion, since I see you are directly moving its position.

quaint anchor
#

oh is that not necessary ?

eternal needle
#

The rigidbody is needed if you want it to have collision with walls and such

quaint anchor
#

okay i see, well currently the only collision it would need to have is with the player or the player's hit

#

since if it collides with the player the player takes damage

#

or if its slashed by the players weapon its deleted and adds a score to their score counter

celest holly
#

makes them more realistic

quaint anchor
#

I'm getting this error but im not too sure what it means, this is the line that it takes me to in the players combat script

burnt vapor
#

So you should take a look at this line and figure out what could be null

#

Hint: it can only be one thing

quaint anchor
#

the get component ?

burnt vapor
#

How would you figure out if it is?

quaint anchor
#

probably because i copy pasted code from another enemy with the component named Enemy and forgot to change the line of dialogue LOL

burnt vapor
#

Perhaps

quaint anchor
#

am i able to have more than one of those lines ?

burnt vapor
burnt vapor
quaint anchor
#

like this

burnt vapor
#

I don't know what you mean

quaint anchor
#

since i have these two that i want the player to be able to hit

#

but currently my code is only accounting for the enemy ocmponent

burnt vapor
#

If you want to access the enemy component it must be part of the enemy gameobject you use here

#

I should correct myself, two things can be null here

#

Because not only the component can be null, the enemy variable can also be null

#

This is the very first thing you should be figuring out

quaint anchor
#

im confused where the log goes? just in the line above ?

burnt vapor
#

Yes, definitely before the code or it will not trigger because of the exception

quaint anchor
#

right

#

im confused exactly what i should be logging though ? since the code works fine when trying to attack the enemy object just not the projectile object

burnt vapor
#

First log enemy, then log enemy.GetComponent<Enemy>();

#

Debug.Log(enemy);

quaint anchor
#

so like that

burnt vapor
#

Yes

#

Note there will be another exception popping up if enemy is null but the whole point is figuring this out anyway

quaint anchor
#

oaky well when i run nothing comes up in the console

#

just the same error

burnt vapor
#

Try Debug.Log(enemy == null)

quaint anchor
burnt vapor
#

So the second one is null, which means the call for the component is null

#

This means the enemy variable you are using doesn't have an Enemy script attached

quaint anchor
#

okay right yes that might be the issue

#

i dont exactly want it to hav ethe same script though as I want to make adjustments to the enemy's health without changing the current script

#

ah wait i think i was being stupid this whole time

#

yeah okay so if I attach the enemy script it should work now

burnt vapor
#

Yeah it always needs that, I'm not sure what you tried to do

#

Note if the component is optional you can also use GetComponent and then check if it's null

quaint anchor
#

I was trying to create a seperate script using the enemy script's code since they'd have the same properties just altered a little

burnt vapor
#

The exception is only thrown if you actually apply logic to a null variable

quaint anchor
#

right

burnt vapor
stuck palm
#

Does timescale= 0 stop coroutines?

quaint anchor
burnt vapor
gaunt ice
#

stop wait for second

burnt vapor
stuck palm
quaint anchor
burnt vapor
#

But my guess is that TakeDamage has no effect?

quaint anchor
#

TakeDamage has an effect on the other enemy i was testing out on earlier so if im using the same script should it not function the same ?

jaunty coyote
#

idk if im stupid or what but why does does return an empty array? **
Collider[] hitColliders = Physics.OverlapSphere(Vector3.zero, 1000);** scene is set up fully empty with just a default box collider cube at 0,0,0

burnt vapor
hexed terrace
young fossil
#

Hey guys, I do have another design question: what is the best way of finding scripts in the scene.

  • FindObjectsByType/FindObjectsOfType, for this I have only been using for singletons. Still, I know it is slow and although I used sparingly am aiming for lower-end devices so want to replace it completely.
  • GetComponet with SerializeField and drag and drop inspector. This way seems to be the most intended although I run into issues. If there are multiple scripts of many types, it can be confusing to go through all of them and attach relevant scripts

One "solution" to this problem is to use the Drag&DropInspector->SerializeField->GetComponent way but instead attaching all scripts used in the current scene inside a "management" gameobject, then you reference that single script.

Want to hear other's opinions on it, or if you have a video/resource please share it

jaunty coyote
hexed terrace
#

!code

eternal falconBOT
young fossil
# hexed terrace https://unity.huh.how/references afaik - singletons aren't slow..

Oh okay coool, so your approach is predominantly serialized references. How do you deal with missing references after changing the reference inside the script though? Also, it relies on the editor's inspector to remember and store the references which I have previously had lots of references lost from minor changes to scripts

jaunty coyote
young fossil
#

Because you make a reference and then have to change the name, then you're caught with a bunch of missing reference errors

young fossil
#

Still run into the inspector problems though. Unless there is a way I'm using the inspector wrong?...

strong wren
young fossil
languid spire
young fossil
strong wren
young fossil
#

Does the DI prevent the issue with the inspector I am adressing too?

young fossil
#

Thanks, I'll try it out!

strong wren
strong wren
languid spire
fervent mulch
#

Hi, chatgbt told me use Rigidbody or CharacterController for zombie movement, but i want ask you which one is better? (i use rigidbody rn)

strong wren
#

It should work out of the box. Unity uses IDs stored in .meta files to handle those references.
Make sure your !ide is configured?

eternal falconBOT
strong wren
#

Renaming in VS should work fine too

young fossil
#

Just tested, it removes the reference 💀

languid spire
#

no it wont because the .meta file will not be renamed

strong wren
#

Make sure to use the rename functionality

hexed terrace
young fossil
strong wren
#

Oh wow, it actually doesn't seem to work

wintry quarry
young fossil
#

That is unbelievable

#

Every project I've done in Unity, we have used VS exclusively

hexed terrace
#

Oh you meant renaming a variable. Yeah, use the attribute Prae said

young fossil
#

So... What is the solution here?... Because the whole point of renaming references is usually to improve readability when refactoring, so if that effort is countered with the time waste of dragging the script back again, what is the solution

#

I care about performance so to avoid Find() and other similar methods, but I also care about time efficiency as a developer

#

And yea, you could say "get Rider" but that fixes the issue for a single person in potentially a group of other members

wintry quarry
#

The other members get to manually add the attribute 😉

#

I think - without question - it's the responsibilty of the developer who does the rename to fix the references afterwards.

If you use the attribute that still can look like a process of:

  • Rename (with attribute)
  • Reimport/Re-save all assets that have that reference so they get the new serialized name
  • Remove the attribute
#

Rider of course has another useful feature here in that it tells you exactly where in your Unity project serialized fields have saved values

#

So that makes it easy to track down all the assets that need to change

#

Sorry if this is sounding more and more like a Rider advertisement

young fossil
wintry quarry
#

It is not free

#

unless you're a student

young fossil
#

Seems like the most supported IDE

young fossil
wintry quarry
#

I think so?

#

Idk, I just pay for it. Well worth it in my eyes

karmic kindle
#

Is this the right place to ask about camera problems?

young fossil
#

Does it work well with C++?

wintry quarry
#

If it's camera code

brave compass
wintry quarry
shell sorrel
#

Rider is for C++ as well

wintry quarry
#

Is it?

shell sorrel
#

CLion for Cmake C++

wintry quarry
#

Oh you're right

shell sorrel
#

RIder for vs soultion C++

wintry quarry
#

Ok then yes

shell sorrel
#

so Rider for C++ on windows

#

Clion for cross platform or mac/linux since its all cmake

karmic kindle
young fossil
#

Ugh... Well anyway thanks guys. I'm happy I learned that attirbute exists at least

#

Also does Ride work well for Unreal

strong wren
#

My current Unity instance wasn't handling type renames for whatever reason, but yes, it does work.
@languid spire .meta file is also renamed with the ID intact.

wintry quarry
wintry quarry
strong wren
#

Yes, variable names do need the attribute when renaming, but type renames can be done as is with the renaming functionality.