#💻┃code-beginner

1 messages · Page 447 of 1

languid spire
#

public string ImageDataFolder
{
get
{
if (IDataFolder < 0 || IDataFolder >= ImageDataFolders.Length)
{
Debug.LogError($"Invalid IDataFolder index: {IDataFolder}. ImageDataFolders length: {ImageDataFolders.Length}");
throw new System.Exception("Data Folders not initialised, or data folder index out of range");
}

        return ImageDataFolders[IDataFolder];
    }
}
#

completely unnecessary

reef patio
#

does anyone know how to fix a nav mesh error?

late burrow
#

static gameobjects and bake navmesh

languid spire
reef patio
#

Actually I fixed it...

#

Thanks though.

errant solar
#

guys help please

#

@sick cloud

languid spire
#

this code makes absolutely no sense. What are you trying to do?

errant solar
#

the code is too long and i had to duplicate it alot so i need to make this
Input Player = new Input(Input.GetKey(KeyCode.W) | Input.GetKey(KeyCode.S) || (Input.GetKey(KeyCode.D) | Input.GetKey(KeyCode.A)))
do you have solution?

languid spire
#

what makes you think that that is even valid code?

errant solar
languid spire
#

I'm not going to tell you.
look at it
Input is a static class so cannot be new'ed
GetKey returns a bool so why would that be passed into a class constructor?
you are mixing | and || without seperation. What do you expect that to do?

errant solar
languid spire
errant solar
errant solar
languid spire
#

I'm not going to give you code, however I am trying to help you figure it out yourself so you actually learn something

languid spire
#

nothing wrong with this
althought why only one | after the first part?

errant solar
languid spire
#

but, yes, you can turn that into a bool but not an Input

round mirage
#

hello i want destroy a gameObject when he touch something but he only work when i dont call my function . someone can help me ?

void OnCollisionEnter(Collision col)
    {
        Debug.Log("Collision with an object");
        if (wasDrinked)
        {
            Debug.Log("if wasDrinked");
            playPop.Play_Audio_GlassBroke(); // function in another script attach to the player 
            Destroy(gameObject);
        }
    }
round mirage
#

yes

languid spire
#

care to share them or should I just guess NRE's?

round mirage
#

OH

#

ok

#

i found my mistake

#

thank you

spark glacier
#

Hello I'm trying to make my player jump when space is pressed but whenever I try to do so the gravity always resets the player to the ground. I tried making a bool for isJumping and using that but it still doesn't work. Can anyone help?

#

Here is my code

languid spire
#

Look at the logic of your code
Frame 1
keyDown is true isGrounded is true so jump
Frame 2
keydown is false isjumping = false
isgrounded is false isjumping is false so apply gravity

Your jump logic is never given the time to actually happen

spark glacier
#

So how do I give it time?

languid spire
#

use a timer before setting isJumping to false

spark glacier
#

Okay thanks Ill try that

long jacinth
#

guys how do i access this boolen from another script

#

if(MobileCheckerey.GetComponent<MobileChecker>().MobileToggle(isMobile) == true)

#

this is the if statement im using

quasi girder
#

Pressing T update the variable ONLY for the one who pressed it

half egret
# long jacinth guys how do i access this boolen from another script

That's a function parameter, you can't access it from another script. It's relegated to the scope of that function and that function only.
You need a bool that's in scope of the class, e.g. "public bool isMobile" that you update when toggling mobile. You can retrieve that

languid spire
quasi girder
long jacinth
half egret
#

this.isMobile = isMobile might work for your use-case here

#

But you need to define the isMobile class variable

#

There is also redundant code there

#

You can just do MobileCanvas.gameObject.SetActive(isMobile)

long jacinth
#

oh

#

so i make a function inside the script with the bool? and then i make the toggle do that script?

half egret
#

It doesn't need to be a function, it's just a class variable

#

And in the function you have, you just toggle said variable.

spark glacier
#

I'm having an issue with jumping again. When I press jump the player just kinda teleports up in to the air instead of uhh jumping. I don't really know what to do so if anyone can help out it would be great.

long jacinth
wintry quarry
#

A jump is not a single movement

#

You need to simulate vertical velocity over time

#

A jump is when you suddenly gain a bunch of positive vertical velocity, followed by many frames of the natural parabolic arc of gravity after that

#

Your code is simply doing one movement, as you described

spark glacier
#

Okay how do I make it a fluid movement then

wintry quarry
#

I said how

spark glacier
#

I know how to do it with a rigidbody but with a charactercontroller it's kinda difficult

#

Soo i should apply a smaller force each frame?

#

instead of one big one in one frame?

wintry quarry
#

How did you get that idea from what I wrote

#

You're missing even the baseline system that would enable anything like a "force" to be applied as far as I can tell from that code snippet

wintry quarry
#

You need to keep track of your velocity and to do that you need a variable

#

Also you should only ever call Move one time per frame

spark glacier
#

So I should create a velocity variable and use that?

#

Or how do I simulate a vertical movement?

#

Im really new sorry if I sound kinda dumb

wintry quarry
#

If you're that clueless maybe you should try a tutorial or two and see how they do things

#

To get an idea

spark glacier
#

I did but most of them use a rigidbody and I don't really wan't to use a rb. I already know the basics like variables and operators and stuff like that I just don't know how to do stuff like this.

#

But i guess i'll watch some more

wintry quarry
spark glacier
#

Okay thanks

queen adder
#

I think i messed up. In my current project (only) visual studio is giving me intellisense and autocompletion for commented code lol

vast vessel
#

will this return the y axis of a vector3?
return v3[1];

deft grail
vast vessel
#

i know i can do that, i want to know what this will return

deft grail
sick cloud
deep yew
sick cloud
modest dust
#

Pass the reference to Player Goal when you Instantiate the prefab

deep yew
#

ty

sick cloud
modest dust
# deep yew I don't understand, but I'll try to figure it out

Your Enemy is a prefab (a template to be copied and spawned in any scene) and your PlayerGoal is a GameObject present in the scene. You cannot reference anything from a scene in a prefab. What if you suddenly decided to spawn it in another scene that doesn't have that object?

deep yew
#

Ah, I get it.

modest dust
#

In your EnemyX script add a new method with a param to pass the Player Goal reference with

#

Instantiate returns the reference to the newly spawned instance of the prefab, so call the method on it

deep yew
#

Alright, now I know what to do.

#

Thanks man.

fervent abyss
#

hi, how can i check if a new list element was created in editor?

willow scroll
fervent abyss
willow scroll
fervent abyss
willow scroll
#

Yes, so which variant are you talking about?

fervent abyss
#

what do you mean by variant

#

what variant

#

😭

willow scroll
#

I have mentioned two options for you to chose from

fervent abyss
#

OnValidate

willow scroll
#

You have to track the previous List and see whether it's not the same as the new one

fervent abyss
#

mk

willow scroll
# verbal dome Yes

I have never heard of this before, but it seems that Vector3 has an indexer

public float this[int index] => index switch
{
    0 => x,
    1 => y,
    2 => z,
    _ => throw new IndexOutOfRangeException("Invalid Vector3 index!"),
};
#

Interesting, but I'm not sure why they haven't checked it themselves

vestal nest
#

Can anyone hel: XR Interaction Toolkit - How to prevent dropping an object

mint remnant
#

he posted there lol

