#💻┃code-beginner

1 messages · Page 119 of 1

amber spruce
#

makes it less laggy

#

and you wont get shot from smth you cant see

#

also whats the best way to keep track of when all the enemies die

sullen zealot
#

something like this will work?

var obj = Instantiate(...);
obj.creator = transform;
fickle plume
sullen zealot
queen adder
#

why does it look like this?

amber spruce
queen adder
fickle plume
queen adder
sullen zealot
queen adder
#

it has to set the RenderCamera with the Main Camera right?

fickle plume
amber spruce
sullen zealot
fickle plume
#
public ObjScript Initialize(Transform tr)
{
  creatorTr = tr;
  return this
}```
#

Then var obj = Instantiate(...).Initialize(transform);

#

And class name should be capitalized too to not create confusion

amber spruce
#

this a good way of spawning them when you go through that

woven crater
#

this is my Scriptable Object. can i make so that i can set Teir_Value any type and value in the editor?

desert elm
#

this will just delete the gameobject this script is attached to after a frame, right?

timber tide
#

pretty much

woven crater
woven crater
#

nvm i can just use float

split dragon
#

Hi. I want to make a zoom change through a script. How to access the zoom change in the screen through a script (what is the name of this thing). I tried to find it on the Internet, but I didn't find it.

split dragon
amber spruce
#

hey so quick question so i have a variable that gets increased by 1 when a enemy spawns and decreases by 1 when a enemy dies that way i can keep track of when all the enemies are dead but if i just check if it is 0 then it will fire before the enemies spawn how can i fix this

desert elm
terse belfry
#

hey guys im jw cos im new to 2d unity what would be the best way to make an infinite flappy bird game?

#

like im talking about generating new chunks of the level

#

ik how to implement the actual gameplay

amber spruce
#
 void Update()
 {
     if (remainingenemies == 0f)
     {
         NoEnemiesLeft();
     }
 }
rich adder
#

no need for Update loop here

ionic zephyr
#

guys does somebody know EXACTLY why is FixedUpdate related to Physics

rich adder
ionic zephyr
#

but why essentially?

fickle plume
#

It's a method that allows to run the code in step with physics calculations

ionic zephyr
#

what do you mean by in step

rich adder
fickle plume
#

on the same frame

rich adder
#

If you're moving rigidbody on Update for example , you're mooving it outside of its intended physics loop and you get weird sync issues , innacuracy more

ionic zephyr
#

ok, i think im getting it but I still need help at understanding whatis THE PHYSICS LOOP

ionic zephyr
#

I already read that and still dont understand

rich adder
#

then idk 🤷‍♂️

graceful oar
#

Anyone good at photon / parrelsync that can help me by any chance?

ionic zephyr
#

I mean, the thing is, Physics Loop is independent of any method in our script?

#

it is just something that exists?

rich adder
ionic zephyr
#

oh okay okay

#

so the only way we can acces that loop is with fixedupdate?

rich adder
#

pretty much

#

you also have Time.fixedDelta time

desert elm
#

hm, I need to instantiate game objects that immediately delete themselves after one frame, but I can't just copy an existing gameobject since it would delete itself- how could I do this?

ionic zephyr
#

okay and what about ticks

#

what are they

fickle plume
#

You can also use coroutines to run on fixedUpdate frames

verbal dome
#

'Tick' isnt used that much in unity context but usually it means one physics frame (or rendered frame)

#

If your physics is set to run 50 times per second (default) then you could aay that the tickrate is 50

ionic zephyr
#

i dont understand teh concept of physics "running"

fickle plume
#

If object is falling, its fall processed every physics frame. It is different from Update frames in that FixedUpdate will guarantee fixed amount of frames to run, they could be late, in that case it will try to hurry them up later, but they will run. Update doesn't care how much frames it will run, and runs as fast as it can.

desert elm
ionic zephyr
#

but what exactly is a frame

gaunt ice
#

addcomponent, it returns the newly added component

fickle plume
ionic zephyr
#

so why are there update frames and physics frames

rich adder
#

or we would have to make our own ticks

#

for every object

verbal dome
ionic zephyr
#

alright Im really confused

fickle plume
verbal dome
#

The Fixed in FixedUpdate means that it runs a fixed amount of times per second, regardless of your rendering speed

rich adder
#

you should at least pool them

ionic zephyr
#

yeah, thats what i understand but I dont get why we talk about physics frames and logic frames

desert elm
rich adder
#

Instantiating and destroying makes a lot of garbage

ionic zephyr
#

i mean

verbal dome
#

No need to create an object for it

ionic zephyr
#

is fixed update called before update?

rich adder
#

you literally were sent the link twice

ionic zephyr
#

yes man I know

rich adder
#

it tells you exactly the order..

desert elm
#

thanks

rich adder
verbal dome
ionic zephyr
#

ok thanks for all I guess

verbal dome
#

It can run twice or more too if your framerate is less than the fixed delta time/physics timestep

gaunt ice
#

actually whether update or fixed update runs first doesnt matter, you can have multiple or none fixed update in one update cycle (also for long run game you cant tell which one run "first", since there is no such concept)

ionic zephyr
#

But if fixedUpdate is the only way to acces the Physics calculations, how is it possible to calculate that stuff inn Update as well

#

Im really lost please help

verbal dome
sullen zealot
#

hello!
if i call ontriggerenter function in antoher function it will just run the function as if it was a normal function?

verbal dome
rich adder
#

eg move the suff from OnTrigger to another method

#

then only call method

#
 private void OnTriggerEnter(Collider other)
    {
        //some code
        //some code
        //bad

        //instead do
        Method();
    }

    public void Method()
    {
        //code
        //code
    }```
now you only need call method
sullen zealot
#

ok

#

but would it work if i just called the ontrigger?

wintry quarry
rich adder
#

if you're manually calling it something is flawed in your design

desert elm
split dragon
#

Hi. I need to find out: Did I access the "speed" variable correctly, which is in another script? It's just that when I launch it, speedFire does not change in any way, unlike speed.

sullen zealot
desert elm
#

which could be done by spawning an object, not as much with the physics2D.OverlapCircle
( I think, i am probably wrong )

rich adder
sullen zealot
rich adder
#

it should work like that afaik

#

child collider sends hit from rigidbody no?

sullen zealot
#

yes

#

but its not a child

rich adder
#

oh..

verbal dome
#

You can loop over them and do whatever you want

rich adder
#

so idk why it would be a big deal to put script on other object if thats what does logic

gaunt ice
#

actually update call is still the most suitable place to call any GetKey since fixed update (you can still call it in fixed update) can still miss the rising edge to stable event transition
key event has four states: idle (getkey==false) rising edge (getKeydown==true) stable (getkey==true) falling edge (getkeyup==true) (clock indeed....), all transitions of state are happening on update so fixed update can miss
lets say if the transition from rising edge to stable happening on t=0.0048s (at 3rd update frame) and you check it in 2nd fixed update frame (0.040), you miss it

