#💻┃code-beginner

1 messages · Page 356 of 1

swift crag
#
public int CoolInteger => otherObject.myInteger;
wind raptor
#

ah, sure

#

I'm not familiar with =>

#

why not just =?

swift crag
#

this declares a get-only property

wind raptor
#

neat

swift crag
#
public int CoolInteger
{
  get
  {
    return otherObject.myInteger;
  }
}
#

this is the most verbose way to write that

#

=> is used in several places to use an expression instead of a whole block statement

#
public int GiveMeThree() => 3;
#

for example

#
public int CoolInteger
{
  get => otherObject.myInteger;
}

another example

wind raptor
#

Huh, cool. Thanks!

swift crag
wind raptor
#

Briefly

#

public getters, private setters mostly

swift crag
#

just to make it less verbose

#

still kinda iffy on it

hexed terrace
#

I use it all the time

#

for properties and oneline methods

rich adder
#

😮
cursed? public bool IsSpacebarHeld => Input.GetKey(KeyCode.Space);

swift crag
#

very reasonable

swift crag
#

I use => everywhere

west sonnet
#

I have an object with a collider and OnTriggerEnter2D. it's working all good. But the OnTriggerEnter2D is being called when I enter the trigger of a different object? Anyone ever experienced this?

The triggers overlap eachother but they're on different objects?

swift crag
west sonnet
#

But surely OnTriggerEnter2D should only work for the object that the script is attached to?

wintry quarry
violet glacier
#

Sorry for bothering again, but do I put this script inside the main camera?

swift crag
swift crag
#

it would make sense to be on the camera, I guess

west sonnet
#

I have 2 trigger colliders. One Big, and one small. The small one is inside the big one. I have an OnTriggerExit2D on the small collider. If I exit the small collider, it called the OnTriggerExit2D for the small collider, but it also does it for the big collider, despite me still being inside it

polar acorn
west sonnet
polar acorn
west sonnet
onyx tusk
#

how 2 make some field editable on runtime in editor?

polar acorn
violet glacier
#

Would it make sense to put a full 2d game on a canvas? I've read online that the canvas updates every time one object updates.

thorn crown
#

hello, is this where i could ask for help with code?

wintry quarry
#

Here

thorn crown
#

i have this problem where if i have more than one coin in the scene, none of them load except one

polar acorn
thorn crown
#

yeah

polar acorn
#

Show !code

eternal falconBOT
thorn crown
#
using UnityEngine;
using UnityEngine.UI; // Import Unity's UI library

public class Coin : MonoBehaviour
{
    public int coinValue = 1; // The value of the coin, can be set in the Inspector
    public Text scoreText; // Reference to the UI text element

    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("Player"))
        {
            CoinDisplay.Instance.AddCoins(coinValue); // Add the coin value to the coin display
            UpdateScoreText(); // Update the score text
            Destroy(gameObject); // Destroy the coin object
        }
    }

    void UpdateScoreText()
    {
        if (scoreText != null)
        {
            CoinDisplay.Instance.UpdateScoreText(); // Call a method to update the score text
        }
    }
}
#
using UnityEngine;
using UnityEngine.UI;

public class CoinDisplay : MonoBehaviour
{
    public static CoinDisplay Instance; // Singleton instance

    public int score = 0; // Current score

    public Text scoreText; // Reference to the UI text element

    void Awake()
    {
        if (Instance == null)
        {
            Instance = this;
            DontDestroyOnLoad(gameObject); // Don't destroy this object when loading a new scene
        }
        else
        {
            Destroy(gameObject);
        }
    }


    public void AddCoins(int value)
    {
        score += value; // Increase score by the coin value
    }

    public void UpdateScoreText()
    {
        if (scoreText != null)
        {
            scoreText.text = "Coins: " + score.ToString(); // Update the UI text with the current score
        }
    }
}
polar acorn
thorn crown
#

yeah

polar acorn
#

Since CoinDisplay is a singleton, it's destroying every additional copy of it

#

so there is only ever one

thorn crown
#

oh shii right

#

so i should attach it to the UI

polar acorn
#

Doesn't really matter where it is as long as there's only ever one of it

brave robin
#

But there's probably other ways to do what you need

onyx tusk
brave robin
brave robin
# onyx tusk any crutches?

A separate var on the class to expose it, which on Awake is made equal to the static.
Then in OnValidate you copy the separate var to the static, so it changes the static if you modify it?
Its hacky, but might work

onyx tusk
#

i just tried public var i => staticvar; & throught get; set;

polar acorn
willow scroll
#

You cannot simply write public var

onyx tusk
willow scroll
brave robin
#

properties won't show up in the inspector either, so this won't get it to show up unfortunately

willow scroll
#

If you wan to serialize a property, you have to make sure it doesn't have a custom getter or setter

brave robin
#

Ah, true, but in this case they'd need one so that it modifies the static

willow scroll
#
// works
[field: SerializeField]
public Something MyProperty { get; set; }

// doesn't work
[SerializeField]
public Something MyProperty { get; set; }

// doesn't work
[field: SerializeField]
public Something MyProperty => _something;
eager spindle
#

today I learned

willow scroll
# onyx tusk thx
[SerializeField] private Something _myField;

public static Something myField;

private void OnValidate()
{
    myField = _myField;
}
#

That's with the static

polar acorn
# onyx tusk stop, it doesn't work

static things don't show up in the inspector no matter what you put before them because they don't belong to an instance. It wouldn't make sense to have them editable through an instance

willow scroll
# onyx tusk stop, it doesn't work

The code I've shown works unless you're trying to use the variable of type Something, which you probably don't have, or making the property static

willow scroll
#

Cause I'm not sure

#

If you really do need to serialize it this way, why not forget about the static one?

brave robin
#

Sounds like they want a global value for all instances to use?

#

But still control it in the inspector during play?

willow scroll
#

I don't think there is a need for both static and serialized variables. It should be better to just remove the static one

#

This way they can simply make all their serialized variables static, which will definitely reduce the readability

knotty ferry
#

any ideas how to make text ui to hide when gameisoverui shows?

brave robin
#

Have whatever turns on your gameisoverui also turn off the object/canvas/etc that contains the UI you don't want

late burrow
#

but to make sure- loading from text wont cause any loss in quality right? i feel like mp3 -> audioclip conversion might generate much more samples that it has when compressed

rich adder
#

you should start getting into a habit into googling things

tough lagoon
# late burrow but to make sure- loading from text wont cause any loss in quality right? i feel...

I don't see your original message, but regardless of what format you import with - Unity will compress and convert it to a format for your target platform based on your settings. So if you override it as uncompressed, and load in mp3s, yes it will make it bigger. If you add raw wav files, but let it compress by default, it will compress them. What you put in, and what format and compression it uses for the platform, is separate.

#

Unless, of course, you are doing something like live-streaming in the data and bypassing the importer/exporter.

late burrow
#

i dont mean unity compression but just mp3 compression

#

compared to raw audio

tough lagoon
#

OK, you said mp3 -> audoclip though. That will end with a unity asset conversion.

summer stump
late burrow
#

okay so it just me messing up byte conversion then

jagged flame
#

Hopefully this is the right channel. I'm working off a tutorial template and need to fully rename the project.

Folder is named right, and it generates the .sln file correctly.

The .unityPackage still has the old name. I did change the name in Project Settings > Player but I haven't seen that have any effect yet.

If I change the namespace in Visual Studio, everything breaks so that must not be the right track. But I do need that namespace changed as well.

Where else do I need to change this name?

rocky canyon
#

unitypackage is just a package u import.. the name really doesn't matter

#

the folder name is teh projects name.. once u open the project u can go into project settings and make sure hte name matches