wintry quarry
#

shouldn't crosspost

deft grail
north iron
#

How should I store prefab for my entity, when I want to spawn it? Should it be in script of that entity, or should I store copy of that on the scene and use it to spawn

cosmic dagger
wintry quarry
summer stump
north iron
#
        Name = "House";
        model = GameObject.CreatePrimitive(PrimitiveType.Cube);
        model.transform.localScale = new Vector3(Random.Range(3f, 7f), 5, Random.Range(3f, 5f));
        model.layer = LayerMask.NameToLayer("NonWalkable");
        model.AddComponent<MeshCollider>();
        model.transform.SetParent(transform, false);

so something like this is fine?

wintry quarry
#

just make a prefab

#

you're just ignoring what we said

summer stump
wintry quarry
wintry quarry
north iron
sick cloud
#

Hey guys the code here only works in the editor, so if I want to make an .exe of my program it wouldn't work anymore. Are there any alternatives?

string folderPath = UnityEditor.EditorUtility.OpenFolderPanel("Select DICOM Folder", "", "");
languid spire
#

there are assets on the asset store for this

sick cloud
#

wait really?

languid spire
#

no, I'm lying. Yes, really, why did you not already check?

sick cloud
#

damn dude

#

sorry for agitating you

teal viper
#

Just to clarify what you're looking for is a "file picker"

sick cloud
#

thx

verbal dome
#

For example cs var center = new Vector3(); center[cap.direction] = 0.5f; cap.center = center;

umbral rock
#