sullen zealot
#

bc i want the first object to ignore the second object's trigger if it is triggered by the wrong object

desert elm
sullen zealot
#

bc if i make it a child it will never know if the trigger was called by itself or by the child

verbal dome
split dragon
#

Hi. I wanted to make the variable "speedFire" depend on a variable from another variable "speed" in another script. I wrote this line, but after starting the game, the speedFire value is set to 0, and the speed value changes. What's wrong?

languid spire
polar acorn
split dragon
languid spire
#

so value types. This is basic C# knowledge you should already have. the difference between values type and reference types

rich adder
polar acorn
#

Speed doesn't "track" changes. You set the variable to whatever speed was when that line of code ran

#

You shouldn't have a speedFire variable at all if you want it to track, just use speed (after you cache that getComponent call into a variable you can reuse)

split dragon
#

Too smart for me. I'll figure it out later. Thanks

languid spire
#

ffs guys, I'm trying to get him to understand WHY this is so

split dragon
#

Oh, thanks. Now I kind of get it

polar acorn
#

The concept is more important than the terminology

languid spire
#

except the terminology is how you find the right docs

woven crater
#

hey can i export an indivitual sprite to a png file?

rich bluff
#

from unity you cant with built in tools

last orbit
#

Hello,

can someone help me.

I can't change the color in the fbx that I'm trying to edit here.

how come?

rich bluff
#

you can open the atlas and cut the sprite you need into a new file, with any graphics program

rich bluff
#

what you have selected is not the mesh itself

#

its an empty root object

#

which has several meshes under it

#

each will need a material assigned

#

you can also do this through the imported object ui

#

click on the fbx in projects panel and find materials tab

#

and this is a coding channel

knotty drift
#

do you have to convert color to color32 or do they work interconnectedly

#

can I assign a color value to a color32 variable?

rich adder
#

unity already does it for you

knotty drift
#

alright thank you

rich adder
#

Color32 should be faster afaik, so use that when possible

#

only 4 bytes (color32)
floats (color) are 4 bytes each channel

woeful hedge
#

How to use smoothDamp() to move smooth to a given coordinate over a period of time through a coroutine?

#

chatGPT believes that the smoothTime parameter is the time it takes to arrive, but that doesn't seem to be true.

robust condor
#
public void OnClick(InputAction.CallbackContext context)
{
    if (!context.performed) return;

    var device = playerInput.GetDevice<Pointer>();
    bool hitUI = IsRaycastHittingUIObject(device.position.ReadValue());

    Debug.Log("Did we hit UI? " + hitUI); // Always true

    if (device != null && IsRaycastHittingUIObject(device.position.ReadValue())) return;

    LeftClick();
}

private bool IsRaycastHittingUIObject(Vector2 position)
{
    if (_PointerData == null)
        _PointerData = new PointerEventData(EventSystem.current);
    _PointerData.position = position;
    EventSystem.current.RaycastAll(_PointerData, _RaycastResults);
    return _RaycastResults.Count > 0;
}
rich adder
robust condor
#

When clicking on ground

#

When clicking on GUI

#

So it is hitting the camera??

#

When I hit an object:

rich adder
#

I never seen this through inspector hmm I assume because camera has that physicsraycaster that sends info

robust condor
#

I use Odin

#

public List<RaycastResult> _RaycastResults = new List<RaycastResult>();

#

My instinct says to check for intances of Graphic raycaster

rich adder
#

thoseare what start the ray on canvas no ?

#

I actually never looked into it so I can't say for sure

#

im having issues with some other UI related stuff lol

robust condor
#

Do you know how to check for module graphic raycaster in the result?

stuck palm
#
if (isThrowing)
        {
            lr.enabled = true;
            DrawTrajectory();
            ThrowProgress++;
            print("tp: " + ThrowProgress);
            return; 
        }

I have this code where throwprogress is basically the force that the player throws at. I had this in fixedupdate but the trajectory line was really laggy, but now that i put it in update the throw force is increasing too quicckly, how do i fix this?

robust condor
#

In _RaycastResults

robust condor
#

The raycast can not take layermask apparently

#

I could have checked vs UI layer

rich adder
#

something very wrong if its showing that though

#

I think there is Blocking Objects option on raycaster

#

nvm thats for colliders

rich adder
#

oh the line nvm

#

use Time.deltaTime if you want consitency in update

#

wait what is throw force? the line ?

stuck palm
#

throwprogress is a number that is clamped to 100

#

so its like

#

100% * a force that is defined elsewhere

robust condor
#

public void RaycastAll(PointerEventData eventData, List<RaycastResult> raycastResults)

#

No options

rich adder
#

oh nvm

stuck palm
rich adder
#

this is just the force for the box to be thrown

stuck palm
#

yeah

rich adder
#

then yeah use time.deltaTime

#

ThrowProgress += TIme.deltaTime * multiplier;

stuck palm
#

okay, thanks

robust condor
#

How can I check against this if it is null?

robust condor
#

No

#

"// Can't use IsPointerOverGameObject() from within InputAction callbacks as the UI won't update
// until after input processing is complete. So, need to explicitly raycast here."

woeful hedge
#

does someone knows why SmoothDamp() takes too much time?
I set smoothtime parameter at 0.461 and the result take 2+ seconds although I had break codes which defences float issues

#
IEnumerator IntroMove(Vector3 target, float time)
    {
        Vector3 Start = transform.position;
        doesMoveCoroutineEnd = false;
        destinationX = target.x;
        destinationY = target.y;
        Vector3 velocity = Vector3.zero;
        //Debug.Log(Vector3.Distance(transform.position, target));
        float deltaTime = 0f;
        if (!doesMoveCoroutineEnd)
        {
            while (Vector3.Distance(transform.position, target) > 0.01)
            {
                deltaTime += Time.deltaTime;
                Debug.Log(deltaTime);
                this.transform.position = Vector3.SmoothDamp(this.transform.position, target, ref velocity, time);

                // if (deltaTime > time + 0.1f)
                // {
                //     Debug.Log("bruh");
                //     transform.position = target;
                //     doesMoveCoroutineEnd = true;
                //     yield break;
                // }
                yield return null;
            }
        }


        transform.position = target;
        // Debug.Log("------------Task End------------");
        doesMoveCoroutineEnd = true;
    }```
woeful hedge
#
IEnumerator CaneGunFire(int FireNoteIndex, Vector3 loaction)
    {
...
        timeLeft = player.noteEndMS[FireNoteIndex + 1] - (player.CONSTANT_TIME * 1000);
        timeLeft = Mathf.Round((float)timeLeft) / 1000;
        Debug.Log(timeLeft);

        //yield return StartCoroutine(SmoothMove(new Vector3(transform.position.x + 8, transform.position.y, 0), (float)timeLeft));
        yield return StartCoroutine(IntroMove(new Vector3(transform.position.x + 8, transform.position.y, 0), (float)timeLeft));
       ...
    }```
woeful hedge
#