jagged flame
#

I did change the name on this page, no effect

rocky canyon
#

it doesn't really have an effect until u build the game.. that becomes the exe name

jagged flame
#

Yeah I saw that the build files are updated now, my bad

brave robin
#

Project name can be anything really, I always just give mine generic names like "Turn based RPG" and then I change the product name in settings when I know the final game's name

jagged flame
#

So the Unitypackage file, am I able to just rename that in Windows Explorer without issue?

#

I already know the name I want 🤷‍♂️ Why are you guys trying to talk me out of this lol

rocky canyon
#

we're not.. ur misundertanding.. the unitypackage is the package u import..

#

liike a zip file..

#

its name also doesnt matter..

slender nymph
#

yeah that unitypackage file is not part of your project

rocky canyon
#

its an extra file thrown in there.. like if u didn't want to open abrand new project.. u could import into an existing project

#

and again its name doens matter because the files inside of it.. are named what they're named and are gonna import the same no matter what u name it

jagged flame
rocky canyon
#

yes. name it whatever you want.. its been answered

jagged flame
#

Thanks

rocky canyon
#

literally means it doesn't matter

#

name it anything u want

jagged flame
#

That's a direct answer if I fully understand the context of how to work with unity, but I lack that context. That's why I needed a yes or a no. Thank you.

#

As for the default namespace, what do I need to do to safely change that?

summer stump
#

Change the default namespace!?

jagged flame
#

Where do I change that? I changed the namespace in VS but it broke everything

summer stump
#

Maybe I am missing some context
But you cannot change the default namespace

jagged flame
#

Damn I'm feeling a really hostile vibe in here. Why are people getting snarky about beginner questions in #💻┃code-beginner ?

brave robin
#

You can rename a namespace in VS through solution explorer

rocky canyon
summer stump
#

Ah, so not the default namespace. The namespace of the package?

jagged flame
#

Disregard, maybe I misread the tone

#

The C# namespace

rocky canyon
#

u can rename ur namespace using the rename.. now if ur ide isnt correct configured that may not change it everywher.e.

brave robin
#

Or possible by right clicking on the namespace in your code and choosing rename

rocky canyon
#

and u'll have to manually change it around the project

brave robin
#

Spawn beat me to it

rocky canyon
#

but it does 👍

jagged flame
#

When I do F2 to change this project-wide, the project stops working. Project Settings doesn't open.

rich adder
#

indeed

summer stump
#

Just to explain my confusion. default namespace is the namespace that is there by default when you don't write any namespace

And you cannot change that

But I see I WAS missing context

jagged flame
#

Ok, I'm going off what VS calls it, the one it will enter into files automatically.

#

I checked if there was a mismatch in .csproj but no references to the name at all in there

rocky canyon
#

RoqueSharpTutorial is the main namespace..

#

.Controller means theres a class called Controller within that namespace somewhere.

#

your renamed would be SomethingElse.Controller

jagged flame
#

Correct

rocky canyon
#

can't remove that .Controller bit unless u rename it as well

short hazel
#

Given that VS is configured and the project is loaded, hitting Ctrl + R twice while the caret is over the namespace name will trigger a project-wide rename operation

rocky canyon
#

try this

jagged flame
rocky canyon
#

try what spr2 mentioned.. im working out of VSCode at the moment

jagged flame
short hazel
#

Stopped working as in, you got errors? Scripts detached from game objects?

jagged flame
#

No, it loads the game but none of the sprites from the look of it

#

Canvases are intact

#

No sound to check

#

Changing that namespace back causes it to work again

#

So I think there is still a mismatch somewhere

short hazel
#

Unless the sprites are loaded from the code, it's unrelated to the code

brave robin
#

Console might be full of warnings about monobehaviours being missing

rich adder
#

not a limbo master

jagged flame
#

What daily yoga does to a mfer

rich adder
#

that looked painful

brave robin
#

"Look up"
SNAP
"... ow."

late burrow
#

57 million long byte array

#

meaning takes up around 57 megabytes

#

going below that would reduce audio quality isnt it

#

how is audio file itself much smaller then

summer stump
late burrow
#

i debug logged the samples in untiy

#

57 million bytes, 14 million floats

#

mp3 is some kind of zip isnt it

summer stump
late burrow
#

that why i was getting huge white noise when going for mp3 itself

#

because it was compressed and unusable

#

so i need in fact convert it to raw audio

summer stump
late burrow
#

i dont mean that

#

mp3 is 3mb

#

pcm is 60mb ish

summer stump
#

Yes.....
Not sure what that has to do with what I said.
Compressed files are indeed smaller

slender nymph
#

oh dear god, please don't try and encode a 60 megabyte file to base64 just to download it as a string like i just know you want to

late burrow
#

i will definelly not use base64

#

just raw byte

#

dropped from 75mb to like 57

slender nymph
#

again, why do you need to do all of this. you know you can just download the audio file directly from the server, right? you don't need to convert it to a string, send it to the client, then convert it back

#

and all of this is still illegal no matter how you try and go about it because you do not have the rights to distribute these songs

#

what you are trying to do is actual piracy

late burrow
#

its not about songs or whatever

summer stump
#

Oh damn. Did not realize the context.
Alright, I'm out

late burrow
#

its just my main possiblity of downloading things

#

i use strings for everything

slender nymph
#

which is pretty fucking wild considering you don't need to do that at all

short hazel
#

Generally speaking, transmitting stuff over network is done using a stream of bytes. Of course you can interpret these bytes as characters, but why?

late burrow
#

i already succeeded at that

#

the issue im seeing is i should take dirty work in my hands with changing formats

slender nymph
#

and i can succeed at flinging my shit at unsuspecting zoo goers, that doesn't mean i should or that it is in any way a good idea

#

you don't need to do all this reencoding just to download files as strings when unity already comes with tools to download files very easily at runtime

summer stump
late burrow
#

whats the use of mp3 bytes for audioclip creating

#

they are unusable

#

need be turned into something else

short hazel
#

If you don't know the format of what you're getting from the server, why not write it to a file and put it through an online recognizer? There are plenty of services which can guess the file type based on their contents

late burrow
summer stump
late burrow
#

just everything else than pcm has not worked

#

wav semi worked but i heard some noise in background already

rich adder
#

did you debug ? if so how

#

for example would start with
LevelManager.GetInstance().currentLevel putting that into a variable

#

debug it

knotty ferry
#

i debug it

rich adder
#

never assume your values are what you think they are

knotty ferry
#

it says timer added

#

but in other scenes like level 1 level 2 the text updates

#

but in level 3 it doesn't

rich adder
#

so just text doesn't change? but the value adds?

knotty ferry
#

yes

#

u are correct

short hazel
rich adder
#

be careful with this

#

timerScript = FindObjectOfType<TimerScript>();

#

this will find the First one it can,

#

make sure you dont have 2

knotty ferry
late burrow
rich adder
#

make sure it grabs the correct one

knotty ferry
#

mhm

rich adder
#

since this is going ontimerScript.timer.ToString

knotty ferry
#

but in other scenes it works in the level 3 scene it doesn't 🤔

rich adder
#

thats why i said to check if you dont have an extra TimerScript left over somewhere in scene3?

#

also debug.log your currentLevel

knotty ferry
knotty ferry
knotty ferry
rich adder
#

where did you put log

#

alr

#

can you show me during playmode in level 3 the ObstacleController object

knotty ferry
rich adder
#

screenshot of the inspector

#

also mp4 for embedding video on discord

knotty ferry
#

me bad i thought u asked video

rich adder
#

nah just need to see during playmode which component it has

knotty ferry
rich adder
#

Obstacle( Timer Script)

#

is this correct to you ?