so i have a code that lets a player move to the right in a 2d game if(GetKey(Keycode.D){ (rb.velocity = new vector2(speed, rb.velocity.y) but that only makes the character move to the right, how would i move him to the left also?

cosmic dagger
umbral rock
#

no that makes me move to the right

wintry quarry
raw token
#

If positive speed moves you to the right...

umbral rock
#

i tried, -speed

wintry quarry
#

that will work

umbral rock
#

didnt work lol

wintry quarry
#

it will

#

you did something wrong

#

show what you tried.

raw token
eternal falconBOT
umbral rock
#

my laptop just shut down bcs of the battery lol, i'll definitly send it later this day, i will look at it again too maybe that i missed something

cosmic dagger
#

Convenient . . .

queen adder
#

!code

eternal falconBOT
summer stump
sacred horizon
#

i get this when i export

languid spire
sacred horizon
#

yes

languid spire
#

so say that. build to what target?

sacred horizon
#

trying to make it a apk

languid spire
summer stump
#

In the spot where interactable == null, set isInteracting to false.
Also, in the same spot, and the else where you turn the isInteracting bool to false, you likely need some StopInteracting method

willow scroll
#

The InteractWithClearCounter method is called in neither of these scripts

wintry quarry
#

whya re you using a static variable

#

time to learn - this isn't going to work well with a static variable

#

you already have cross script communication here

#

via the raycast

#

there's no need for static anything

summer stump
wintry quarry
#

the counters should track their own state

#

when you interact, you can toggle the state

willow scroll
#

It's time to use them

wintry quarry
#

how many states are there

#

sounds like a bool to me

#

no?

#

you don't need to reference anything what do you mean

#

when Interact is called, you toggle the bool

#

and you toggle the visible thing

#

again this state needs to go on the COUNTER

#

not on the player

#

it makes no sense on the player

summer stump
#

I just gave you a link of a ton of different ways to reference btw. Static should not be your first, or third choice. It should be the back of the line, only in front of Find

willow scroll
#

Note that you should never make a variable static if it is different for every specific instance of your structure

#

For example, in your class Human, you should make neither name nor age static, as they, usually, differ for every instance of it

#

There are many variants for you, the ones I would take into a consideration are:

    1. Manage things directly in your Player script
    1. If there is a good reason to manage it in another class, it may invoke an event for your Player to catch
#

Honestly, there are really few reasons to make the logic associated with the Player in another classes. One of them would be if that's a Singleton class like a GameManager

#

If you don't want to have too much code in your single Player class. Ignore this desire

#

Make it partial and create several files, for example

stark gyro
willow scroll
#

Usually, I would consider working with Vector2Int

#

Not sure why Unity has implemented neither implicit conventions nor overloads for Tilemap

stark gyro
willow scroll
#

Now send the tile's "before n after"

stark gyro
#

I'll record 1 sec

willow scroll
#

No need, you can also take a screenshot

stark gyro
#

Nothing changes

willow scroll
#

So, where is the changed tile?

drowsy flare
#

I have a script which I use from Unity, which contains:
public GameObject ShowPicture;

If I didn't link it to a game object in the gui, I get a UnassingedReferenceException.
Is there any way to check if it's assigned without throwing an error?

I tried the following but they throw the same exception:
if (ShowPicture is object)
if (ShowPicture is null)

#

I kinda wanna know if the variable is initiated? I think? 😄

stark gyro
#

Like I said, even log says it's changed but it never actually changes

willow scroll
short hazel
#

v != null to check if a variable has a value.

willow scroll
#

Instead, you should simply compare your GameObject to null:

if (ShowPicture == null) { }
if (ShowPicture.Equals(null)) { }

Unity also has an implicit bool operator, so you can remove == null and add a ! to revert the statement

public static implicit operator bool(Object exists)
{
    return !CompareBaseObjects(exists, null);
}
if (!ShowPicture) { }
#

Note that UnityEngine.Object's Equals method is safe and does check for this being null before comparing

willow scroll
#

And prefer the last option, because it's the most readable, as for me

willow scroll
#

You already use is, so it seems like you should also know about == and Equals

drowsy flare
#

I thought is was exactly the same as ==

stark gyro
#

wait
is != == ?

drowsy flare
#

That's what just blew my mind, it works well with == and !=

willow scroll
drowsy flare
#

Damn, thanks a lot

summer stump
#

Unity overloaded the == operator

Ah, i see you are discussing something different

willow scroll
#

is returns true if both objects have the same type, for example, GameObject and GameObject

#

Alright, no

#

Ignore this, because I don't know what I'm talking about.
You should not use null with Unity objects

slender nymph
#

the is operator can also do a null check, but it is a pure null check and does not handle destroyed objects

stark gyro
#

I think tilemap manipulating could've been so much more easier

drowsy flare
stark gyro
#

It's been hours and I'm still trying to make a block turn yellow when it's the closest tile.

slender nymph
drowsy flare
#

I started writing a game the other day, and I'm sooo hooked right now 🙂

drowsy flare
#

Thanks, I need it so much

willow scroll
willow scroll
stark gyro
#

The problem is, I'm not understanding how do you want me to change things

willow scroll
summer stump
#

Oh ok then

stark gyro
willow scroll
drowsy flare
willow scroll
#

Also change the color manually to the required one and send a screenshot

stark gyro
#

Color option is greyed out so I can't

willow scroll
#

Select the Tile

stark gyro
#

This changes colors as a whole

willow scroll
#

Not the tilemap

stark gyro
#

Oh in the assets folder

willow scroll
#

Yes, you even have a folder called "Tiles" there

stark gyro
drowsy flare
#

Oh, another thing I found kind of confusing. Do my 2D box colliders need a 2D rigidbody to detect collisions? Because it seems like I don't detect collissions when I remove the rigidbody, and I don't want it to have one. Or have I just been a noob with my scripts?

stark gyro
#

Yeah you need rigidbody

willow scroll
# stark gyro

In the Start method, try changing the color of a random tile

drowsy flare
willow scroll
#

Note that a suitable Rigidbody should be used. 2D with 2D, 3D with 3D

drowsy flare
stark gyro
#

Looks good?

drowsy flare
slender nymph
#

are you trying to drag a scene-object into a prefab?

slender nymph
#

and giving the asset a reference to the player prefab will not be useful

#

again, assets like prefabs cannot reference in-scene objects

raw token
# stark gyro Looks good?

I know virtually nothing about working with tilemaps, but looking around a bit out of curiosity, I'm finding a bunch of stuff about tiles seemingly being configured with TileFlags.LockColor by default which may prevent the behavior.

drowsy flare
#

I also wonder if I'm supposed to have an AudioSource component attached to all GameObjects playing sounds, or should I reference a single AudioSource?
Right now the only solution to play sounds that I found was to add an AudioSource on all my sound making little assets in the scene 🙂
Edit: Found a solution to use a "general" audiosource. I still kind of wonder about best practise ...

willow scroll
stark gyro
willow scroll
#

Black is not affected by color change

stark gyro
#

I rewinded it to original, white

willow scroll
willow scroll
drowsy flare
stark gyro
willow scroll
# stark gyro I didn't get this

The black color is not affected when changing the color of the entire image. It always stays black, (255, 255, 255) or (1, 1, 1)

stark gyro
#

This one(0,-4,0) was supposed to change to yellow because of Start()

willow scroll
stark gyro
#

No...

#
Debug.Log(tilemap.GetColor(new Vector3Int(0, -4, 0)));
#

I'm gonna add this now

willow scroll
stark gyro
#

I think it should've been 1,1,0,1

sleek marten
#

I'm at my wits end here. When I'm in Simulator mode my player moves to a click point AND interacts with the UI despite using
EventSystem.current.IsPointerOverGameObject()
But it works fine in Game mode. I've looked at this problem up and down and I don't get it. Can someone please tell me what I'm not getting?

ripe arch
#

is there a reason why i cant initialize the IkanScriptableObject here? even though the scriptableobject exist?

abstract pelican
#

hi guys, how to track the placement of items like in the game Rust?

willow scroll
stark gyro
#

Saw this on reddit :
Make sure that your tile doesn’t have the “lock color” setting on it in your project. Once placed any call to SetColor will be ignored at runtime.

willow scroll
sleek marten
#

when I'm in Simulator it does both at the same time. If I keep clicking on a UI after this it will ONLY interact with the UI. When I click on world space it still assumes I'm clicking on the UI for that one instance. If I click on world space a second time I can move again.

ripe arch
slender nymph
#

show the class declaration for IkanScriptableObject

stark gyro
#

It works...

#

Thank you @willow scroll and @raw token

raw token
#

Nice!! 🎉

ripe arch
slender nymph
#

that is not a class named IkanScriptableObject

ripe arch
#

sorry

willow scroll
sleek marten
#

It was working fine just a few days ago

#

I thought it might have had something to do with Canvas work I started but even after starting fresh it's still broken

willow scroll
#

Well, it does seem like a problem with a Simulator

#

I have never worked with them, so I cannot assist you further here, I'm sorry

sleek marten
#

this might make me explode because I can't do anything else until it's resolved

#

I'll try the forums next I guess

median halo
#

!vscode

eternal falconBOT
#
Visual Studio Code guide

If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:

https://on.unity.com/vscode

dire estuary
#

Hi, I'm developing a small game to practice Unity, but recently I've encountered an issue that I can't understand the origin of. As soon as my character moves, numerous stutters (FPS drops and the camera seems to shake) occur. This seems to happen randomly after several seconds, minutes, or right at the start of the game. I thought it was due to the way the camera and the player's Rigidbody interacted, but from what I can see, my scripts are correct (the camera is a child of the player, the player's Rigidbody is handled in FixedUpdate, and the camera in LateUpdate). Does anyone have any idea what could be causing this?

rocky canyon
#

craazy

#

click one of the peaks.. and see what code is takin the longest (expanding the hierachy of the debugger)

raw token
#

stonks stonks 📈

rocky canyon
dire estuary
rocky canyon
#

this

#

u can see ur PlayerLoop (and ur code/functions uve written)

eternal needle
#

If it's under editorloop then you'll have to profile again

dire estuary
rocky canyon
#

if its editor loop i'd build first and test

#

it could be just the editor

eternal needle
#

That frame doesnt even look to be an issue

rocky canyon
#

yea u missed the peak and clicked the trough

bronze shale
#

I'm curently playing around with Unity Course's game, and I want to add points system. My idea was to make invisible cube, and when player collides with it, it adds point. However it needs to colide with player, and If I do so, player hits this cube and loses. Any ideas how to make it better?

summer stump
bronze shale
dire estuary
raw token
dire estuary
summer stump
bronze shale
#
   {
       if (collision.gameObject.CompareTag("Ground"))
       {
           isGrounded = true;
           dirtParticle.Play();
       } else if (collision.gameObject.CompareTag("Obstacle"))
       {
           gameOver = true;
           explosionParticle.Play();
           dirtParticle.Stop();
           playerAudio.PlayOneShot(crashSound, 1.0f);
           Debug.Log("Game Over");
           playerAnim.SetBool("Death_b", true);
           playerAnim.SetInteger("DeathType_int", 1);

       }

       if (collision.gameObject.CompareTag("Points") && !gameOver)
       {
           Debug.Log("YOU GAINED POINT");

       }
       
   }```
#

That's what I want to do, I want player to be able to pass this cube, but trigger CollisionEnter. I just don't know how

summer stump
#

As we said twice

rocky canyon
summer stump
#

OnTriggerEnter instead of OnCollisionEnter

willow scroll
rocky canyon
#

it may be helpful (as its already setup to work w/ cc's and/or rbs)

bronze shale
#
    {
        if (other.gameObject.CompareTag("Points") && !gameOver)
        {
            Debug.Log("YOU GAINED POINT");
        }
    }```

Something like that?
rocky canyon
#

but if u want to use custom stuff. may just need to tinker around w/ it and debug as u do

#

other.CompareTag() is sufficient

willow scroll
summer stump
errant pilot
#

Guys does onmousedown() need a rigidbody?

willow scroll
#

It only needs a Collider

bronze shale
#

Thank you, It works how it should now 🙂

errant pilot
willow scroll
errant pilot
#

thats it

willow scroll
#

Would it be possible for me to observe it in a visual form?

summer stump
rocky canyon
#

^ you need this too

errant pilot
errant pilot
willow scroll
rocky canyon
#

you should be able to check the eventsystem during playmode and see exactly what ur mouse is interacting w/

errant pilot
#

this is it all

willow scroll
errant pilot
willow scroll
#

Is OnMouseDown not called at all?

rocky canyon
#

debug it

errant pilot
errant pilot
rocky canyon
#

jsut checking

willow scroll
errant pilot
#

the showmodule one

willow scroll
#

Send it too

errant pilot
#

when i make the object trigger mid game it works once

errant pilot
willow scroll
#

Well, where is the debug?

errant pilot
willow scroll
#

You have just said it is inside of ShowModule

#

Put a print and see

errant pilot
#

i said outside it

willow scroll
#

You said "outside of OnMouseDown, inside of ShowModule"

rich adder
#

how would you even put debug.log outside a method 🤔

errant pilot
#

i meant outside the showmodule inside the onmousedown

willow scroll
willow scroll
summer stump
#

Just put it back, show the debug, then show the console (without cropping it)

errant pilot
#

this is what it was like

#

oh

#

it was the z coordinate

pliant sleet
#

Why does my text suddenly disappear when its size passes a number and how do I make it so it won't ?

summer stump
pliant sleet
#

Thank you

warm raptor
#

Hello ! I tried to make a list where I can put Text mesh pro that are In my UI so I can easily access them, but I see nothing in the inspector

public List<TMP_Text> PseudoTeam1 = new List<TMP_Text>();
rocky canyon
#
    [SerializeField]
    private List<TMP_Text> pseudoTeam1 = new List<TMP_Text>();``` works too
warm raptor
warm raptor
rocky canyon
#

then use public

#

i was just showing that both methods work

cosmic dagger
rocky canyon
#

or that ^

warm raptor
rocky canyon
#
    private int _score;

    public int Score
    {
        get { return _score; }     // public getter allows reading the value
        private set { _score = value; }  // private setter restricts modification to within the class
    }``` something like this, but thats as far as i can expand on it.. as i haven't gotten that far to use em yet
#

i intend to soon tho

warm raptor
rocky canyon
#

its good to encapsulate the thing, while exposing only the necessities

#

i typically just make stuff public 🫣 i need to stop lol

warm raptor
rocky canyon
#

no, i mean i need to stop doing that.. its better to use getters and setters

cosmic dagger
rocky canyon
#

someone like random, can tell u more important stuff about it

warm raptor
rocky canyon
#

idk, ask random

#

if you only intend on reading it from other classes.. and can ensure u dont write over it.. then sure just use public

#

problem is when code starts to grow, or ur sharing it w/ other developers.. its easier to make stuff public and private / with setters and getters and stuff..

#

it'll stop accidents from happening

mint remnant
#

if unsure, make it all private until compiler complains about no access to a variable, turn it public at that point

rocky canyon
#

^ thats how i usually work

rocky canyon
#

but! imma start using properties asap

queen adder
#

How would I refrence a component from a prefab

mint remnant
#

naturally good up front design thought trumps that, but it's a fair fallback

rocky canyon
#

Reference reference = Instantiate(prefab);
Whatever newWhatever = reference.GetComponent<Whatever>();

#

Instantiate returns the instance of the copy

queen adder
#

Okay thank you

rocky canyon
#

prefabs can't reference scene objects
and scene objects can't reference prefab internals

cosmic dagger
rocky canyon
#

unless u get into the nittygritty.. i think u can use Resource stuff to access it

queen adder
#

Yea i figured out that scene objects cant refrence prefabs im tryign to get the prefab to move towards a gameobject

rocky canyon
#

you could always use a public method inside the prefab to set things.. (like initialization method)

#

oh you spawned?
well, spawnedthingy.SetYourTarget(gameobject);

rich adder
rocky canyon
#

but rreally.. im soo far behind w/ properties

rich adder
#

they're too good!

#

hardly use public fields now

rocky canyon
#

the next time i come crawling for help, they'll be properties involved.. 😛

bronze token
#
using TMPro;

public class HUDManager : MonoBehaviour
{
    public TMP_Text scoreText; // Optional, if you are using a score system
    public TMP_Text coinsText;
    public TMP_Text worldText;
    public TMP_Text timeText;
    public TMP_Text livesText;

    public void UpdateScore(int score)
    {
        if (scoreText != null)
        {
            scoreText.text = "SCORE\n" + score.ToString();
        }
    }

    public void UpdateCoins(int coins)
    {
        if (coinsText != null)
        {
            coinsText.text = "COINS\n" + coins.ToString();
        }
    }

    public void UpdateWorld(string world)
    {
        if (worldText != null)
        {
            worldText.text = "WORLD\n" + world;
        }
    }

    public void UpdateTime(int time)
    {
        if (timeText != null)
        {
            timeText.text = "TIME\n" + time.ToString();
        }
    }

    public void UpdateLives(int lives)
    {
        if (livesText != null)
        {
            livesText.text = "LIVES\n" + lives.ToString();
        }
    }
}

This is the HUDmanager

#

ngl, we are complete beginners

eternal falconBOT
bronze token
#

oh mb

rich adder
#

I'm guessing your GameManager has HUDManager missing that might also be part of the problem

#

according to the screenshot you sent anyway

bronze token
deft grail
bronze token
#

i think we've added

bronze token
rich adder
#

where is the one that updates the logs

bronze token
#

but for some reason we cant see

#

1 sec

rich adder
#

also whats happening here

rich adder
bronze token
bronze token
rich adder
#

you will lose and references you have to scene objects

#

since cross scene references dont work

brisk thunder
#

we kinda used ai a lot

deft grail
brisk thunder
#

lol

deft grail
#

you used it for stuff you shouldnt really need to use it at all

brisk thunder
#

so what now

rich adder
#

when you link them together, the other object starts as DDOL which is inside a completely different scene

brisk thunder
rich adder
brisk thunder
#

we are both working on the same thing

rich adder
#

Ohh..well you should've made that clear

#

or said something lol

brisk thunder
rich adder
# brisk thunder mb

anyway not the complete problem but its part of the problem. You see the reference in the Game Manager goes Missing for UI ?

#

thats because one is inside DDOL scene and one is not, what you got going right now is cross-scene references which unity does not do (cannot reference components in another scene from one scene)

rocky canyon
#

you'll need to carry them over from one scene to another w/ the manager.. or re-reference the new ones on scene load

rich adder
#

Singleton is also an option

pallid nymph
#

well, to be fair, if you just moved something to the DDOL scene you'd be fine if you need it to reference the same object

rich adder
#

since these are managers

pallid nymph
#

it's not randomly going to get lost

rocky canyon
rich adder
#

yes each has their pros and cons

rocky canyon
#

i DDOL my singletons all the time

rich adder
#

I dont use DDOL on all my singletons, so I reserve it for specific things

pallid nymph
#

DDOL is pretty much the worst, as it means you can't easily restart scenes anymore and you need to take extra care to handle each DDOL object... and 99% of the time people use them because it's the default singleton implementation and not because they need them
/rant 😅

rocky canyon
#

w/ all the stuff i need to follow the manager along the game flow

rich adder
#

yea thats also a good way to do it as well

eternal needle
rocky canyon
#

lol.. my DDOL is useless!

#

tf lmao

rich adder
#

carrying the whole squad

rocky canyon
#

just never implemented it seems

#

sooo, theres 2 people here w/ the same problem/ same unity project?

#

or yall just having the same issue / different unity projcs

brisk thunder
#

so what we can do now as we are beginner
is there any voice channel i can join and share my screen

rocky canyon
#

you can record a video and post it up here

#

theres no VC's in this discord

rich adder
brisk thunder
#

me and kenmaaa are working on the same project

rocky canyon
#

alright! just wanted to confirm.

silver girder
#

sikatrick
11m
my soccer/football when i hold LMB it doesnt shoot the ball maximum power is 30 and script placed in the player which is only a capsule with a movement script

script here

using UnityEngine;

public class Shot : MonoBehaviour
{
public GameObject soccerBall; // Reference to your soccer ball
public float maxPower = 100f; // Maximum power for the shot
private float power = 0f;
private bool charging = false;

void Update()
{
if (Input.GetMouseButtonDown(0)) // Left mouse button down
{
charging = true;
power = 0f;
}

if (charging)
{
    power += Time.deltaTime * 100; // Increase power over time
    if (power > maxPower)
    {
        power = maxPower;
    }

    // Optional: Add visual feedback for power here
}

if (Input.GetMouseButtonUp(0)) // Left mouse button up
{

    charging = false;
    ShootBall();
    power = 0f;
}

}

void ShootBall()
{
if (soccerBall != null)
{
Rigidbody rb = soccerBall.GetComponent<Rigidbody>();
if (rb != null)
{
Vector3 direction = (Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.transform.position.z)) - soccerBall.transform.position).normalized;
rb.AddForce(direction * power, ForceMode.Impulse);
}
}
}
}

eternal falconBOT
eternal falconBOT
rich adder
#

double kil

silver girder
#

!code

eternal falconBOT
rich adder
#

how do you miss it twice lol

silver girder
#

MY ENGLISH IS BADD

rocky canyon
#

no worries, use a translator.

#

Click Link -> Paste Code -> Save Code -> Copy New Link -> Paste New Link Here

silver girder
#

my soccer/football when i hold LMB it doesnt shoot the ball maximum power is 30 and script placed in the player which is only a capsule with a movement script

script here

using UnityEngine;

public class Shot : MonoBehaviour
{
public GameObject soccerBall; // Reference to your soccer ball
public float maxPower = 100f; // Maximum power for the shot
private float power = 0f;
private bool charging = false;

void Update()
{
    if (Input.GetMouseButtonDown(0)) // Left mouse button down
    {
        charging = true;
        power = 0f;
    }

    if (charging)
    {
        power += Time.deltaTime * 100; // Increase power over time
        if (power > maxPower)
        {
            power = maxPower;
        }

        // Optional: Add visual feedback for power here
    }

    if (Input.GetMouseButtonUp(0)) // Left mouse button up
    {

        charging = false;
        ShootBall();
        power = 0f;
    }
}

void ShootBall()
{
    if (soccerBall != null)
    {
        Rigidbody rb = soccerBall.GetComponent<Rigidbody>();
        if (rb != null)
        {
            Vector3 direction = (Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.transform.position.z)) - soccerBall.transform.position).normalized;
            rb.AddForce(direction * power, ForceMode.Impulse);
        }
    }
}
}
rocky canyon
#