so actually I excepted SmoothDamp IntroMove will end near 0.461 seconds, but the result is 2.07 seconds

#

How to solve this problem?

languid spire
#

why are you setting timeLeft twice? nvm, i read it again

#

Debug.Log all the values

woeful hedge
#

wait for me

amber spruce
#

hey so i have 3 different enemies each has a different controller script which also deals with health and stuff how do i have them take damage

woeful hedge
#

end of IntroMove()

languid spire
#

these timeLeft = player.noteEndMS[FireNoteIndex + 1] - (player.CONSTANT_TIME * 1000); are the values I wanted to see

woeful hedge
#

wait

#

and it is just converting ms to second I remember

#
        Debug.Log("TimeLeft = " + player.noteEndMS[FireNoteIndex + 1] + " - " + (player.CONSTANT_TIME * 1000));
        Debug.Log(Mathf.Round((float)(player.noteEndMS[FireNoteIndex + 1] - (player.CONSTANT_TIME * 1000))));
        timeLeft = player.noteEndMS[FireNoteIndex + 1] - (player.CONSTANT_TIME * 1000);
languid spire
#

wait, you should be reducing time by deltaTime every itteration of the loop

woeful hedge
#

at where?

#

IntroMove() 's deltaTime has declared 0 at first

languid spire
#

here
this.transform.position = Vector3.SmoothDamp(this.transform.position, target, ref velocity, time);
you are using time as a constant

woeful hedge
#

oh

split dragon
#

Hi. I have a problem: I wanted to do all the sound activation in 1 script (to make it easier and everything in 1 place), I kind of did everything right, but when I start the game, for some reason all the sounds are activated immediately, and they stay that way forever (even though all the objects on which they depend are turned off). What did I do wrong?

woeful hedge
#

💀

#

wait I'll try

#

uh so should I rewrite like this?

this.transform.position = Vector3.SmoothDamp(this.transform.position, target, ref velocity, time-deltaTime);
#

which is the time left for end

languid spire
#

yes

native flicker
#

how could i know when sombody closes the app?

languid spire
#

which platform?

native flicker
#

android

languid spire
#

OnFocus

woeful hedge
#

👍

native flicker
#

alright thx

rich adder
#

also disable PlayOnAwake on AudioSource

thorn holly
split dragon
#

Or do I need to create a separate void for each object?

languid spire
thorn holly
#

well yeah, but node zero doesn't move either

rich adder
thorn holly
#

oh wait i know the problem

#

nvm mb

split dragon
rich adder
lavish roost
#

i have a question about scriptable objects

when using scriptable objects should you add values that can change to them or should every value be fixed but accessible, im having an issue with my item scriptable objects, basically im changing the amount of the item but it changes the whole scriptable object for every item

how are you supposed to handle values that change inside of a scriptable object?

lavish roost
#

so whats the right way to handle the amount the correct way

languid spire
#

seperate serializable class

lavish roost
#

so just an object with the item scriptable object + amount

languid spire
#

yes, per instance of the objects using the SO

#

you can create an instance of the SO for each object, which will allow them to update their own values, but then you still need a way to serialize and save/load it at runtime

lavish roost
#

is it possible to set the variables in the SO to public get, private set so i can avoid doing it by mistake?

rich adder
#

ofc

languid spire
#

yes if you use [field:SerializeField]. they are called Properties btw

gaunt ice
#

field:serializefield

languid spire
#

although why anyone would write code 'by mistake' is beyond me

hushed ingot
#

What version of unity do i need to use to not pay the actrivity fee

languid spire
#

any current version

amber spruce
#

hey so im struggaling with damage here is my takedamage function

public void TakeDamage(float damage)
{
    currentHealth -= damage;

    if (currentHealth <= 0)
    {
        Die();
    }
}

how exactly would i pass the damage i want to deal from another function

hushed ingot
amber spruce
languid spire
hushed ingot
#

Then how come i dont need to pay

languid spire
#

because, if you bothered to do any research, you would know that it starts with Unity version 6

hushed ingot
#

Chill

languid spire
#

then don't be lazy

hushed ingot
#

😉

rich adder
languid spire
#

rofl

rich adder
#

I'm if you're making that kind of cash the last thing i'd worry about is the 2.5%

hushed ingot
#

OKay thanks

languid spire
#

Another one who's bought the mansion in Malibu and the Ferrari even before they've started to design their game

hushed ingot
#

Yes its already on the way 🙂

languid spire
#

Ain't gonna happen kid

rich adder
#

Ferrari Cake

#

but its only a Acura

hushed ingot
languid spire
#

Fact of life, sorry, the truth hurts

amber spruce
rich adder
#

or just look for this class specifically

#

then pass the value in the method as you did any other methods you used..

hushed ingot
shrewd swift
#

in Visual Studio 2019 can I change the color of variables ? or give a special colors to all "Unity" related methods

rich adder
amber spruce
rich adder
rich adder
#

and yeah ofc you can change everything

shrewd swift
safe carbon
#

so OnTriggerEnter in contrast to Oncollision checks if the check mark in clicked but it is still a collision detector?

shrewd swift
rich adder
shrewd swift
safe carbon
rich adder
languid spire
rich adder
#

ah yeah they're in the Environment collapsable

#

my shits always expanded 😆

shrewd swift
#

ty guy

rich adder
#

Triggers detect Collider in Trigger

#

they're not collisions

#

Collisions are solid

shrewd swift
#

doesnt looke like there is a way to customize Unity stuff

safe carbon
shrewd swift
#

oh so its "user"

i thought it wasnt unity related

#

ty again

rich adder
#

yeah these have nothing to do with unity

#

they're common types for coding

split dragon
#

Hello again. I have a problem with the character, or rather with the speed. In my script, there is activation by the keys: "C" and "LeftControl". because of the 61 lines, the 40 line does not work. (when I press C), the speed remains 10. I understand why this is so (because the shift is not clamped, and therefore the speed is 10). How to fix it?

rich adder
#

they're usually slightly imprecise and never exactly the value you want

#

you should not check controller height for speed

#

rather make a crouched boolean

rich adder
split dragon
split dragon
#

Ok. Thanks

rich adder
# split dragon Ok. Thanks

what are you trying to accomplish cause I see a few flaws here . esp Timespeed doesn't have a time.deltaTime you will get all sorts of weird results

#

your decrease will happen fast if you have high FramesPerSecond

#

also once it hit 0 it never gets put to 0 or a bool to stop so it will keep decrease

split dragon
thorn holly
#

The heavens have shined upon to me, for by nothing short of a miracle, my code worked first try.

lunar tapir
#

Hi,
I have a base class named FS_Unit which stands for File System Unit, and have 2 derived classes File and Directory.
I want to make File and Directory scripable objects, while also making them inherit from FS_Unit class. I cannot inherit from both FS_Unit and ScriptableObject.
What can I do?

amber spruce
#

how do i stop all other animations for a character

lavish roost
#