knotty ferry
rich adder
#

that doesn't answer the question lol

rocky canyon
#

u know if u disable that script.. it can't re-enable itself..

rich adder
#

Do you want ObstacleController to get TimerScript from Obstacle?

knotty ferry
#

yes

rocky canyon
#

im suprised ur still working on this 😄

knotty ferry
#

Xd

#

it's new

rocky canyon
#

ahh okay

rich adder
#

that makes no sense. wdym thought you said the one from Level Manager

#

why would you want Timer from the Obstacle

#

why is it still there in the first place

#

You dont need 2 timer scripts..

knotty ferry
#

but one script is for level manager

rich adder
#

You're grabbing the one disabled

#

what use is that

knotty ferry
#

in level manager GO its enabled

rich adder
#

so what?

knotty ferry
#

so i don't think that would work without it

rich adder
#

what?

#

whos talking about the Level Manager one

knotty ferry
#

alr i will disable it

rich adder
#

what?

#

thats not what I said at all

knotty ferry
#

u saying that im grabbing the one that is disabled

rich adder
#

yes.

#

thats what FindObjectOfType does

#

it literally finds the object of type

#

it doesn't care if its disabled or not

#

it does have a bool you can pass for that to disable

knotty ferry
#

ok

rich adder
#

to recap, You're not grabbing the one that is useful to you LevelManager timer script

#

you're grabbing the one on obstacle that is disabled, hence why the text isn't changing

#

because value isn't updating on correct script

#

You should not even have the one on Obstacle was my point from before

knotty ferry
#

ok

#

i need to change to grab the one that is enabled

rich adder
#

you could..sure..or just delete the extra copy.

#

again, why do you need 2 Timer scripts?

knotty ferry
rich adder
#

why are you showing me this?

knotty ferry
#

i can delete the other one

rich adder
#

if its disabled why is it even there ?

#

you still have not answered that

knotty ferry
#

i wasn't focused on that problem so i didn't do anything to the script i fixed it

final totem
#

should i use DieID = Animator.StringToHash("die"); then set bool or the .setbool("die") for string lookups?

slender nymph
#

using the hash is more efficient over a long period of time (assuming you store it in a field and don't just hash it each time). if you just need set it once or twice though using the string directly is perfectly fine

rich adder
ember tangle
#

do you ever have an epiphany and suddenly realize that you can turn 30 lines of code into 5?

#

what a great feeling

#

lol

timber tide
#

then you realized maybe you shouldn't have shaved off that vector normalization

willow scroll
polar acorn
#

And that one line can become zero when you decide to just lay face down on the floor and dream your game into existence

jagged flame
#

Trying to open a UnityPackage, and the launcher just spins endlessly. How do I troubleshoot this?

#

God damn it, just click it a bunch of times? Why the hell did that work

strong wren
#

nah when i was a beginner they were all bulying me cause i didnt know how to round with code

calm dove
#

guys which better to detect the attack from an object is it by using polygon collider or a raycast?

polar acorn
strong wren
stray jacinth
#
namespace Phone
{
    using Player;
    using UnityEngine;

    public class PhoneAnimation : MonoBehaviour
    {
        public Transform phone;
        public Transform camera;
        public float rotationSpeed = 5.0f;

        private Quaternion originalRotation;
        private Quaternion targetRotation;
        private bool isRotatingToPhone = false;
        private bool isRotatingBack = false;
        private float transitionProgress = 0.0f;
        private bool toggled = false;

        void Start()
        {
            targetRotation = Quaternion.LookRotation(phone.position - transform.position);
        }

        void Update()
        {
            if (Input.GetKeyDown(KeyCode.Q) && !isRotatingToPhone && !isRotatingBack)
            {
                toggle();
            }

            if (isRotatingToPhone)
            {
                camera.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, rotationSpeed * Time.deltaTime);

                if (Quaternion.Angle(transform.rotation, targetRotation) < 0.1f)
                {
                    isRotatingToPhone = false;
                }
            }

            if (isRotatingBack)
            {
                camera.rotation = Quaternion.RotateTowards(transform.rotation, originalRotation, rotationSpeed * Time.deltaTime);

                if (Quaternion.Angle(transform.rotation, originalRotation) < 0.1f)
                {
                    isRotatingBack = false;
                    phone.gameObject.SetActive(false);
                }
            }
        }

        void toggle()
        {
            if (toggled)
            {
                PlayerController.instance.toggleMovement();
                isRotatingBack = true;
                toggled = false;
            } else {
                PlayerController.instance.toggleMovement();
                phone.gameObject.SetActive(true);
                originalRotation = camera.rotation;
                isRotatingToPhone = true;
                toggled = true;
            }
        }
    }

}```

 Does anyone know why whenever i press Q it just locks forward and doesnt let me unforward
tired peak
#

hello i need help with something, im coding for a school project and decided to make kind of a horror game and im stuck, i want to when my player and my"monster" collides ther pop ups an image, i dont get it to work please:D

polar acorn
tired peak
#

pop up, collision is showing in the debug

#

i just need the image to "activate"

tired peak
#

@polar acornthx ill take a peek

summer stump
strong wren
#

yeah ofc if they wouldnt bully me here they would get muted but in dms not really

summer stump
strong wren
#

YES SIR YES SIR 🫡

timber tide
#

you can mute dms per server too so opt into that setting

rocky canyon
#

i need to do that ^

#

i get unsolicitd messages all the time..

tired peak
rocky canyon
#

"since ur the one that helped me the most... do mind just doing my entire project for me!?

cosmic dagger
#

i did not know that either . . .. . .. . .

polar acorn
timber tide
faint agate
#

I have a sphere gameobject, the X and Z axis are locked, so I can only move the gameobject up and down on the Y. A script is attached to the gameobject that allows me to click and drag it up and down.

The problem is when I hold the gameobject and move far or closer, the gameobject moves a lot faster and not the speed of the player looking up and down. I understand the issue is the X and Z axis being locked is causing this, but I’m having a hard time finding a way to fix it without unlocking them.

#

the z and x axis constraints are not in code but on the gameobject itself with a component called, " position constraint"

rocky canyon
frail laurel
#

how to make with playerwalksound when gameisover the script must disable??

tired peak
faint agate
rocky canyon
#

no more annoying red pills popping up everywhere'

faint agate
polar acorn
polar acorn
rocky canyon
#

how to make it so my player doesn't make walking-around (footstep) sounds after the game has ended

#

lol.. feels like price is right..

frail laurel
#

yes

faint agate
rocky canyon
#

you could set teh footstep script to be disabled.. in the gameover script.. (using a reference to the script)

polar acorn
polar acorn
void thicket
void thicket
#

Sound like you could utilize raycast to the plane

polar acorn
#

You'd make a plane at the ball's XZ, and get the ray from the center of the camera

rocky canyon
# frail laurel okey ima try

just use a [SerializeField] private FootStepScript footSteps; and u can drag in the gameobject / the scripts on

polar acorn
#

Then, get the plane intersect point, ignore the X component, and set the ball to that Y position

rocky canyon
#

then its just footSteps.enabled = false;

#

or footSteps.gameObject.SetActive(false); to disable the entire gameobject

arctic shadow
#

hi i know it is probably a stupid question but i have looked around and can't find anything to match what i need to do. Is there a way to transfer the information from a variable in a different "void" ,don't know what to call it, as i am having a problem where it wont unfreeze a rigidbody's position as it doesn't know what it is.

frail laurel
void thicket
polar acorn
rich adder
slender nymph
frail laurel
rocky canyon
#
        // Check if the player is below the ground
        if (transform.position.y < -10)
        {
            isDead = true;
            gameManager.gameOver();
            footSteps.enabled = false; // Disable foot steps when game is over
        }```