good enough.

silver girder
#

tank yu

rich adder
silver girder
rich adder
#

so did you debug the method to make sure it runs?

brisk thunder
#

so we dont know about DDOL in script

rich adder
#

don't use things you do not understand first

grave frost
rich adder
#

have somewhat of an idea what its doing

rocky canyon
silver girder
#

UHM LEMME SEE

#

oop cpas

#

NullReferenceException: Object reference not set to an instance of an object
Shot.ShootBall () (at Assets/Scripts/Shot.cs:44)
Shot.Update () (at Assets/Scripts/Shot.cs:32)

rich adder
#

well there you go

rocky canyon
#

fix those errors and it should work..

rich adder
#

you cannot continue the rest of that code with NRE before
code runs top to bottom line by line, if line above fails. Rest wont continue

rocky canyon
#

did you assign

silver girder
#

yes

grave frost
#

is Rigidbody rb = soccerBall.GetComponent<Rigidbody>(); line 44?

rocky canyon
#

is there a rigidbody on it?

rocky canyon
#

LINE NUMBERS

grave frost
#

in your IDE, there should be code lines on the left side. What is on line 44?

rocky canyon
#

is line 44 that line

silver girder
#

really

rich adder
#

thats why I said use links..

#

we'd know the line by now

rocky canyon
#