you could make it so directory inherits from file and fs unit inherits from directory

lunar tapir
#

then again, I wouldnt be able to make Directory into a scriptable object because it inherits from File already

#

Basically, is there a way to create an object into a scriptable object when it already inherits for a class?

rich adder
#

wdym

languid spire
amber spruce
rich adder
amber spruce
#

idk i was asking if thats the same thing

#

because i dont see a Stop

pliant mist
#

I wanna make a 3D enemy movement script that just flies directly towards the player but cannot turn quickly meaning if you dodge it will miss

#

is there a good tutorial, most 3D tutorials are more like a top down game displayed as 2d

#

I guess I could get the rotation from the front of the enemy to the player then marginally change the rotation

rich adder
sullen zealot
#

hello!
is there an equivalent in c# for c++ pair<T,T> ?
besides tuple

rare basin
#

dictionary?

#

you could just literally google it

amber spruce
rare basin
#

instead of asking there

sullen zealot
#

i only found tuple

#

on google

rare basin
amber spruce
pliant mist
#

How do I find out how much rotation is need for one object to face another?

amber spruce
#
 private void Die()
 {
     if (enemyController != null)
     {
         enemyController.IsStunned = true;
     }
     if (enemyController2 != null)
     {
         enemyController2.IsStunned = true;
     }
     if (enemyController3 != null)
     {
         enemyController3.IsStunned = true;
     }
     animator.StopPlayback();
     animator.SetBool("Dead", true);
     StartCoroutine(Destroy());
     //Destroy(gameObject, 3f);
 }

this is the die function

stuck palm
#

whats the opposite of ignore collision

#

Physics.IgnoreCollision(GetComponentInParent<CharacterController>(), itemdrop.gameObject.GetComponent<Collider>());

dawn juniper
#

Why doesn't the "public GameObject island" appear as a variable in the controller when I have added the script to it?

stuck palm
tacit estuary
languid spire
pliant mist
dawn juniper
dawn juniper
ivory bobcat
dawn juniper
#

if I click on the script, the GameObject is there.

dawn juniper
languid spire
#

screenshot console

dawn juniper
pliant mist
#

how do you just move something 3f forward regardless of direction

#

like it can face in any direction but I want it to move "forward"

verbal dome
#

Or Quaternion.Inverse and multiplication

dawn juniper
dawn juniper
# languid spire screenshot console

I didn't touch anything in Unity, I just created an empty GameObject and created the script, then dragged the script onto the gamenObjecy called Controller.

verbal dome
#

Sounds like you just want Vector3.forward

languid spire
dawn juniper
#

okey

pliant mist
languid spire
amber spruce
dawn juniper
languid spire
#

odd, sorry I'm out of ideas, this all looks fine

verbal dome
amber spruce
#

any state

verbal dome
#

I figured so

amber spruce
#

can it not be from any state?

verbal dome
#

Any state includes that Enemy1_dead state as well

#

Theres an option "can transition to self' in the transition I think

#

Uncheck that

sullen zealot
#

or reimport the script

amber spruce
dawn juniper
dawn juniper
sullen zealot
dawn juniper
sullen zealot
#

idk then

#

does this happen to all your scripts?

#

or only this one?

flat slate
#

my Particle system wont start per script

#

can someone tell me why?

#

!code

eternal falconBOT
dawn juniper
flat slate
sullen zealot
queen adder
#

I need help on something, where should I write?

sullen zealot
#

just say what you need help on

verbal dome
sullen zealot
flat slate
#

what do you mean?

summer stump
rich adder
eternal falconBOT
#
Where can I get help?

Take a look at #🔎┃find-a-channel

:warning: This is not a channel for official support.

Please do not ping admins, moderators, or staff with Unity issues.

flat slate
#

per button

#

all teh other things in the scripts are working

#

just not the particles

dawn juniper
queen adder
# sullen zealot just say what you need help on

I want to make a map based game (strategy similar to hoi4) I have maps ready but I don't know how to do it (I followed the guides but I don't know how to use it). If you have any advice, I would be very grateful, sir.

sullen zealot
flat slate
#

okay

#

i try

sullen zealot
#

also when playing or starting them check if they are alerady playing.

flat slate
#

okay

sullen zealot
#

something like this:

if(!particlesyst.isPlaying) particlesyst.Play();
if(particlesyst.isPlaying) particlesyst.Stop();
rich adder
#

start with a more basic game

pliant mist
#

game jam scripts are some of the grossest stuff I've ever written

#

how do I make a object spawn randomly inside a sphere but also not too close to the center?

queen adder
#

pixel game ?

sullen zealot
#

yes

flat slate
#

The problem is that the particals only starts when im in the scene view

rich adder
queen adder
rich adder
#

if you plan on doing strategy go though you might want to look into many of those patterns

sullen zealot
#

u want it to spawn on the sphere or inside?

icy cape
#

This might be a really stupid question but why am I unable to attach a script with generics onto a game object. It extends MonoBehavior

languid spire
icy cape
sullen zealot
languid spire
#

how do you expect to specify a value for T ?

flat slate
sullen zealot
flat slate
#

wait

#

maybe it works now

#

no doesnt

summer stump
rich adder
lavish dirge
#

is there a flag/filter or other mechanism to search only for all scripts that are referenced in the hierarchy? e.g. I'd like to find all scripts used by a particular prefab with several dozen objects

#

(also, is there a better channel for editor questions?)

gray crest
#

im having a really simple problem but i cant work it out

using UnityEngine;

public class OneWayPlatform : MonoBehaviour
{
    private Collider platformCollider;

    private void Start()
    {
        // Assuming the collider is attached to the same GameObject as this script
        platformCollider = GetComponent<Collider>();
    }

    private void OnTriggerEnter(Collider other)
    {
        // Check if the colliding object is the player
        if (other.CompareTag("Player"))
        {
            Debug.Log("Player entered the platform trigger.");
            // Disable the collider temporarily to allow the player to pass through
            platformCollider.enabled = false;
        }
    }

    private void OnTriggerExit(Collider other)
    {
        // Check if the colliding object is the player
        if (other.CompareTag("Player"))
        {
            Debug.Log("Player exited the platform trigger.");
            // Re-enable the collider when the player exits
            platformCollider.enabled = true;
        }
    }

    private void OnTriggerStay(Collider other)
    {
        // Check if the colliding object is the player
        if (other.CompareTag("Player"))
        {
            Debug.Log("Player is within the platform trigger.");
            // You can perform additional actions while the player is within the trigger zone
        }
    }
}

my player is just a cube and so is my platform, this code is on my platform. OnTriggerEnter but not the other two. why?

gray crest
#

I just dont know where ive gone wrong

summer stump
shrewd swift
#

i have an issue
i am doing a sort-of rope with hinge joint, and i am attaching my player to the last "part" of the rope
the rope is composed of multiple cylinder of scale 0.1, 1, 0.1
when moving the last cylinder, the player is deformed
when the scale of the cylinder is 1,1,1 i got no issues