#

this should disable it..

void thicket
polar acorn
arctic shadow
rocky canyon
#

did u check the inspector after the code should have run

#

the tickbox next to hte component should become unticked

slender nymph
arctic shadow
#

Thanks didn’t see the message from someone else earlier

rocky canyon
#

CombineToMakeC(1,2);

rocky canyon
#

ya, check the gameobject and see if the tickbox next to the component is ticked or unticked

rich adder
#

whats good with those speed lol

frail laurel
#

;Dd

rich adder
#

someone doing Rigidbody * time.deltaTime?

polar acorn
# frail laurel

Okay, so the object you have assigned to footSteps is being disabled

frail laurel
#

yes it does say that

polar acorn
frail laurel
#

i don't have any other variables to assign

#

it

polar acorn
#

I have no idea how that is an answer to my question. Why two variables that hold the same reference?

rocky canyon
#

yea, thats odd.. if u already had one.. there wasn't a need to create another one..

frail laurel
#

oh

#

okey

#

fixed it

#

but it still doesn't turn off the playerwalksound

rocky canyon
#

i dont see how thats possible.. unless something else is enabling it

#

you could just mute the audiosource

frail laurel
#

how?

rocky canyon
#

all its functions and parameters are down below..

#

audioSourceReference.mute = true;

#

or audioSourceReference.Stop();

#

and before u go gungho with it.. audioSourceReference is just an example name.. and u use w/e u want to call urs..

#

as long as it has a reference like any other type

#

umm.. idk what to do here

rich adder
#

wat

#

Transforms are attached to gameobjects

#

you can't create one without the other

#

those are separate things

rocky canyon
#

i'd just create a transform within the gameobject and use what u need from it

rich adder
#

make a custom struct

rocky canyon
#

u can unattach it when the game starts

#

orrr custom structs work too

#

just more typing..

#

i use a transform for a car controller i have.. the transform follows the rigidbody but can't be parented to it..

#

so the script just references it.. and i unattach it at start

#

mockTransform.parent = null;

#

mockTransform.transform.forward i see what ur doing there

#

i do that too.. i call them mimics

#

lol

#

yeap.. just use u an extra gameobject for its transform

#

and call it a day

smoky bobcat
#

Hey everyone can someone help please, i want my character to jump but he don't jump

rich adder
#

oh jesus

eternal falconBOT
rich adder
#

also !ide

eternal falconBOT
smoky bobcat
#

How ?

rocky canyon
#

with windex probably

rich adder
#

haha microsoft using github to show other peoples code

rocky canyon
#

😄 lmao just messing.. but for real.. post code using an external paste bin site or something

rich adder
#

ik its just funny , when you agree to a free* account

smoky bobcat
languid spire
smoky bobcat
#

Ok thx

rocky canyon
#

just the 1

#

unless VSCode is trolling me in the background

#

i renamed the symbol yesterday and all was fine..

#

today i got all those errors.. which all i had to do was modify a character or so and resave

#

and they get fixed

#

¯_(ツ)_/¯

#

its unity6 soo i guess ill give it a pass

short hazel
#

If you don't make your own constructors, by default the class will already have a parameterless constructor accessible.
Do not implement constructor on classes deriving from MonoBehaviour. As Unity manages the lifetime of the objects, constructors might be called at unpredicatable times, or not called at all.

#

Do not call constructors on classes deriving from MonoBehaviour, they won't be attached to a GameObject and it's not valid, use AddComponent<T>() instead

rich adder
#

creating GameObject is okay just not MB

#

Unity handles MB for you , so you use Awake as faux constructor (to setup object)

rocky canyon
#

am i missing something?
wouldn't it just be cs GameObject newGameObject = new GameObject("MyGameObject"); Transform newTransform = newGameObject.transform;

strong wren
#

how can i change a String to a Float?

#

i know that i can easily change a float/int/double to a string using .toString() but there isnt a toFloat Maybe ToInt32 b

short hazel
#

float.TryParse() method, it's the safest way as it can handle invalid input

strong wren
#

tysm,

rocky canyon
#

yay! 😄 lol

rich adder
#

is default spawned at Vector3.zero worldpos?

gaunt ledge
#

exporting unity build for android, and it keeps giving me gradle failure, do you guys know how to solve this?

faint agate
brave robin
faint agate
#

https://gdl.space/obepoxumel.cs
this is what I have connected to the object for me to move it. Do you think I can do it with what I have or need a whole new method

rich adder
#

if it works ur fine

#

i usually move it in update and just use a bool in the OnMousedown/up

faint agate
violet glacier
#

Are animations in canvas ui expensive?

short hazel
swift crag
#

Animations can cause layouts to get recalculated every frame

brave robin
short hazel
#

Or use a tweening library which doesn't use the animator system.
Before changing things though, make sure you have used the profiler and confirmed there's an issue caused by excessive canvas renders

swift crag
#

would using the animation system actually matter?

#

it's just setting properties on things

#

I guess it can wind up setting lots of properties on lots of things, constantly

short hazel
#

Not if you only keyframe the stuff you plan on changing

brave robin
#

I have my own fancy layout group classes that I use to "animate" UI elements from time to time, and haven't noticed any performance hit when using them. But when I'm doing that there's only UI being rendered and nothing else is going on. I'm not simultaneously rendering a 3D scene under my fancy moving UI.

swift crag
#

I don't have much UI animation beyond fading canvas group alpha, but I do have a lot of menus. I deactivate whatever isn't being used and it runs very well.

#

I did used to have a problem where I deactivated the entire menu when its alpha hit zero...but I was using SmoothDamp to change the alpha

#

0.0000000001 > 0

short hazel
#

Faster customization of easings, predefined effects, ability to chain them or run them at the same time

swift crag
#

ah, fair enough

#

i was thinking you were talking about performance there

short hazel
#

Depends on if you prefer doing it all via code, or with curves

swift crag
#

i vastly prefer code-driven behavior

rich adder
strong wren
#

how can i get the Volume Variable to be the same as the slider value

#

ive tried some stuff like Slider.value = float; but that just makes the Slider unusable

brave robin
strong wren
#

it only works when i change the volume variable thru the inspector

faint agate
# rich adder yea

the issue im having is creating a planeraycast on an object in which the script is assigned to that object to move. How can I make a plane at the objects XZ axis if that same object is whats holding my script to move using ScreenToWorldPoint. I think I may need a new method to move the object, but this is the only way I know I can move it without holding the actual object

eternal needle
brave robin
strong wren
astral falcon
#

So, its getting late, my head is stuck 😄 Does anyone have a quick hint on how to achieve the following. I got a hand and head position, I want to target the UI to stick with the hand (working) and look at the head (working). What I am missing now is, how do I add some kind of offset to the final position in relation to the angle?

                Vector3.Lerp(
                    uiRuntime.transform.position,
                    XRHandPalm.instance.transform.position + offset,
                    Time.deltaTime * RuntimeHandler.Settings.uiFollowEasing
                );
rich adder
strong wren
brave robin
strong wren
#

its confusing but if u look at the first letter of those variables one is capitalized and one isnt

#

making them 2 different variables

brave robin
strong wren
#

i dont even have a update method

brave robin
#

And if you remove SettingsManager, does your slider move again?

strong wren
#

yeah

#

i dont have to remove it tho

short hazel
strong wren
#

its only when i say smth like
Volume = VolumeBar.value;
or
Volume = volume;

strong wren
short hazel
#

It's an option that appears when you select the method to call on the event

#

In the Inspector

strong wren
#

ohh

#

yeah i do have it as dynamic

brave robin
strong wren
astral falcon
#