the 44, and 32 are line numbers if u double click the error it should open the IDE to where the error is

#

my guess is ur rigidbody isn't on the soccerball

rich adder
#

I tried pasting in VSC but lines dont match

grave frost
rich adder
#

for me 44 is

rocky canyon
grave frost
#

@silver girder we just waiting to see what's on line 44

rocky canyon
#

it has to be soccerball or RB

#

theres nothing else

grave frost
# rich adder for me 44 is

yea, depending on indentation and crap it could be slightly different. Likely the line or two under it or above it?

rich adder
#

maybe this error is old

rocky canyon
#

Camera.main?

#

lol

silver girder
#

!code

eternal falconBOT
rich adder
#

can you just like CLEAR all errors and re-run that code

#

send the code as is with link service as shown in bot message

silver girder
#

``
Vector3 direction = (Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.transform.position.z)) - soccerBall.transform.position).normalized;

``

#

line 44

rich adder
#

ok well either Camera doesnt have Main Camera tag or soccerBall is null

grave frost
#

or both lol

#

if soccer ball is destroyed, you'd get a null reference exception. You should look at the inspector in play mode when you get that error to see if it lost the reference. Also double check your camera has the main tag.

silver girder
#

hey guys btw the code is ai generated

mint remnant
#

LOL

rocky canyon
#

don't tell us that

silver girder
#

ik only lua

rich adder
#

no shite

rocky canyon
#

thats a good way to get ignored

silver girder
#

nvm didn't say anything

rich adder
#

copying code you dont understand for us to fix is not a good look

#

esp when its crap ai stuff

silver girder
grave frost
#

I have nothing against AI generated code, what I have is against people thinking AI can generate code for you without knowing how to code. If you know lua, learning c# should not be out of your reach.

silver girder
rocky canyon
rich adder
#

we already pointed out the issue

rocky canyon
#

!learn @silver girder

eternal falconBOT
#

:teacher: Unity Learn ↗

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

rich adder
#

but its hard for you to fix it if you dont know where to look

rocky canyon
#

try this out ^

silver girder
rocky canyon
#

you wont regret learning the proper way

rich adder
#

it pays dividends to learn do it properly

grave frost
rocky canyon
# silver girder yes i fixed

in ChatGPT - type this:
"the Unity Discord Helped me Fix your jacked up code.. Can you from now on tell me when I need to assign references in the Inspector.. so that doesn't happen again. K, Thanks"

silver girder
#

ok

rich adder
#

nothing wrong with using AI tools for us more experienced and know what to look for, when its wrong or not we can tell etc.. it just bad for anyone who has no experience or knowledge in the language

warm raptor
#

Is their a way to change the color of a material in a script ?
the players have markings around their arms and helmets and I'd like to be able to change the color of the markings according to their team. Is there a way to store the material in the player information and access it to change the color?
here's the class where I store the player's parameters

public class PlayerInfo
{
    public GameObject Player { get; set; }

    public int Health { get; set; }

    public int Kills { get; set; }

    public string PreviousTeamState { get; set; }

    public string Coordinates {  get; set; }

    public string PreviousLivingState { get; set; }

    public Animator PlayerAnimator { get; set; }
}

where I create my new players :

if(!Players.ContainsKey(newID))
            {
                var playerInfo = new PlayerInfo { Health = 100, Kills = 0, Coordinates = "0", PreviousLivingState = "1", PreviousTeamState = "1"};
                Players[newID] = playerInfo;
                player = Instantiate(PlayerPrefab, new Vector3(10, 10, 10), Quaternion.identity);
                player.name = newID;
                Players[newID].Player = player;
                Players[newID].PlayerAnimator = player.transform.GetChild(0).GetComponent<Animator>();
                Players[newID].PlayerAnimator.enabled = true;
            }