is there a way to fix this ?

gray crest
rich adder
#

use Dot Product prob

rich adder
#

never attach things with scales already modified imo

#

separate your visuals with your root objects

shrewd swift
rich adder
#

so that root can be mantained at a reasonable 1,1,1

shrewd swift
shrewd swift
#

can you bake a scale in Unity like in UE ?

rich adder
#

no

shrewd swift
#

maybe i can try adding at runtime a hinge joint on the player

lavish roost
#

is it possible to increase this green border size without changing the image size?

rich adder
#

the Cylinder you are talking about the mesh right ?

#

just Rightclick it and make new partent

shrewd swift
rich adder
#

then only attach to parent

summer stump
rich adder
rich adder
#

that has scale 1,1,1

rich adder
shrewd swift
summer stump
rich adder
#

well no

#

is cylinder the the one that moves?

#

then yea

shrewd swift
shrewd swift
#

endRope is empty object at scale 1 1 1

rich adder
summer stump
shrewd swift
#

player is 1 1 1
but when attached to endRope is has to be 10 1 10 because the cylinders are 0.1 0 0.1
to keep ratio

lavish roost
#

i have a drag function in the inventoryItem script and its based on the size of the green border but its too small

rich adder
#

you have to fix that

#

again seperate mesh from main obj

shrewd swift
#

well i can make a mesh in third party editor

summer stump
rich adder
#

never have visual on your root

lavish roost
shrewd swift
#

what is the "main obj"

lavish roost
summer stump
lavish roost
#

thanks

rich adder
shrewd swift
#

i totaly understood that my cylinders cannot be != than 1 1 1, or my player shouldnt be parent to != than 1 1 1 objects
but then, how do i make the player like its attached ?

rich adder
shrewd swift
# rich adder

how do i make the player "attached" to the rope then ?

shrewd swift
#

if the "root" is somewhere else

rich adder
shrewd swift
#

actual setup:

-rope
--cylinder0
--cylinder...
--cylinder4
---endRope
----?player?```
shrewd swift
rich adder
#

and rope should have a rigidbody with collider then

#

only resize colliders

#

dont resize gameobjects

#

unless they are visual child

shrewd swift
shrewd swift
rich adder
#

the rope is not a chain of hinge rigidbody ?

rich adder
shrewd swift
shrewd swift
rich adder
#

they are nothing more than visuals

#

the "slices" are the sections

shrewd swift
#

i dont understand the link with how to fix the issue tho

rich adder
#

should only be collider,rb,and hinge

shrewd swift
#

im fk lost now

rich adder
#

scale in inhereted through parent to child

shrewd swift
#

yes
so without changing the scale of the cylinders, what is the possible solutions ?

rich adder
#

child is relative scaled to parent

shrewd swift
#

only cylinderX are deformed to != 1 1 1

rich adder
robust condor
#

Is it more common to use this.Function() or just Function() in Unity?

rich adder
#

then end of rope should only be child of rope

#

otherwise fix the cylinder scale..

#

not that confusing

shrewd swift
rich adder
#

or you're passing/registering yourself(the script) to something

robust condor
#

I know, but convention

#

In TS you kinda need it

summer stump
waxen oracle
#

Is there a way to have code activate when there is a collision (im new to unity and c sharp)

rich adder
#

its not a requirement its implied

#

already

rich adder
#

did you google, there are dozens

rich adder
# shrewd swift

well if cylinder 4 has a rigidbody with hinge and moving then obv it need to be attached to cylinder

#

but you have to fix the scale

#

idk how else I can explain it tbh

waxen oracle
#

everytime i google something with unity i get rly conveluted results i figured ill ask first

#

ill try google

shrewd swift
#

okay
seems weird that there is no solution that having 1 1 1 scale

rich adder
#

how's it weird ?

#

scale is inherited I just explained it

shrewd swift
#

feels limited

unkempt goblet
#

having lag issues in main game any common reasosns/fixes?

rich adder
#

get used to doing it

shrewd swift
#

before i leave, what scale is using unity ? so i can model 3D object it another sofware without rescaling ?

rich adder
#

1m

shrewd swift
#

ok ty

rich adder
unkempt goblet
#

how do i do that?

waxen oracle
#

Massive blocks of code for simple tasks usually but ive found a good website for this

rich adder
waxen oracle
#

Btw do u know any good rescources to learn C sharp outside of unity

#

It would be pretty helpful to understand the language itself

unkempt goblet
waxen oracle
#

Alright

#

thanks

rich adder
#

link is there

#

Intro to c#

unkempt goblet
#

@rich adder this is what i got

#

it works fine in the engine but as soon as i build and play the game it starts lagging

rich adder
#

profile it

#

put it in devmode and connect it to profiler
watch a few videos on this , profiler is quite complex but tell you exactly whats going on

true swallow
#

can anyone help me with this? my canvas text isnt showing at all even though it is first in the sorting layer?

true swallow
unkempt goblet
true swallow
#

thanks alot

flat slate
#

i have a problem i think it has to do with the settings from it but my particles do not start when i am just in Game view but they do when i am aswell in the Scene view. do someone know how to fix that?

rich adder
robust condor
#

How can I do this in C#. Instead of looking up by string I want to look up by variables but I want it in a child called "actions", like this:

InputAction pauseGameAction = PlayerInputHandler.Instance.actions.pauseGameAction;

Instead of:

InputAction pauseGameAction = PlayerInputHandler.Instance.pauseGameAction;
flat slate
#

ye they are

#

i show you

rich adder
#

this is prob not code related though, wrong channel

flat slate
#

i dont know where to ask then?

rich adder
flat slate
#

okay thx

gray crest
#

Best way to create one way platforms with 3D rectangles?

rich adder
#

combined with a OnTrigger for check if collider still crossing

pliant mist
#

how do I check the tag of a solid collider colliding with another solid collider?

#

does 3d not have triggers?

summer stump
#

And when you say check the tag, do you mean in OnCollision or OnTrigger?

#

If the former, collision.gameObject.CompareTag()

#

If the latter, collider.CompareTag()

waxen oracle
#

Im trying to add a greyscale filter to my code but my screen just becomes either black or pink, the problem cannot be the shader, as ive tried it with a blank one.

#

using UnityEngine;

public class greyscale : MonoBehaviour
{
private Material mat;
public Shader shad;
public bool grey = true;
// Start is called before the first frame update
void Start()
{
mat = new Material(shad);
}
private void OnRenderImage(RenderTexture source, RenderTexture destination)
{
if (grey == true)
{
Graphics.Blit(source, destination, mat);
}
}

}

eternal falconBOT
past brook
#

how do you call a function from another script, nothing i looked up seems to work or be in date

wild cargo
rich adder
#

calling functions from another script hasnt changed since c# was around..

past brook
wild cargo
#

Don't worry about [SerializeField] for now

agile mesa
clear seal
#

Can someone help me for this script, yesterday i got told that i need to do this but it didn't work

rich adder
clear seal
rich adder
#

no delete this and use links

#

Large Code belong in links

agile mesa
rich adder
#

except use a site from the bot

#

pastbin sucks a donkey

agile mesa
#

should i change it or just for next time?

rich adder
#

next time

#

half the page is wasted on bs

#

man you need to learn an Array

safe socket
#

what are arrays used for in Unity? Know what they are from Comp science knowledge but curious as to how its used

#

i can imagine inventories

celest holly
#

is spawning a script on each individual bullet to move it inefficient? is there a better way to code this?

rich adder
#

you literally use collections in everything substantial you do

rich adder
#

you still need scripts on bullets anyway if you want to do on impact fx maybe

celest holly
#

especially with the collision

rich adder
rich adder
#

but anyway at level you're at don't worry about it

celest holly
#

okay, ill just stick with multiple scripts then

rich adder
#

if it gives you problems profile it later

celest holly
#

the only other thing i was gonna try was a list of the bullets and looping through them each time but that freaked me out a bit lmao

#

thanks for helping

rich adder
#

instantiating and destroying is expensive in comparison

safe socket
rich adder
#

you use them like any other languages usually

agile mesa
robust condor
#

Why is my visual studio using 4GB ram lol

agile mesa
vast ivy
robust condor
#

Nothing, just have 4 scripts open

rich adder
#

are the other ones working ?

agile mesa
#

yes

#

but i forgor some code

rich adder
clear seal
#

can someone quikly tell me how do i use a variable to change key

frosty hound
rich adder
frosty hound
#

Could have quickly just looked it up yourself too

north kiln
#

public KeyCode Key would be the most sensible way, instead of trying a string

rich adder
#

screenshot was cut for some reason 😅

rich adder
#

although you can see editor which type you would need to store @clear seal

north kiln
#

🆒

rich adder
clear seal
# rich adder although you can see editor which type you would need to store <@70447971471405...

`using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;