So how would you add lets say 0.5 to the right inside my code snippet?

storm pine
#

Maybe you have check the "Whole number" thing on your slider by error or something and you are trying to obtain a float, idk. A slider isn't that hard to use

brave robin
faint agate
# rich adder would be easier to answer knowing the usecase of what the mechanic you're going ...

I have a sphere gameobject, the X and Z axis are locked, so I can only move the gameobject up and down on the Y. A script is attached to the gameobject that allows me to click and drag it up and down.

the z and x axis constraints are not in code but on the gameobject itself with a component called, " position constraint"

The problem is when I hold the gameobject and move far or closer, the gameobject moves a lot faster and not the speed of the player looking up and down. I understand the issue is the X and Z axis being locked is causing this, but I’m having a hard time finding a way to fix it without unlocking them.

I was told using planeraycast to make a plane at the ball's XZ and get the ray from the center of the camera. The problem now is the way I'm really moving the object. https://gdl.space/obepoxumel.cs .. Since im doing it from the object itself and not the player, this is where I get confused cause I can't find another way to move the ball like I am now or implement the planeraycast with what I have now.

strong wren
strong wren
faint agate
bright violet
#

I'm trying to build a splitscreen system from scratch. I'm using the joining feature of the player input system to get events. And on join i'm firing this:

void DoSplitScreen(PlayerInput playerID)
{
    Debug.Log("Initializing SplitScreen for player: "+ playerID.playerIndex);
    var camera = playerID.camera;
    
    float cameraXMin = playerID.playerIndex / 2;
    Debug.Log("CameraXMin equals: " + cameraXMin + "since playerID is: "+ playerID.playerIndex);
    float cameraYMin = 0;
    float cameraxMax = cameraXMin + 0.5f;
    Debug.Log("CameraXMax equals: " + cameraxMax + "since playerID is: " + playerID.playerIndex);
    float camerayMax = 1;
    camera.rect = new Rect
    {
        xMin = cameraXMin,
        yMin = cameraYMin,
        xMax = cameraxMax,
        yMax = camerayMax
    };

    Debug.Log("xMin: "+ camera.rect.xMin+ " xMax: "+ camera.rect.xMax+ " yMin: " + camera.rect.yMin+ " yMax: " + camera.rect.yMax);
}

it should work, yet the result is always the same. It looks like cameraxMax = cameraXMin + 0.5 is referencing the previous cameraXMin. Why?

rich adder
astral falcon
#

And what if there is no parent? I guess I need something like

UIRuntime.transform.position += UIRuntime.transform.TransformDirection(RuntimeHandler.Settings.uiHandOffset);
#

Yeah no, that code did not work either. Jesus, its such a simple task but I might just need some sleep 😄

faint agate
faint agate
pure pike
#

can someone help me fix this

bright violet
velvet sierra
#

Hello again everyone. So i managed to do some stuff by myself but i ran into an issue rn. Player should die when slime touchs it and indeed it dies no problem here but i didn't managed to add die animation. I mean there is a die animation but there is no time to play it, player just disappear. ho can i manage to do that. this is the code:
Player script:

  void OnCollisionEnter2D(Collision2D collision)
  {
      if (collision.gameObject.tag == "Enemy")
      {
          anim.SetBool("is_alive", false);
          gameObject.SetActive(false);
      }

  }```
rich adder
pure pike
polar acorn
eternal falconBOT
pure pike
rich adder
#

here we go again..

polar acorn
pure pike
rich adder
#

I told you this yesterday and you still haven't done it 🤔

polar acorn
# pure pike it is configured

Miscellaneous files - not configured
Unity classes such as MonoBehaviour uncolored - not configured
Line with error on it not underlined - not configured

bright violet
faint agate
polar acorn
#

Follow the guide

languid spire
rich adder
#

lets see difference between yours and mine @pure pike

pure pike
astral falcon
#

That looks quite promising, let me try and thanks 🙂

rich adder
#

if you want an example I can show you when I get back home soon

#

should be easy though look at docs for plane

#

the is ScreenToRay too you can use directly then put that on the plane for obect placement

bright violet
# pure pike ok

other than well fixing your editor, try and learn how to read the error messages: they give you the exact line where the mistake is so you can find it easily. as an example in your screenshot your error says "...playerMovement.cs(18,5) this is the file and the line that is causing the error

storm pine
# faint agate I have a sphere gameobject, the X and Z axis are locked, so I can only move the ...

I haven't test to much with that but It looks that for 3D you have to use Raycast and maybe a plane. I have see this video: https://www.youtube.com/watch?v=0jTPKz3ga4w
So maybe something like this can work: https://hatebin.com/jqeyurtfdf

🌍 Get my Complete Courses! ✅ https://unitycodemonkey.com/courses
👍 Learn to make awesome games step-by-step from start to finish.
🎮 Get my Steam Games https://unitycodemonkey.com/gamebundle

💬 One of the comments I get a lot is people asking why the code shown in the video isn't working, and usually the reason is because in the video I showcase ...

▶ Play video
rich adder
polar acorn
# pure pike ok

It is imperative that you do not simply fix this one error and go about your business. Configure your IDE so you stop making spelling mistakes in the first place

bright violet
polar acorn
pure pike
#

i sorta know how to read errors

faint agate
#

Should I give that watch or would it make this more confusing?

bright violet
rich adder
# bright violet cmon why

aside from the older ones using the annoying "use my library to use this method" and downloading from his site.
His other videos' now are watch this other video before you watch this video. which is quite annoying

faint agate
#

Ill watch wen I get home

polar acorn
# bright violet cmon why

I keep a counter of the times that people claim they have exactly the same code as the tutorial:

"I did it exactly like the tutorial so why does theirs work and mine doesn't" counter:
Number of times it wasn't exactly like the tutorial: 162
Number of times it was exactly like the tutorial: 5
Number of times the code literally did not exist: 1
2022-07-19 to 2024-5-21

Three of the five "times it was like the tutorial" and the one "time the code literally did not exist" were all Code Monkey

rich adder
#

but most dont claim to be writing "clean code"

#

which is what tickles my gooch

pure pike
astral falcon
#

Thanks again, this seems to be working. Jesus, now seeing it it totally makes sense. Thanks for saving me some hours of sleep 😄

rich adder
faint agate
#

Trolin, ill check out the vids ina bit tho. Appreciate the respond

faint agate
#

I have no idea what im doing but ill figure it out

bright violet
#

i just thought i was too dumb and messing stuff up

polar acorn
polar acorn
pure pike
rich adder
polar acorn
# pure pike manually

Show a screenshot of your VS Workloads section where the Unity workload is installed

bright violet
pure pike
polar acorn
pure pike
#

i changed it to the vs thing bc i was on open by extension but i swear i changed it to vs but ig not

rich adder
#

close vs, click Regen and open script again

pure pike
#

i got it now yippie

bright violet
storm pine
bright violet
# pure pike oh that stinks

iirc it should help if next time it happens you manually look for visual studio's executable and select that

rich adder
#

but obv you want a diff normal dir, prob maybe transform.forward

pure pike
#

theres nothing wrong but it still says theres an error

rich adder
#

great now read the error

#

; expected

#

you're missing ;

pure pike
#

im not tho

rich adder
#

ofc you are

#

look above the line it underlines

#

its "leaking"

rocky canyon
pure pike
rich adder
#

you forgot to close the valve

rocky canyon
#

LoL

pure pike
rich adder
#

; is like a period to a sentence

pure pike
#

i know

polar acorn
# pure pike im not tho

You are. Remember, a line only ends when it hits a semicolon. So, line 18 is actually private float jumpBufferCounter [SerializeField] private Rigidbody2D rb; which makes no sense

pure pike
#

those dang semicolons

rich adder
#

the importance of IDE config ✊

rocky canyon
#

braces too

#

braces are just as evil

rich adder
#

python users got so scared of them they took em out UnityChanLOL

rocky canyon
#

im soo glad i dont have to use python very often

pure pike
rich adder
rocky canyon
#

i made a video on how to configure it.. and because of that i had to unconfigure and reconfigure it multiple times..

#

some of those times required me to do a restart on the ide and my pc

#

glad thats over with 😄

rich adder
#

sometimes it says the assembly is incomplete or missing

rocky canyon
#

vscode was the worst

#

ngl

#

rider the easiest

rich adder
#

😢 VSCode before Unity plugin came out was the WORST

#

Visual Studio mac was the easiest

#

only used rider for a year was also pretty easy, nothing to setup

rocky canyon
rich adder
#

Microsoft really came in with the clutch

#

Unity would've took another 5 years

#

they figured out how to connect VSCode to the Visual Studio package 😛

rocky canyon
#

yup, my older projects were a mess

#

w/ both plugins.. one always complaining

rich adder
#

Frienemies

rocky canyon
#

ive upgraded most of my stuff to unity6

#

🤞

rich adder
#

yeah the new version dont even install the VSCode package anymore lol

#

that shite goneee

rocky canyon
#

ya, the new package manager doesn't even let it exist hehe

manic fjord
#

hey sry to bother, I got an issue understanding instances, i'm using a "Spawner" gameobject with a script linked to it and I would like to copy this object and maybe use it with a spawnRate not set to 5 but to 20 for exemple, therefore I would have one "Spawner" object with a spawnRate parameter of 5 and the other one cloned, with a spawnRate parameter of 20. I guess the thing to do is to use public variable to set them independently in each "instance"/"copy". But when i'm modifying the parameter of one object, the other one also gets affected, any ideas ?

ivory bobcat
manic fjord
#

was using the inspector through public variables

ivory bobcat
#

So you'll need to modify the scene object and not the prefab.

manic fjord
#

This is what i'm modifying

rich adder
#

are you cloning the scen object and not a prefab ?

manic fjord
#

yeah, i'm not supposed to ?

rich adder
#

not if want different values on new object

rocky canyon
#

nah, thats not a good way to do that..

#

make it a prefab and instantiate that instead

rich adder
#

Instantiate returns a clone of the object

manic fjord
#

for each layer i'd like a different value for exemple but all layers seem to be affected that's the problem

#

i'll try

ivory bobcat
rocky canyon
#
layer1 = Instantiate(prefab);
layer2 = Instantiate(prefab);

layer2.setting1 = 10f;
layer1.setting1 = 5f;``` etc super simple example
manic fjord
#