rocky canyon
#

its a tool, not a tutor

silver girder
#

guys im dumb so pls dont be bothered

rocky canyon
silver girder
rich adder
#

otherwise you're just tinting green one and wont look good

grave frost
rocky canyon
#

white materials w/ tinting is the way to go

rocky canyon
#

keeps u from having to have multiple colors for no reason

warm raptor
rocky canyon
#

when white works for every color

rich adder
#

you probably want to change the sharedMaterial

#

but should still have 2 materials TeamA/TeamB or whatever

#

when you modify material runtime it creates a new one

rocky canyon
#

^ ohh facts

rich adder
#

so you will have a lot of materials garbage

rocky canyon
#

ya, jsut make 2 now that i think about it.. dont wanna be copying em like nav mentioned

grave frost
#

You'd still probably want to make them white and set their color using the method I stated, just get the sharedMaterial reference insteead.

rocky canyon
#

you can change out the sharedMaterials by index i think if there's multiples

warm raptor
#

ok, but how can I dicide which one to apply to the mesh (because usually I just drag and drop the material to the mesh 😅 )

rocky canyon
#

look in the Materials drop down

rich adder
#

two white materials is fine to change colors runtime, jsut make sure it gets assigned to correct team member

#

enum maybe ? idk how you distinguish teams

#

have the two fields Material TeamA/TeamB

rocky canyon
#

not sure if u have multiple materials on the mesh

#

but if u do.. u can find w/ one corresponds w/ the headband or w/e

rich adder
#

oh right if it has multiple material you need the index:P

rocky canyon
#

materials[materialIndex] = newMaterial;

rich adder
rocky canyon
#

if thers just 1 material its ez pz

warm raptor
rocky canyon
#

🫣 lol

warm raptor
#

I don't have a mesh renderer for the whole charater ...

grave frost
rich adder
frosty hound
#

It'll be a child object

rich adder
#

you can type t:MeshRenderer in hierarchy

rocky canyon
warm raptor
grave frost
rich adder
warm raptor
#

I don't even rename my bones ... 🫠

rocky canyon
grave frost
rich adder
grave frost
rocky canyon
#

ohh, they're seperate pieces.. = 1 material

warm raptor
grave frost
rocky canyon
#

1 material

rich adder
#

materials is collapsed catcrymic

rocky canyon
#

but the index is 1

grave frost
rocky canyon
#

indexLength!

#

tomato tomato

rich adder
#

not a code question, this is a code channel

rigid ridge
rich adder
#

also you should really look into software like OBS or ShareX

rigid ridge
grave frost
# warm raptor like that ?

ok one material. Reference those meshes in your script and set the color on their shared materials, something like this should get you started:

public MeshRenderer meshColor1;
public MeshRenderer meshColor2

public Color color1;
public Color color2;

private Material matColor1;
private Material matColor2;

void Awake()
{
  matColor1 = meshColor1.sharedMaterial;
  matColor2 = meshColor2.sharedMaterial;

  // if it doesn't work, try "_BaseColor" instead. Not sure which is which tbh.
  matColor1.SetColor("_Color", color1);
  matColor2.SetColor("_Color", color2);
}

*disclaimer, I wrote this in discord just now and it's untested

rich adder
#

phone recording are cringey lol

rigid ridge
rocky canyon
#

ShareX ☑️ one vote for ShareX

rich adder
raw token
#

Wasn't that Sam Bankman Fried's thing 😂

#

(I love sharex)

warm raptor
rocky canyon
#

teamAMaterial;
teamBMaterial;

grave frost
# warm raptor and if on my helmet I have like 5 different materials 😅 ?

on your helmet it looks like the green is the first one. Just replace one of the lines like this:

matColor2 = meshColor2.sharedMaterials[0];

remember, the index (in this case 0) would be the position of the material - 1. So if it's the first material, it's 1 - 1 = 0. If it's the second, 2 - 1 = 1, etc. Double check what position it's in under the mesh renderer > materials.

rocky canyon
#

unless he wants the player to chose a color..

#

like dynamically

#

that'd be cool

rich adder
rocky canyon
grave frost
rich adder
#

wouldn't you want to assign a new material to the renderer ?

rocky canyon
#

no, u were setting the matCOlor to the sharedMaterial.. not the sharedMateiral to the mat color

rich adder
#

instead of copying the mateiral

grave frost
#

you aren't copying the material like this, you're getting a reference to the shared material and changing it.

rich adder
#

yeah but materials modifying at runtime makes a new copy no?

rocky canyon
#

am i high?

warm raptor
grave frost
rich adder
#

they are reference types, if you change one at later point it will change original too but these are new instances of materials so new one gets made

grave frost
rich adder
#

or make an enum

rocky canyon
rich adder
#

but yeah two prefabs will be easier

rocky canyon
#

and since we're talkin about sharedMaterials.. we'd basically need 2 prefabs

grave frost
rich adder
#

ill take your word on it here, I havent messed with materials runtime too much

grave frost
#

Maybe modifying renderer.sharedMaterial creates a new instance, but it's only one new instance and not a new instance for each mesh.

rich adder
#

I generally swap out materials instead of changing them

warm raptor
rich adder
raw token
#

Altering a sharedMaterial will change it for all shaders which use it which do not have their own unique instance. You can also use sharedMaterials for equality checks with material fields :)

rich adder
#

shits kinda confusing ngl

rocky canyon
rocky canyon
grave frost
rocky canyon
#

im taking a knee

rich adder
#

make a red and blue material or whatever and just swap it. Screw setting this color shit at runtime lmao

#

call it a day

rocky canyon
#

my original concensus as well..

ember gate
#

hey when creating the jump what aspects should I consider
like what really makes the character jump

rocky canyon
#

Y velocity

warm raptor
rocky canyon
#

find meshrenderers w/ that tag after u instantiate it

grave frost
# warm raptor I don't understand why you are now talking of having 2 prefab 😭

Basically you have a fewe options:

  • 1: Use two prefabs, each with a different white material, then set their colors at runtime using the method I showed you. This method allows some customization later on, like changing of the enemy team or friendly team color by the user.

  • 2: Use two prefabs, each with a different material with a preset color. Reduces code needed, but no customization options.

  • 3: use renderer.material instead of renderer.sharedMaterial and then doing the same thing I showed earlier. This will create more material garbage, but probably not worth worrying about unless it really causes you issues.

warm raptor
rocky canyon
#

its primitive but it'd work ¯_(ツ)_/¯

grave frost
#

I like to avoid tags unless they're absolutely needed, since a game object can only have one tag.

rocky canyon
#

most of us.

ember gate
#

oh u answered it

rocky canyon
#

watch this @ember gate ^

ember gate
#

ight thanks

rocky canyon
#

its basically the same whether u use 2D or 3D

warm raptor
rocky canyon
#

theres a few issue's you'll normally run into

  • ground check
  • cancelling out built up gravity
  • input detection
  • etc
#

but you'll figure that stuff out as u work on it

grave frost
rocky canyon
warm raptor
#

because If I refer the specific part like that :

public MeshRenderer meshColor1;