public class PlayerOneSoccerScript : MonoBehaviour
{
public float speed = 10f;
public float Rotation = 10f;
public KeyCode Key;

// Start is called before the first frame update
void Start()
{
    
}

// Update is called once per frame
void Update()
{
    if (!Input.GetKey(KeyCode.Key))
    {
        transform.Rotate(0, 0, Rotation);
    }
    else
    {
        transform.position += transform.up * speed * Time.deltaTime;
    }
}

}
`

rich adder
north kiln
#

Just pass the Key variable to the function instead of trying to use it as an accessor to KeyCode

#

Also, use three ```, not one of them for a codeblock

rich adder
#

@clear seal
btw if you plan on using collisions, you should probably not move like this
transform.position += transform.up * speed * Time.deltaTime;

bleak prism
#

This might sound dumb, but do you guys think i should make a prefab out of this

#

And when a player is spawned

#

it just spawns the prefab

#

Bcs rn i just have the player forced on the map right

rich adder
bleak prism
#

And i want to make him spawn

#

On a certain location

rich adder
#

you only need to spawn once anyway

#

after that its just teleporting

ashen wind
#

I have two boxing ai that are hitting each other and I want to do a check on collision enter to see what part of the other fighter the boxing glove hit

queen rock
#

Hello. I am struggling with a smooth rotation

void Update()
    {
        // Moving towards waypoint
        Vector3 dir = target.position - transform.position;
        transform.Translate(dir.normalized * (speed * Time.deltaTime), Space.World);

        // Frontside of the enemy looks towards the next waypoint
        Quaternion lookRotation = Quaternion.LookRotation(dir);
        // Smooth rotation
        transform.rotation = Quaternion.Slerp(transform.rotation, lookRotation, Time.deltaTime * rotationSpeed);

        // Has enemy reached the waypoint ?
        if (Vector3.Distance(transform.position, target.position) <= 0.2f)
        {
            GetNextWayPoint();
        }
    }

Right now, the enemy looks towards the next waypoint and does a smooth rotation after he reached the waypoint. But I want that the enemy begins the rotation before he reaches the waypoint. For example 0.5seconds before he reaches the waypoint, he starts the rotation. So the rotation time is equal before and after the waypoint. How do I do that?

ashen wind
#

so I'm doing this

            if (col.gameObject.tag == "boxingGlove")
            {
                Debug.Log(col.gameObject);
            }
#

but it's logging collisions before the fighters even start hitting each other

rich adder
wild cargo
ashen wind
rich adder
queen rock
ashen wind
queen rock
rich adder
#

i have no context on your setup

ashen wind
#

somehow there are a bunch of collisions between the boxing glove and parts of the gameobject it's attached to

#

and I want to filter those out

rich adder
ashen wind
#

yes

wild cargo
ashen wind
#

I want to only check if it's hitting the other boxer

rich adder
rich adder
#

or put Physics.IgnoreCollision method inside

woven crater
#

why calling randomshootangle() does not change the value in each loop

ashen wind
#

cause I don't want the different parts of the gameobject to stop colliding with each other

rich adder
ashen wind
#

I just want a way to differentiate them without putting a unique script on every sub-gameobject

queen rock
rich adder
#

put them inside a list of colliders the one you want ignored and do a foreach loop in the beginning with the Physics.IgnoreCollision @ashen wind

wild cargo
#

Then start rotating when it does

rich adder
ashen wind
queen rock
clear seal
rich adder
wild cargo
ashen wind
ashen wind
#

I don't want the physics to operate any differently than it does

clear seal
wild cargo
rich adder
ashen wind
wild cargo
#

sorry meant to quote the other reply I made

rich adder
queen rock
ashen wind
rich adder
#

and it doesn't matter cause its the first script it finds (GetComponentInParent) for example

#

you only need 1 script on the appropriate player

wild cargo
queen rock
#
using UnityEngine;

public class EnemyMovement : MonoBehaviour
{
    public float speed = 10f;
    public float rotationSpeed = 5f;
    private Transform target;
    private int wavepointIndex = 0;
    private Waypoints waypoints;

    void Awake()
    {
        waypoints = GetComponentInParent<Waypoints>();
        if (waypoints != null)
        {
            target = waypoints.points[0];
        }
        else
        {
            Debug.LogError("Waypoints script not found in parent objects.");
        }
    }

    void Update()
    {
        // Moving towards waypoint using MoveTowards
        Vector3 currentPosition = transform.position;
        Vector3 targetPosition = target.position;
        transform.position = Vector3.MoveTowards(currentPosition, targetPosition, speed * Time.deltaTime);

        // Frontside of the enemy looks towards the next waypoint
        Quaternion lookRotation = Quaternion.LookRotation(targetPosition - currentPosition);
        // Smooth rotation
        transform.rotation = Quaternion.Slerp(transform.rotation, lookRotation, Time.deltaTime * rotationSpeed);

        // Has enemy reached the waypoint ?
        if (Vector3.Distance(currentPosition, targetPosition) <= 0.2f)
        {
            GetNextWayPoint();
        }
    }