okay i see

digital wharf
#

Is there any way to detect collisions between a primitive collider and mesh collider using the ontriggerenter method? The level in my game uses a mesh collider and is an indoor level(I can't make the mesh collider convex), but that means the box collider that I am trying to detect collisions with won't detect collisions for the level.

rich adder
#

you could just use physics queries which works on any collider type

shy ruin
#

I'm getting this weird camera stuttering and I don't know why. I've had this before, someone please help! Here is a video of it, and some of my code ```// Called later and update.
void LateUpdate()
{
HandleCamera();
}

/// <summary>
/// Handles the camera, call in LateUpdate.
/// </summary>
void HandleCamera()
{
    // Get the mouse inputs and add them to current rotation vector.
    currentCameraRotation.x -= Input.GetAxis("Mouse Y") * CameraSensitivity * Time.deltaTime;
    currentCameraRotation.y += Input.GetAxis("Mouse X") * CameraSensitivity * Time.deltaTime;
    currentCameraRotation.x = Mathf.Clamp(currentCameraRotation.x, -85, 85);

    // Set the camera position to the camera position gameobject.
    Camera.transform.position = CameraPosition.transform.position;


    // Orientation object is set to the correct rotation, then the players rotation is set to it to prevent player model stuttering, but when setting the camera rotation it doesn't work.
    Camera.transform.localRotation = Quaternion.Euler(currentCameraRotation.x, 0, 0);
    Orientation.transform.rotation = Quaternion.Euler(0, currentCameraRotation.y, 0);
    transform.rotation = Orientation.transform.rotation;
}```
ivory bobcat
#

If you're moving through physics, consider updating the camera in the physics step to have it be accurate.

teal viper
#

Typically you want to move the camera as often as rendering happens, so update or late update is correct. Now, jittering usually happens when the camera or objects in the scene are not moved in sync with it's update.

#

Since physical objects are moved in fixed update by default, this is often the cause.
That's why there's interpolation option on the rbs. What it does is actually moves the rb in between it's fixed update positions during the regular update.

rich adder
#

mouse is already framerate independent

shy ruin
#

I tried that before though

#

Just changed it and I'm still getting the problem.

rich adder
#

I'm saying it as a general thing you should not be doing

#

idk what ur issue is I havent looked yet

#

is your character a character controller or rigidbody ?

shy ruin
#

Rigidbody, interpolation on, using AddForce inside fixedUpdate from Input.GetAxisRaw multiplied by delta time

rich adder
#

makes sense why its jittering

#

your mouselook is def happening faster than rigidbody can update

shy ruin
#

So... what should I change?

rich adder
#

I think mostly the rigidbody rotation

shy ruin
#

So you're saying I should rotate the player inside Update

rich adder
#

if its an option you should use Character Controler since thats moving in Update

#

shouldbe less of issue jittering

shy ruin
#

Wait,

#

I'm rotating my player in LateUpdate, will that cause the problem?

rich adder
#

it should be okay, but You tried Update already?

shy ruin
#

One second

#

Still has the problem in Update

rich adder
#

its a tricky problem with rigidbody

shy ruin
#

I would use character controller but this game is physics based

#

This is the worst problem 😦

rich adder
#

understandable, its for sure the camera though

shy ruin
#

The weird thing is I copied this code from my old working script...

rich adder
#

did you turn on the interpolations and everything?

shy ruin
#

Yeah, what is everything?

rich adder
#

maybe playing around with the Physics settings

shy ruin
#

In the Project Tab?

rich adder
#

yeah project settings

shy ruin
rich adder
#

maybe something in there

shy ruin
#

Here is my old code that works for a different game

#

Wait... I did lerp in that one.

#

Is that maybe it?

rich adder
#

also , s this rigidbody also ?

shy ruin
#

Yes

rich adder
#

oh ok

#

also note no TIme.deltaTime here either 😛

shy ruin
#

Well in that one it was ok

#

It was lerping

#

Let me add some lerping rq

rich adder
#

the lerp is somewhat inaccurate

#

it will work differently across framerates

shy ruin
#

wdym?

rich adder
shy ruin
#

Lerping didnt work.

#

It's even worse with a parent transform

rich adder
#

maybe try rotating player in FixedUpdate with rb.MoveRotation ?

#

I haven't worked on physics based controllers too much so not sure what fix is

#

i know its definitely the mismatch in rigidbody move/rotating in physics loop while rotating in update

shy ruin
#

So, not the camera?

rich adder
#

yeah its the camera

#

fighting rb

rocky canyon
#

cuz thats the underlying issue

rich adder
#

because the camera is moving in a different loop ?

shy ruin
#

Oh my

#

It's even worse now when I reverted the code??!??!?!

#

It seems the rigidbody moving, then rotating the child camera is conflicting with each other

#

Im rotating the rigidbody in update

rich adder
#

also I think camera being parented to a rigidbody doesn't help

#

parenting and dynamic rigidbodies don't work well

#

transform following a rigidbody what i mean

shy ruin
#

What if I damp the position of the camera so it smoothly follows the view

#

Even smoothing isn't working...

#

Once I make it higher at least

hasty sleet
#

Can you exclude the camera from viewing the player?

shy ruin
#

What do you mean by that

rich adder
#

now its laggy instead of studdering

shy ruin
#

I've figured out the problem

#

It's the rotation of the rigidbody

#

It just doesn't like rotating with the camera

rich adder
#

yes rigidbody is working on FixedUpdate

shy ruin
#

No but

rich adder
#

camera isnt

shy ruin
#

I'm not rotating it in fixed update

#

I rotate them both

#

at the same time

#

in update

rich adder
#

yes but the rigidbody will still wait till the next physicsupdate to rotate

#

thats why its outta sync

shy ruin
#

I'm doing transform.rotation though

rich adder
#

and the physics rigidbody has to catch up to that

#

imagine the physics objects being a seperate scene

shy ruin
#

I got to go for now, but I really want to fix this 😦

rich adder
#

also haveyou tried this in the build ?

#

you might get different result than editor

shy ruin
#

Ok one second

rich adder
#

editor has more overhead to run could be messing with physics sync

#

found this
untested but read last answer from unity employee

solemn fractal
#

Hello guys, one question. If I would like to make a game like tap ninja, it is easier in programming and more logical do do the screen move and not the character or its better to move the character? It seems like games like that the scenario moves but not the heroe itself.. anyone can enlighten me ? thank you

shy ruin
#

Happens worse in build, I'll check out cinemachine later I used that last time and I think it will fix it

#

Actaully yeah

#

I think thats it

rich adder
#

yes cause you can pick to update rate of cinemachine brain

rich adder
#

ideally you want to move objects towards player

solemn fractal
rich adder
#

if you hit a certain amount of position with big float you will get weird issues (float point errors big numbers)

solemn fractal
#

ok thank you very much

rich adder
#

usually games get around this problem by respawning player at 000 and then moving the world with it

#

but for inifinte runner easier to just let obstacles move to you

#

and terrain for you

solemn fractal
#

ok, thank you i will do like that.

rocky canyon
#

like dis 😄

misty coral
#

How does sphereCast with the distance of the cast set to 0(So the sphere has no ray length presumably) differ from CheckSphere

wintry quarry
misty coral
#

huh

wintry quarry
#

since spherecast doesn't detect colliders it starts out overlapping

hybrid tapir
#

why isnt putting [System.Serializable] over my class definition and/or putting [SerializeField] over the variable for the class putting my values in the inspector?

rich adder
#

do you have like properties or something

wintry quarry
#

Show the code if you want to know exactly what's wrong

#

(or maybe your code just isn't compiling yet, because you have a compile error)

hybrid tapir
rich adder
#

RawImage?

#

also those are private

wintry quarry
#

but uyeah you put [SerializeField] only on an enum declaration, which makes no sense

#

All the actual fields in your class are private

hybrid tapir
wintry quarry
#

it's not a field

#

if you had a field like:
posFromText exampleField; you could serialize THAT

#

such as the one you have on line 37

hybrid tapir
#

yea, thats the only thing serializing

wintry quarry
#

Why are you defining the same enum in two different places though

rich adder
#

you have two definitions you don't need two

wintry quarry
#

the rules are simple

#

fields only

#

the thing on line 19 is not a field

hybrid tapir
#

yea i added the field

#

why wont my other fields serialize tho

wintry quarry
#

because they're private

#

as already mentioned

rich adder
#

u need above each

wintry quarry
#

and you didn't put [SerializeField] on them either

#

Look at the first rule:

Is public, or has a SerializeField attribute

hybrid tapir
#

ok so i changed it back to what i had first and NOW everything is serializing (what i had first wasnt in the ss)

rich adder
#

do you plan on using them because you would need a property/method or a public field to use them elsewhere

#

you wouldn't be able to access the private fields in a script from instance

hybrid tapir
#

i put the words public back in the beginning of my class fields and they finally seiralized

#

odd that it didnt do that the first time i made them public

#

i thought something changed lol

wintry quarry
#

or had a compile error etc

hybrid tapir
#

ah ok

wintry quarry
#

possibly were missing [Serializable] on the class for example

hybrid tapir
#

oh

#

how do i use foreach with a list

wintry quarry
#

Isn't that the canonical example for foreach?

hybrid tapir
#

ooop i forgot they need the temp var name

wintry quarry
#

Usually a bootstrap scene is a good idea anyway though

#

A scene that you load just to set things up

#

Always loaded as the first scene

#

even before a main menu etc

true birch
#

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

public class TestingPathfinding : MonoBehaviour
{
void Start()
{
print(Physics.Raycast(transform.position, new Vector3(5, 0, 0), 5));
Debug.DrawLine(transform.position, new Vector3(5, 0, 0), Color.white, Mathf.Infinity);
}
}

Why does the raycast return false here? The following script is attached to the smaller box and the raycast comes from it and arrives at the point with nothing but black around it at the end of the drawn line.

wintry quarry
#

Raycast and DrawRay take one position and one direction
Linecast and DrawLine take two positions

#

you're confusing position and direction vectors

#

Also for sharing code please format it !code

eternal falconBOT
true birch
#

thank you

rocky canyon
#

i imagine it refers to "pick yourself up from your bootstraps"

#

lol, its just im always trying to think of clever/ witty names for things

#

and that ones is pretty dang cool LOL

summer stump
#

Basically the idea behind that phrase.

rocky canyon
#

im weird i guess

summer stump
#

(Even though that phrase originates from the idea of lifting oneself by ones bootstraps being impossible)

rich adder
rocky canyon
#

see that stuff is super interesting to me 😄

rich adder
#

#computersnappleacts

rocky canyon
rich adder
#

but he didn't expect that shit

rocky canyon
#

coool lol

#

the bug one.. says Thomas Edison coined it..

#

but the other source i read was about the Moth and Grace Hopper a admiral in the US Navy

#

Edison.. always trying to take credit for things 🙄

rich adder
#

yeah half this stuff is nonesense

rocky canyon
#

it did come from reddit

#

im definitely gonna rename my Master scene to Bootstrapper 😄

#

I've thought about using Bootloader.. but i didn't think it fit well
i'll keep the Bootloader for my embedding stuff

magic panther
summer stump
#

Can you show the ball controller script?

magic panther
#

sh my bad

#

updated

summer stump
#

Also consider setting interpolate to interpolate and collision detection to continuous

magic panther
#

ok, one sec

summer stump
magic panther
#

lemme test

#

bro, how do you know that

#

works perfectly now, thank you

summer stump
#

Eh, lots of practice, and making the same mistakes haha.
Glad it worked!

solemn fractal
#

hey guys, when I use Json system to save my game. where can I find that save inside my computer?

summer stump
#

Ah, persistentDataPath depends on the os

solemn fractal
#

windows

summer stump
#

The docs tell you exactly where it goes

solemn fractal
#

thank yuou

#

wil check it out

keen dew
#

Debug.Log(Application.persistentDataPath); <-- there

unkempt carbon
#

Hi guys, I'm trying to write a script for saving and loading a deck of cards and so far I have this logic:
Functions:

  • when button is clicked, unity saves string (i).
  • when loading said string (i), profile (i) is loaded.
  • when loading said string (i), load card preset (i).

is this correct?

hasty sleet
queen adder
#

What's the easiest way to render geometric primitives in both scene and game view? Just trying to do some testing for a geometric algebra library I'm working on.

queen adder
#
Debug.Log(GameObject.FindGameObjectsWithTag("BossHealthText").GetComponent<TextMeshProUGUI>());

Why is it:

NullReferenceException: Object reference not set to an instance of an object
EnemyBoss.Update () (at Assets/Scripts/EnemyBoss.cs:25)
#

yes I have the tag assigned to the GUI text mesh

queen adder
eternal needle
languid spire
low sandal
#

Can anyone make me an Ultrakill type movement for free? (Please dont ban me or wtv I read through the rules and couldnt find anything about if commisions were bannable)

eternal falconBOT
low sandal
queen adder
# languid spire no it is not. FindGameObjectsWithTag returns an array. You cannot call GetCompon...

Yes I figured that out, sorry didnt update the code.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class EnemyBoss : MonoBehaviour
{
    public float speed;
    public float health;

    public GameObject enemyMissile;

    // Start is called before the first frame update
    void Start()
    {
        transform.position = new Vector3(0.0f, 4.0f, 0.0f);
    }

    // Update is called once per frame
    void Update()
    {
        // spawn at top of screen and moves left and right continuosly (facing downwards) always facing towards player ship (roatating towards player ship)

        TextMeshProUGUI bossHealthDisplay = GameObject.FindGameObjectsWithTag("BossHealthText")[0].GetComponent<TextMeshProUGUI>();
        Slider bossHealthSlider = GameObject.FindGameObjectsWithTag("BossHealthSlider")[0].GetComponent<Slider>();

        GameObject player = GameObject.FindGameObjectsWithTag("Player")[0];
        // move left and right
        if (transform.position.x > 10.0f)
        {
            speed = speed * -1.0f;
        }
        if (transform.position.x < -10.0f)
        {
            speed = speed * -1.0f;
            // asd asdadsa
        }

        transform.position += new Vector3(speed, 0.0f, 0.0f);


        // rotate towards player
        Vector3 direction = player.transform.position - transform.position;
        float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
        Quaternion rotation = Quaternion.AngleAxis(angle - 90, Vector3.forward);
        transform.rotation = Quaternion.Slerp(transform.rotation, rotation, 0.1f);

        // shoot missile
        if (Random.Range(0, 300) < 1)
        {

            Quaternion missileRotation = transform.rotation;
            GameObject missile = Instantiate(enemyMissile, transform.position + new Vector3(0.0f, 0.6f, 0.0f), missileRotation);
            missile.GetComponent<EnemyMissile>().speed = 0.02f;

        }
        bossHealthDisplay.gameObject.SetActive(true);
        bossHealthSlider.value = health / 2;
        bossHealthSlider.gameObject.SetActive(true);
         //asd 
    }

}

So I am trying to implement something where the Text Mesh and slider is only created when Enemy Boss object is created, however when i keep these as inactive, it says array is out of index (hence they are not found), is there any workaround this?

languid spire
#

Problem you have if No objects are found an index of 0 will be out of range

#

eg

Slider bossHealthSlider;
GameObject[] gos = GameObject.FindGameObjectsWithTag("BossHealthSlider");
if (gos.Length > 0) bossHealthSlider = gos[0].GetComponent<Slider>();
#

Also FindGameObjectsWithTag does not have an override to include inactive objects

queen adder
languid spire
#

your other option, which is more efficient, get the relevant gameobjects to inject themselves into a List when they instantiate and remove from the List when they Destroy. That way, if the List.Count > 0 then one of the objects exists

south sand
#

who invented vector flow field pathfinding?

timber tide
#

me

raven ferry
#

hello i made a script that changes a object color when clicked, but how do i change the way a new color value makes a object look? the defuelt is that it adds the color ontop of the original color and blends into it. how would i make the color change solid or ajust things like opacity and blend mode

wintry quarry
raven ferry
#

a object containing a sprite rendere

#

the script changes the color value of the sprite but the color change itself blends into the original color, and doesnt replace it

stoic glen
#

Why doesn't the Start function get called after returning to a scene that was loaded before. How can I fix this

surreal mango
#

Hello, does object instantiate - clear events from the copy?

molten dock
#

in 3d games are you supposed to rotate the camera with local or world position

#

like transfom.rotation and transform.localRotation

burnt vapor
#

It depends (tm)

wintry quarry
molten dock
#

first person game

brave compass
wintry quarry
languid spire
molten dock
#

i am transforming the cameras position to the player personally

languid spire
#

if the camera has no parent then local and world are the same

molten dock
#

oh alright

#

okay ty

molten dock
mortal ginkgo
#

hi. can someone show me like basic code to make a 2d object move left and right? i'm trying to learn unity but when i follow youtube videos to remake something i get an error

#

here's the code and the error

cosmic dagger
cosmic dagger
#

oh, this is pretty straight-forward. it says the Rigidbody2D does not have a definition or member called Velocity. check the docs for Rigidbody2D and find/use the correct definition/member . . .

mortal ginkgo
#

ok thanks

molten dock
#

ill let u figure it out but its a capital letter issue

#

gotta use the right casing in these things

mortal ginkgo
cosmic dagger
mortal ginkgo
#

ok

cosmic dagger
molten dock
#

do you have a bot which puts three dots at the end of each sentence

#

still gotta figure something out

mortal ginkgo
#

i just need examples before i start making something my own

mortal ginkgo
#

but thanks

cosmic dagger
queen adder
#

How would you achieve constant velocity for a Rigidbody2D? I thought of a backend variable that overrides the current velocity. I dont know if it's good to set velocity in Update() frequently. Movement seems okay in 60 FPS but not in 30-40 fps if i do it in Update()

// Acts like speed. It sends negative version of self to overrideHorizontalvelocity on negative input (left-right)
public float constantVelocity = 5f;

// Overrides velocity in FixedUpdate
private float overrideHorizontalVelocity;
molten dock
#

if you want to do it in script do it in fixedUpdate

#

void FixedUpdate()
{
rb.velocity = Vector2.up * speed;
}

queen adder
cosmic dagger
molten dock
#

would it fr keep the momentum that is useful for me lol

queen adder
molten dock
#

tell me if its still smooth despite being out of fixed update

queen adder
#

Ah no velocity does not stay constant. Maybe he confused with 3D?

molten dock
#

may be able to make it constant with the correct rigibody settings

queen adder
#

Yeah so i understand that i must edit velocity inside FixedUpdate() now. Thank you

molten dock
#

do you know that physics should usually be in fixedupdate

queen adder
#

Actually wait friction had worked lmao you were right

queen adder
languid spire
molten dock
#

fixedupdate updates at the same frequency as physics is the reason

burnt vapor
eternal falconBOT
prime kelp
#

I am new to unity.

slender nymph
eternal falconBOT
#

:teacher: Unity Learn ↗

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

late burrow
#

wait am i missing something

#

raw bytes actually weight more than base64

#

perhaps unicode is bad format?

slender nymph
#

if only there were some other way to transfer that data instead of encoding it as a string

late burrow
#

if only people stopped complaining about my solutions

slender nymph
#

if you'd stop trying to turn your audio data into a string just to transfer it from your server to a client, then you might actually get somewhere

late burrow
#

i could download it as video but then all the other data would be put somewhere in that video as string regardless

slender nymph
#

why would you download it is a video? that makes no sense

late burrow
#

because 1 link and only 1 link

slender nymph
#

okay first of all, this is your own restriction you've placed on this problem. second, as i have already told you, if you store the path to the audio in your string that you are sending already you can use that to then download the audio.

#

so you just have your "one link" that your players will enter or whatever, then your "one link" will contain the level data and another link for the audio. this will also allow you to download level data without immediately downloading the audio data allowing you to potentially set up a preview or whatever because it will be much faster since i'm sure the level data is much smaller than the audio

late burrow
#

i could make like 10 sub sites just for sake of downloading audio

#

if i really were to take like 300mb to download single mp3