and that I acces my player by doing

Players[ID].Player

can I do something like

Players[ID].Player.meshColor1

?

rocky canyon
#

how is ur game setup? do you spawn in the player at runtime?

#

or are they already in the scene

warm raptor
#

I spawn them when the client detect that the serveur has send a message with a new player ID

rich adder
ember gate
#

one question do you use transform and vectors only when creating own physics or you can use them when using unitys physics system too

warm raptor
rocky canyon
#

when he said [ID] i just knew it was networked

#

ya, but the way u handle spawning a player on a singleplayer game.. and how u handle spawning a player in multiplayer is different..
theres a bit more to think about

grave frost
# warm raptor swap between 2 material ?

Ok, so this might not be as efficient as possible or whatever, but we're in #💻┃code-beginner and imo the most important thing is doing not worrying about performance or scaling unless you really need to.

So I'd go with a two-script setup. On the object you actually instantiate, in the prefab, go with something like this:

public class MaterialChanger : MonoBehaviour {

// assign these in the inspector on the prefab
public MeshRenderer meshColor1;
public MeshRenderer meshColor2;

public void SetMaterial(Material mat)
{
  meshColor1.material = mat;
  meshColor2.materials[0] = mat;
}
}

Then when you instantiate your players...

void SomeMethodYouUseToInstantiatePlayers()
{
// instantiating players here
instantiatedPlayer.GetComponent<MaterialChanger>().SetMaterial(GetMaterialForTeam());
}

public Material GetMaterialForTeam()
{
 Material mat = null; // somehow determine material needed here and assign it to that, NOT null.
  return mat;
}

*disclaimer, this was written in discord and untested lol

rocky canyon
#

but i suppose if u have different IDs and different instances of the player.. its pretty similar

warm raptor
rocky canyon
rich adder
rocky canyon
#

and u can just call the method when its time to set em up

warm raptor
rocky canyon
#

once u realize how they work.. and whats involved in changing them around @ runtime and whatnot.. it becomes much easier

#

(muscle memory) + ofc supplemented w/ trial and error

warm raptor
grave frost
warm raptor
grave frost
warm raptor
warm raptor
grave frost
#

yes. I just had no idea how you do your teams, so using a method was the easiest catch-all I could think of.

#

with instantiatedPlayer set to your actual instantiated player reference of course.

warm raptor
grave frost
#

yea you can do that, as long as MaterialChanger is on the same object that Player is on.

warm raptor
grave frost
#

the armband is a SkinnedMeshRenderer, sorry.

#

you could chang the references to "Renderer", that should allow both in either

warm raptor
warm raptor
grave frost
#

that's probably important yes

warm raptor
royal river
#

can anyone help me make my gorilla tag fan game in unity

grave frost
deft grail
#

we can help with certain elements and tell you how you could achieve them

royal river
#

ik but i need it for beta testing

#

but i dont have unity how do i make it

deft grail
royal river
#

i cant my laptop isnt powerful enough

warm raptor
deft grail
royal river
cosmic dagger
deft grail
warm raptor
grave frost
cosmic dagger
deft grail
#

well dont look anywhere, no one's gonna do that 🤣

#

for free

royal river
#

do you have any recommendations

deft grail
#

or get a more powerful computer

royal river
#

ITS NOT THAT EASY

cosmic dagger
deft grail
#

or use something like Godot instead, sure you can handle that, though a game like that idk if would be possible

warm raptor
grave frost
warm raptor
grave frost
#

oh, you need to store it as a temporary reference to modify it apparently

#

so Material[] mats = meshColor2.materials
then use mats on the next line

#
public void SetMaterial(Material mat)
{
  meshColor1.material = mat;
  Material mats = meshColor2.materials;
  //mats.materials[0] = mat;
  mats[0] = mat;
}
warm raptor
# grave frost ```cs public void SetMaterial(Material mat) { meshColor1.material = mat; Mat...

it's not working I got those 2 issues :

Assets\_Script\Multiplayer\MaterialChanger.cs(13,25): error CS0029: Cannot implicitly convert type 'UnityEngine.Material[]' to 'UnityEngine.Material'

and

Assets\_Script\Multiplayer\MaterialChanger.cs(14,14): error CS1061: 'Material' does not contain a definition for 'materials' and no accessible extension method 'materials' accepting a first argument of type 'Material' could be found (are you missing a using directive or an assembly reference?)

grave frost
#

i think you forgot an s after meshColor2

#

and you are not doing .materials on the right thing, you want to do it on the mesh

#

it thinks you're doing something like material.materials

#

you need something like mesh.materials

warm raptor
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MaterialChanger : MonoBehaviour
{
    public Renderer meshColor1;
    public Renderer meshColor2;

    public void SetMaterial(Material mat)
    {
        meshColor1.material = mat;
        Material mats = meshColor2.materials;
        mats.materials[0] = mat;
    }

}
grave frost
#

oh im stupid sorry LMAO

#

mats[0] = mat

warm raptor
#

why ?

grave frost
#

yea, consequence of me writing these in discord and not an IDE

warm raptor
warm raptor
#
Assets\_Script\Multiplayer\MaterialChanger.cs(13,25): error CS0029: Cannot implicitly convert type 'UnityEngine.Material[]' to 'UnityEngine.Material'
Assets\_Script\Multiplayer\MaterialChanger.cs(14,9): error CS0021: Cannot apply indexing with [] to an expression of type 'Material'
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MaterialChanger : MonoBehaviour
{
    public Renderer meshColor1;
    public Renderer meshColor2;

    public void SetMaterial(Material mat)
    {
        meshColor1.material = mat;
        Material mats = meshColor2.materials;
        mats[0] = mat;
    }

}

deft grail
#

your trying to convert an array to not an array

#

then trying to use the non array LIKE an array with [0]

#

Material mats should probably be Material[] mats

#

hence the s in the name, its multiple materials not a single material

warm raptor
#

Oh thx I found a solution !

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

public class MaterialChanger : MonoBehaviour
{
    public Renderer meshColor1;
    public Renderer meshColor2;

    public void SetMaterial(Material mat)
    {

        meshColor1.material = mat;
        Material[] materials = meshColor2.materials;

        if (materials.Length > 0)
        {
            materials[3] = mat;
            meshColor2.materials = materials;
        }
    }
}

grave frost
#

btw maybe rename meshColor1 and meshColor2 to

public Renderer armband;
public Renderer helmet;

That way you know which one is having the special operation performed on it

warm raptor
warm raptor
grave frost
#

lol no worries, I'm at work and it's kinda slow today

ember gate
#

does anyone know a video or like something that can teach me about basic physics and maths in game development because even seeing this jump tutorial makes me insane cause I do not understand any of the physics stuff

grave frost
ember gate
#

thanks

rotund hull
#

how can i set the z rotation of a 2d object to be a RaycastHit2D.normal?

ember gate
#

damn so long

#

ill watch it tomorrow

#

now its too late for my brain but thanks a lot

grave frost
grave frost
# ember gate damn so long

thats just the first episode too... i mean they have entire math courses at universities and math degrees can take like 6 years so... buckle in lol, it's worth it to watch all the episodes. I have a friend that did and he said it was worth it. I only watched her matrix math one.

warm raptor
grave frost
warm raptor
eternal needle
#

There is the formly serialized attribute

grave frost
#