    // Getting the next waypoint
    void GetNextWayPoint()
    {
        if (wavepointIndex >= waypoints.points.Length - 1)
        {
            Destroy(gameObject);
            return;
        }
        wavepointIndex++;
        target = waypoints.points[wavepointIndex];
    }
}

I implemented your "Move Towards" suggestion and it works just fine (for now) 🙂

wild cargo
#

Also, you no longer need the "if (distance < some value)" check, just check if it's literally the target position because MoveTowards is that accurate

#

Distance uses sqrt under the hood so better save performance that way

rich adder
brazen cedar
#

Hellooo

#

How can I make this folk stop bouncing? And how can I make it face the player?

rich adder
robust condor
#

Dafuq is this?

brazen cedar
wild cargo
robust condor
#

What services

rich adder
wild cargo
#

jk

rich adder
brazen cedar
#

Thaanks

robust condor
#

Is this normal?

wild cargo
#

Have you tried googling that?

woven crater
robust condor
#

@wild cargoWell it could be normal since the intellisense is pretty advanced. And don't everyone in here use visual studio?

wild cargo
#

Depending on their preferences

fierce shuttle
austere monolith
#

im having trouble with my camera, the little window that shows what it sees isnt accurate and when i zoom the camera out, everything is pixelated

tender breach
#

My rotation issue never got fixed.

austere monolith
#

im having trouble with my camera, the little window that shows what it sees isnt accurate and when i zoom the camera out, everything is pixelated

polar acorn
#

<@&502884371011731486>

north kiln
#

!mute 1038535490133037127 1d spam

eternal falconBOT
#

dynoSuccess azedev was muted.

tender breach
slender nymph
#

also this is a code channel

austere monolith
blazing plank
#

I've got a quick question about the unity line renderer. Does anyone know why it doesn't change the line to the color I set?
The only way to change the rays color is to give it another Material

frosty horizon
#

Can someone tell me why when I click ctrl p it deletes my changes every second time?

blazing plank
#

where should I post my question instead? Can't find a suitable channel

frosty horizon
#

you have to find the solution yourself

clear seal
#

i know the tansform movement doesn't work with colliders and rigid body

#

i got a problem there

#

how do i make it move so it does not go trough the objects

rich adder
lavish roost
#

is it just me or is coding a fully working inventory that works like one in minecraft unexpectedly difficult

robust condor
#

It is a lot of work

#

I spent 10 hours coding my damn camera

lavish roost
#

i was thinking it will take 2 days max or am i just slow

clear seal
frosty hound
#

Not without showing your work

clear seal
#

public class PlayerOneSoccerScript : MonoBehaviour
{
    public float speed = 10f;
    public float Rotation = 10f;
    public KeyCode Key;

    private Rigidbody rb;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if (!Input.GetKey(Key))
        {
            transform.Rotate(0, 0, Rotation);
        }
        else
        {
            transform.position += transform.up * speed * Time.deltaTime;
        }
    }
}
#

here you go

slender nymph
#

at no point here are you attempting to move via the rigidbody. you're also not even using the right type of rigidbody

clear seal
#

oh yeah i forgot to remove

rich adder
#

there were even examples in the link 😔

clear seal
#

hold i think i am on smth

#

no😔

robust condor
#

I'm trying to alter my zoomspeed but it doesn't matter if I set it to 100 or 10000, it is equally fast...

cinemachineVirtualCamera.m_Lens.FieldOfView = Mathf.Lerp(cinemachineVirtualCamera.m_Lens.FieldOfView, zoomValue, zoomSpeed);

zoomValue = 1f, zoomSpeed = 50f to 10000f

#

Also tried with deltatime

spiral narwhal
#
public abstract class CardEffectTriggerSO : ScriptableObject {}

Would an empty class in Unity be acceptable if it is a base for ScriptableObjects? Generally, there is no good excuse for empty classes, but I just need to be able to select CardEffectTrigger SOs from other SOs

teal viper
lavish roost
teal viper
#

It needs to change from 0 to 1 over time for a proper lerping.

#

Should probably read a bit about how lerp working.

lavish roost
#

yeah he needs to multiply by time.deltatime

teal viper
#

No, he doesn't.

#

That might work since it brings the value under 1, but it's still not a correct way to lerp.

robust condor
#

@teal viperanything between 50f and 10000f

#

Same result

lavish roost
# robust condor <@209684227720085505>anything between 50f and 10000f
public class Camera : MonoBehaviour
{
    [SerializeField]
    private GameInput gameInput;
    [SerializeField]
    private float zoomSpeed;
    [SerializeField]
    private float fieldOfViewIncreaseAmount = 4f;
    [SerializeField]
    private float fieldOfViewMin = 10f;
    [SerializeField]
    private float fieldOfViewMax = 80f;
    private CinemachineVirtualCamera virtualCamera;
    private float targetFieldOfView = 34f;

    private void Start()
    {
        virtualCamera = GetComponentInChildren<CinemachineVirtualCamera>();
    }

    private void Update()
    {
        HandleCameraZoom();
    }

    private void HandleCameraZoom()
    {
        float zoomValue = gameInput.GetZoomValueNormalized();
        if (zoomValue > 0)
        {
            targetFieldOfView += fieldOfViewIncreaseAmount;
        }
        if ( zoomValue < 0)
        {
            targetFieldOfView -= fieldOfViewIncreaseAmount;
        }

        targetFieldOfView = Mathf.Clamp(targetFieldOfView, fieldOfViewMin, fieldOfViewMax);
        
        virtualCamera.m_Lens.FieldOfView = Mathf.Lerp(virtualCamera.m_Lens.FieldOfView, targetFieldOfView, Time.deltaTime * zoomSpeed);
    }
}

this is my camera class and the zooming works fine (zoomSpeed is 2 in the inspector) your speedvalue might just be too high

teal viper
teal viper
lavish roost
#

it will never reach above 1 though

knotty gust
#

how would you go about creating a checkpoint system similar to the one present in games like doom(i essentially need the map to be loaded to the same state it was in when a checkpoint was passed)

teal viper
teal viper
lavish roost
robust condor
#

@teal viperOkay, how to zoom faster than 1?

knotty gust
teal viper
teal viper
knotty gust
#

ive tried saving the data for the triggers in a dontdestroyonload object but then the address for the triggers gets changed when the map reloads

lavish roost
#

but 1 is already insanely fast so theres probably something wrong in your setup

robust condor
#

@teal viperSo I cant have a fast and smooth zoom with lerp

#

What should I use instead?

teal viper
teal viper
knotty gust
teal viper
knotty gust
#

i tried having code that would add anything that would need to have its state saved to a list in a dontdestroyonload level manager but since everything was loaded again any references it had would be gone

teal viper
teal viper
#

Basically, you save plain data and then use it to recreate the state(create any new instances of needed). If you need to get a reference to an existing object for some reason, you could save it's I'd and get it by the Id at loading time.

knotty gust
#

okay that makes sense i was just wondering what format i would be saving it into