yea but then you end up with [FormerlySerializedAs(...)][FormerlySerializedAs(...)][FormerlySerializedAs(...)]... if you rename things as often as me lol

deft grail
eternal needle
# ember gate ill watch it tomorrow

You could also try learning vector math without the game dev part. At least from what I've seen, math "in game dev" tutorials are filled with a bunch of fluff or are just a lot longer for no reason.
Vector math is very simple, tons of resources out there. When you apply it to game dev, unity has built in functions for a lot of the actual tricky stuff

green owl
#

Does anyone know how to change this with C#

eternal needle
raw token
green owl
#

Itensity multiplayer

#

The thing on zoomed image

warm raptor
raw token
green owl
#

Yea I know I tried that

#

fuck. I realiesd now why it was giving me an erro

#

Traditional vscode adding using.UnityEngine something and it didnt recognize from what I wanted it to be used

grave frost
#

well in my experience you do, but my experience was twice and I stopped using it because of that

eternal needle
#

im not sure of the exact specifics to it, but ive most definitely deleted all of them in my project and had no issues

copper orbit
#

is rigidbody conflicting with navmesh pretty common? My objects are jittering pretty badly. Is disabling and enabling NavMesh/Rigidbody when the other is needed, the common fix?

tawdry ember
#

Can someone tell me how to detect if 2 different things are true to make something else happen?

#

Im trying to detect if the player is on the ground and if i hit space to make the character jump but it dont work the way i want it to

dense pike
#

@tawdry ember yoo

grave frost
cosmic dagger
meager gust
#

you'll need a custom solution that involves getting the path array and manually steer the rigidbody towards each point using addforce or velocity

#

its not as hard as it sounds

meager gust
crisp token
#

will this line reset the enum stored in allMovementStates[i] to its default value?

#

I cant test it rn

teal viper
slender nymph
#

and if the type of allMovementStates is already known then assign whatever its default value is without a cast

#

there's also the default keyword you can use

ancient rampart
#

when using unity web request (in this case with standalone file browser) is there a way to return the local path rather than the uri?

grave frost
#

Usually when using web request to load a local file you have to do it that way, unless I'm mistaken? So what would be the point in doing that?

ancient rampart
#

just trying to log the path for another function to read the contents of the file, might just do it all when you open the file tho to avoid having to get the local path

grave frost
#

but on platforms where you have to use a URI to open files this would break when trying to load using the filePath.

ancient rampart
#

And gotcha

grave frost
#

actually there's a simpler way I think

ancient rampart
#

I’ll probably just make it parse all the data when it gets the path

grave frost
#

UnityWebRequest.uri.LocalPath should work, I think UnityWebRequest.uri returns a System.Uri object.

ancient rampart
#

Gotcha, I’ll give it a shot, thank you

crisp token
crisp token
summer stump
slender nymph
crisp token
#

i tried using default but ig i was messing it up

#

like default(movementState.GetType())

slender nymph
#

no it's literally just the word default

crisp token
slender nymph
#

no literally just the word default

#

i don't know how much clearer i can be about that

crisp token
#

i dont get how that would work

#

enum.default?

slender nymph
#

default

crisp token
#

just in a line?

#

allMovementStates[i] = default

#

cant rn playing mc lol

slender nymph
#

then try it when you're done

crisp token
#

alright bro ty

eternal falconBOT
#

:teacher: Unity Learn ↗

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

crisp token
#

Is a Class a kind of Type

languid spire
#

yes a class is a Type

crisp token
#

why does C# have GetType() instead of GetClass()?

languid spire
#

because everything has a Type not just classes

crisp token
#

so Type includes Classes and Values?

languid spire
#

EVERYTHING

crisp token
#

🤯

summer stump
#

public [type] myVariable

Think about all the different things you put in that spot where I wrote type.

crisp token
#

I can think of Class names and value types, and things like structs or enums which are kind of value types I think (idk)

languid spire
#

you can think of Type as the glue that holds C# together

tiny plaza
#

Hey does anyone know how to add a jump buffer with the input system? (not the input manager)

#

i did this but it doesn't work

languid spire
#

should that not be
jumpBufferCounter -= jumpBufferTime;
Also please do not post screenshots of code unless specifically asked to

mint remnant
#

looks like same code as yesterday where someone mentioned comparing a float to 0f was very unlikely

tiny plaza
tiny plaza
languid spire
#

presumable you already have the counter and time values set up so you need to decrement for it to have an effect.

languid spire
tiny plaza
mint remnant
#

the thing with floats is it might display as 0.0, but internally and for comparisons it might be 0.000000000001

tiny plaza
#

and do i need to add "f" to intergers?

languid spire
#

no

#

f means float

tiny plaza
#

wait it's not working

mint remnant
#

which weirdly enough is an alias back to a struct named Single

tiny plaza
#

because "moveDirection = context.ReadValue<Vector2>().x;" so it need's a float

#

what do i do about that

languid spire
crisp token
#

allMovementStates contains different kinds of enums. ChatGPT tells me that even though Enum.parse() returns an object, when I replace an element of allMovementStates with it, it will be of the same enum type specified by allMovementStates[i].GetType(). Could someone explain if / why this is true?

mint remnant
#

it's fine being a float, just that you should never compare a float to 0.0, instead cover the other ends and use an else for the remainder

tiny plaza
languid spire
#

moveDirection = (int)context.ReadValue<Vector2>().x;
the (int) is the cast to int. It means convert to

#

you really did skip learning the basics of C#

elder mesa
#

Hey guys, I've got some doubts to ask.
I'm currently working on a car controller using hooke's law. I've got it all working well and good and i decided to add steering but the issue is that i have no idea on how to add steering using hooke's law, I've done it using wheel colliders but i'm not using them

tiny plaza
elder mesa
#

this is what it looks like

willow scroll
#

In Unity, consider rounding floats to int instead of parsing them to avoid unexpected results

elder mesa
#

i just like need a basic idea and ill build on to that, anything i try is either not working or not realistic

tiny plaza
elder mesa
#

oh my bad, sorry

languid spire
tiny plaza
willow scroll
#

For example, parsing 10.3 should usually give 10

crisp token
#

can someone explain why this line keeps the original Enum type stored in the list despite Enum.parse() returning an object?

tiny plaza
languid spire
willow scroll
#

Please, don't reffer to people directly like that

elder mesa
#

alright cool

#

my bad

willow scroll
#

If they help someone, this doesn't mean they should help everyone.

elder mesa
#

sorry

#

sorry steve

tiny plaza
mint remnant
willow scroll
crisp token
# willow scroll Not sure what that means

allMovementStates is a List<object>, it contains a bunch of different kinds of enums. Enum.parse technically returns an object, but when I assign it to the element in the list, it keeps the enum type. This is good, i just dont get how it works

cedar bone
#

whats a site, I can use to uploud videos to send here?

crisp token
#

any mp4 converter

cedar bone
#

i dont have nitro

#

if i go over by 5 seconds, i cna't send

crisp token
#

r u sure, I feel like i have in the past

mint remnant
#

imgur perhaps?

willow scroll
#

Explicitly converting it to your enum will result in a proper enum value gotten

willow scroll
cedar bone
#

I tried, I can't

willow scroll
#

Discord supports video upload up to 8MB without Nitro, and 50MB with

cedar bone
#

15 secs

#

51MB