#

so it could be read after

teal viper
#

Json or binary if that's what you're asking. Xml is also an option I guess.

lavish roost
#

can someone recommend me a book or video series to learn about clean coding especially game code?

#

things like when to use interfaces, recursive methods, structs etc?

knotty gust
#

like if i didnt want a barrel to reload

#

after its destroyed would a new line be created in a file with a copy of its id and the bool thats triggered be sent to the file

#

and that be used to recreate state?

teal viper
# knotty gust like if i didnt want a barrel to reload

Then you save it's state as destroyed:

public class objectState
{
    int objectId;
    int onjectState; // 0 for destroyed
}

Then, when loading the data you get the object by ID and if it needs to be destroyed, you destroy it. The example I provided is very plain and real code might need to be a lot more complex than that, but the idea is the same.

knotty gust
#

ahhh yeah that should be fine thank you

#

just to make sure that would be present in the script of the object and not be its own class right?

teal viper
#

When you're saving, you could iterate all the savable objects and call something like:

ObjectState objectSaveState = savableObject.GetSaveData();
string saveString = JsonUtility.ToJson(objectSaveState);
//Write the string to file or combine it with other save data
knotty gust
#

ight i see what you mean thanks

steep shoal
#

!code

eternal falconBOT
knotty gust
teal viper
knotty gust
#

ohhhh

teal viper
#

In a GameManqger/SaveManager or something.

knotty gust
#

so i would have the data loaded to the level manager

#

the dictionary would be on the level

#

and on load the data would be transferred to the level and state would be set then?

teal viper
#

Sounds about right.

knotty gust
#

thank you man

#

was stuck on that for a few days

teal viper
#

Well, saving systems can get pretty advanced, so it's not an easy topic for beginners.

true pasture
#

im not familiar with enums so how do I reference the enum from another script. myType is the enum variable on the stats script. im trying to check if the type is Player or Enemy

#

im trying to acess it from the myStats script but can't seem to figure it out

teal viper
#

== EnumType.Value

true pasture
#

oh wtf, i swear i tried that

#

thanks

supple wasp
#

I don't know why I get 2 errors. Can someone help me? I'm trying to do the SlowMotion when I press the V key and this comes up.

ivory bobcat
#

Show us the console errors

spring skiff
#

wow, "Application.Quit();" doesent work anymore in the latest 2023.2.3f1 version.

Hello dear player,
please press ALT+F4 in the future because exiting the game via Exit button will no longer supported anymore.

supple wasp
north kiln
#

Just use your IDE to add it via its suggestions

ivory bobcat
spring skiff
ivory bobcat
spring skiff
#

Windows x64

ivory bobcat
north kiln
#

There's nothing in the issuetracker about it

ivory bobcat
#

Maybe you've got something else going on.

spring skiff
#

I did not touched anything since Unity 2021 and it worked everything fine there. Then I updated to the 2022LTS and to the latest 2023f1 and now the exit button doesent work anymore.
LIke I was known it earlier on the linux build of Unity 2021.

north kiln
#

Well, check for a borked button, an exception occurring before your quit call, returning false in wantsToQuit

#

If none of those, test it in a blank project and report a bug

vale karma
#

I have been watching and kind of blindly following code i dont really understand. Is there something im doing wrong in the learning process?

teal viper
north kiln
#

Yeah, the blindly following

vale karma
#

im familiar with most basic things in unity, and the simple code and syntax, but when it comes to using any of it i suck

spring skiff
#

Well, I made a fresh new project with just a exit button and quiting worked just fine, but I also made a print("ApplicationQuit was Executed."); over my Application.Quit in my Main project and see atleast in the Unity Editor console, my Code does reach it.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.Management;


public class ExitGame : MonoBehaviour
{
    private AudioSource audiosource;
    private bool beendenaktiv = false;

    private void Start()
    {
        audiosource = GameObject.Find("snd_Buttonclick_Ausgabe").GetComponent<AudioSource>();
    }
    public void StartTheEnd()
    {
        audiosource.clip = Resources.Load<AudioClip>("click_mainmenu");
        audiosource.Play();

        beendenaktiv = true;
    }

    private void Update()
    {
        //Solange die AudioSource eine .ogg abspielt, wird die Anwendung nicht beendet:
        if (!audiosource.isPlaying && beendenaktiv == true)
        {
            // Das beenden von XR hat zu folge beim beenden des Spieles, das der Standard VR Home
            // geladen wird und die VR Brille nicht stuck ist!
            if (XRGeneralSettings.Instance.Manager.activeLoader != null)
            {
                XRGeneralSettings.Instance.Manager.activeLoader.Stop();
                XRGeneralSettings.Instance.Manager.activeLoader.Deinitialize();
                Debug.Log("XR also stopped by Quiting Game!");
            }


            beendenaktiv = false;

            print("ApplicationQuit was executed.");
            Application.Quit();
        }
    }
}
north kiln
#

Does it hit it in the build though

vale karma
#

it wont exit in unity, if you run the game as an application it should execute whatevers there

spring skiff
spring skiff
north kiln
#

so why not in the build?
I don't know, that's why you need to test

vale karma
#

go to build settings and see if all the scenes are added.

north kiln
#

You've got to drop any assumptions you have to figure out where things are breaking

teal viper
# vale karma ill try that method

One important element of understanding the code is answering the question "what does it do in the context of the whole algorithm?" And "why this code and not different? What does it contribute to the whole program?"

vale karma
#

yea, im thinking im just not seeing the code enough, like school you study one thing multiple times, but trying to build the smallest of games is difficult bc im doing everything in one go

teal viper
#

Yep. You should slow down and break down your code.

spring skiff
#
            /*if (XRGeneralSettings.Instance.Manager.activeLoader != null)
            {
                XRGeneralSettings.Instance.Manager.activeLoader.Stop();
                XRGeneralSettings.Instance.Manager.activeLoader.Deinitialize();
                Debug.Log("XR also stopped by Quiting Game!");
            }*/
#

after I commented it out, quiting was now working.

vale karma
#

what kinda games should i look to make to start out? i made flappy bird, cubonics, and a million other attempts at harder games.

#

oh, pong as well

teal viper
#

Maybe instead of working on a new game, go back to these projects and try to implement some changes.

vale karma
#

good idea, ill try that now

tender breach
#

How do I make an array to make an object a random color?

summer stump
tender breach
#

But how do I make the sprite the color I want?

ivory bobcat
# vale karma I have been watching and kind of blindly following code i dont really understand...

Since this is the programming channel, I'll only target the programming aspect of game development.
How do you feel about C#. It'll be great if you're comfortable with Procedural and Object Oriented Programming.
Have you worked with other libraries/frameworks before? Most would likely introduce you to patterns of subscribing-to/implementing callbacks and whatnot.
If you're fine with the two above, the remainder of what you'd learn from tutorials would mostly be about how specific tasks are approached and interacting with a particular types.

polar acorn
summer stump
tender breach