#💻┃code-beginner

1 messages · Page 3 of 1

cursive burrow
#

!learn

eternal falconBOT
#

🧑‍🏫 Unity Learn can offer you over 750 hours of free live and on-demand learning content for all levels of experience! Make sure to check it out at https://learn.unity.com/

rich adder
#

iirc you Step Out when that happens

merry pecan
#

hey so any ideas as to where like the text box is? im trying to make it bigger but i still cant see it

merry pecan
#

ahh oops, thank you

last grove
#

is it possible to calculate the neccesary x and z rotations to rotate an object while taking into account a changing y rotation?

rich adder
rich adder
merry pecan
#

its just like more text options?

rich adder
tawdry rock
#

thanks, it would be nice to be able to see the world space as well on the moved child object

merry pecan
#

but il check it out thanks

tawdry rock
#

you also need to reffer it differently than the Text. in case if you watch some old YT tutorial where legacy text is used and wonder why your code not working

unkempt locust
#

Hello, I'm trying to make my player shoot using raycast, but I'm having this problem, can you help me? IShotHit is not working

timber tide
#

Your IDE is giving you a hint, hover over it

unkempt locust
#

o

#

ok

timber tide
#

Is your interface created somewhere in this project?

unkempt locust
#

Yes

timber tide
#

If you've got it contained in a namespace you'll need to include that too.

unkempt locust
#

Not

#

this is a script

timber tide
#

Yes, but I don't see the interface in this script, so you've got it somewhere else.

unkempt locust
#

I'm new to unity, what do I have to do?

polar acorn
#

Show the code for it

timber tide
#

Find where the interface is located. Make sure you've not encapsulated inside of a namespace or a class, otherwise you'll have to include it in this script

unkempt locust
#

And the first time I use raycast in the project

#

help me please

polar acorn
#

Where did you make IShotHit

unkempt locust
#

ok

unkempt locust
polar acorn
wind flower
#

Hello are their any videos/classes where I can learn unity for free?

eternal falconBOT
#

🧑‍🏫 Unity Learn can offer you over 750 hours of free live and on-demand learning content for all levels of experience! Make sure to check it out at https://learn.unity.com/

late burrow
#

can i exclude type printing in tostring

polar acorn
#

You can make your own toString that prints whatever you want

late burrow
#

i dont know how regular tostring works

polar acorn
#

You can make a ToString function for any class and it'll print out whatever you tell it

#

!code

eternal falconBOT
#
Posting code

📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

final kestrel
#

Ahh I'm sorry

rich adder
final kestrel
#

All right a minute

violet verge
#

on my audio manager I only have one SFX source, does that mean only one sfx can play at a time? should I have my PlaySound Method make a new audio source each time it's called?
https://gdl.space/edajawuxoj.cs

final kestrel
#

this the inspector

rich adder
# final kestrel this the inspector

first I'd use an actual character controller if you want accurate collisions / physics (not translate)
also is the platform actually marked as Ground layer?

final kestrel
#

Yes it is. I have a script for character controller too. It still does the same. Want to see it?

rich adder
final kestrel
#

I am using characterController.move

#

on that script.

rich adder
#

ohh ok , did you try using that script instead with character controller

final kestrel
#

The reason why I avoid using physics is that, first I couldnt figure how to set a static speed for move forward. Like it continuously adds velocity. Managed the jump. My character should rotate 90 degrees on the wanted direction instantly when enters trigger. So I could not do it with physics.

final kestrel
rich adder
#

instead of translate you just use .Move

final kestrel
#

You mean with using character controller? I was talking about using rigid body based physics sorry.

#

I can give the code with character controller too if you wish.

rich adder
final kestrel
#

It just sits on top of an invisible ground it feels like.

#

My groundcheck still works as well

#

even though it does not hit the ground while its in the air.

rich adder
final kestrel
#

but my ground check is correct. I didnt mean its broken as well.

#

When I first start moving. The character is on the ground no problem. I execute the jump it jumps as expected. When falling down it does not hit the ground back. It feels and looks as if there is another ground or some other collider above the ground. It keeps moving based on that imaginary ground.

#

I created a default cube and a default platform. Attached the scripts. Chose the layers and all. It does the same. So im pretty sure its not because of the imported assets.

rich adder
final kestrel
#

all right I will do that

#

Sorry but with the gizmos enabled on right top corner. It doesnt show the axis.

#

It looks like this

rich adder
hushed hinge
hushed hinge
final kestrel
#

Ground check is at the bottom which is just an empty

rich adder
final kestrel
#

In the code yes

rich adder
#

so maybe its above the ground by 0.1f

#

remember its a circle

#

sphere**

rich adder
#

then u ccould use OnCollisionEnter2D to destroy projectile

final kestrel
#

Should not it be above the ground and below the player?

#

to detect ground layer?

hushed hinge
final kestrel
#

Checksphere has a physical collider that can prevent the player from touching the ground?

#

I thought it was something like a sphere collider which is just a trigger

rich adder
rich adder
hushed hinge
#

what colliders?

rich adder
#

put a collider on the house if you want the bullet to hit it

hushed hinge
rich adder
final kestrel
#

uhh what is this.

rich adder
final kestrel
#

0.1

rich adder
#

and you put groundcheck.position?

final kestrel
#

These imported assets are rather small

rich adder
#

well then thats how big your checksphere is

final kestrel
#
 {
     Gizmos.DrawSphere(groundCheck.position, 0.1f);
 }```
rich adder
#

that explains the gap i suppose

hushed hinge
final kestrel
#

Hm

rich adder
#

put a tag if you want

final kestrel
#

okay i made it smaller but now it sometimes go below the ground sometimes stays on it.

#

could it be related with collision detection?

hushed hinge
#

this is so confusing

hushed hinge
timber tide
#

It's the same concept for how your character isn't falling through the ground if you think about it

hushed hinge
#

I. still. don't. know. how.

#

everything what I get from here is so super confusing like I don't know what Im supposed to do

final kestrel
#

maybe take a look at what OnCollisionEnter does

timber tide
#

For what you got there, you must have some idea cause it's looking pretty good

hushed hinge
timber tide
#

Well, read up on the usage of OnCollisionEnter. There's also Physics2D.OverlapCircle if you want to do it manually.

hushed hinge
#

what OnCollisionEnter? where?

hushed hinge
summer stump
#

Look at the example code here

#

Ah, you're 2d? One sec

hushed hinge
#

I don't know what I'm supposed to do

rich adder
rich adder
hushed hinge
final kestrel
#

navarone. After setting the sphere a smaller size. I mostly manage to stay on ground. But this time it goes below the ground a little.

hushed hinge
rich adder
hushed hinge
#

I am not a expert and coding, I'm mostly used to designing

rich adder
#

It’s a trigger so you can’t even use OnCollision method

rich adder
#

Anyway you already have an OnTrigger method so just add the walls to it ?

hushed hinge
#

how?

rich adder
hushed hinge
#

they are tag to ground

rich adder
#

So you’re half way there

hushed hinge
#

also how can I make that a projectile sees that it hits a wall

rich adder
#

Tag check

summer stump
#

It is EXACTLY the same, but with the Ground tag (or whatever you named it)

hushed hinge
summer stump
#

else if

#

Not else

#

@hushed hinge But yeah, like that

hushed hinge
hushed hinge
summer stump
#

What is that video even showing? I didn't see a bullet, or am I missing it?

hushed hinge
summer stump
summer stump
#

Show the inspector for the bullet again, did you change it from istrigger?

hushed hinge
summer stump
#

Any other colliders on it?

rich adder
#

Yeah trigger would not be colliding

hushed hinge
#

no, just box collider

rich adder
#

Hmm maybe the movement

summer stump
#

Is the green sphere a child?

hushed hinge
summer stump
#

But I guess destroying the parent would destroy the child too, so nevermind

hushed hinge
#

what am i supposed to do? I am so confused

rich adder
#

!code

eternal falconBOT
#
Posting code

📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

hushed hinge
rich adder
hushed hinge
#

i uses gld now, then what?

rich adder
#

Save. Send link

hushed hinge
rich adder
#

Yup

#

Where is the movement or am I blind rn..

hushed hinge
#

I don't know, My teacher made it, not me

summer stump
#

I think its velocity is set externally when spawned. I see it set to 0 at one point

#

Can you minimize the components in the inspector and show all of them?

Please don't crop the shot either

hushed hinge
#

what components? I don't understand

summer stump
#

There is a little arrow to minimize them on the left of the name

hushed hinge
#

???

#

this is so super confusing, I don't understand any of it

eternal falconBOT
#

🧑‍🏫 Unity Learn can offer you over 750 hours of free live and on-demand learning content for all levels of experience! Make sure to check it out at https://learn.unity.com/

rich adder
#

You’re only shooting yourself in the foot, doing what ur doing now

#

This isn’t a good way to learn

#

It’s essential you learn the basics before even attempting to code anything

summer stump
#

Click these arrows

#

Yeah. What nav said for sure

hushed hinge
summer stump
#

Of ALL of them. And DON'T crop the picture I said

#

Audio source is still expanded

#

So is what I assume is the animator

hushed hinge
#

ok, I clicked all of. the arrows

queen adder
#

so how do i make this animated sprite be infront of this to be seen

polar acorn
queen adder
hushed hinge
summer stump
polar acorn
hushed hinge
#

what's cropping?

polar acorn
queen adder
summer stump
polar acorn
queen adder
hushed hinge
polar acorn
#

Animators animate

queen adder
polar acorn
#

SpriteRenderers don't

queen adder
#

no it works like this

queen adder
hushed hinge
summer stump
# hushed hinge

Ooookay, there we go. So that doesn't look like anything on the bullet should be doing it. Now click the wall prefab and show that

polar acorn
# queen adder

A SpriteRenderer doesn't animate things automatically. Animators do

#

And animators can affect an Image as well

polar acorn
#

Which is what does the animating

queen adder
polar acorn
#

Not the sprite renderer

#

So don't use a Sprite Renderer

queen adder
#

what do i use for my animated logo

polar acorn
#

If it's on a canvas it should be an Image

queen adder
polar acorn
#

nothing changes

#

you still use an animator with a clip on it

summer stump
# hushed hinge

Ok, no scripts that could cause it on there either...
I dunno. Triggers should not cause that behaviour

hushed hinge
#

no triggers on it

summer stump
hushed hinge
#

yeah

summer stump
#

I was gonna say put some Debug.Logs around to see what is happening

rich adder
#

Whereever the movement is set, thats a good clue

summer stump
last grove
#

why does multiplying the capsules rotation with the white slopes rotation turn my player so far?

rich adder
#

Inside the compre tag

queen adder
#

well it aint moving

polar acorn
queen adder
polar acorn
# hushed hinge like this?

You should probably check the Intro to C# guide in the pins. Debug Log should be literally the first line of code you ever wrote

polar acorn
summer stump
queen adder
#

do i have to use another format or

polar acorn
#

If your clip is specifically targeting a SpriteRenderer you will need to make one that changes the sprite of an Image

polar acorn
queen adder
#

Imma just ask chat gpt

polar acorn
#

Have fun with that

#

If you want to animate something, you have to actually animate it

#

You're not going to avoid this by asking a chatbot

last grove
polar acorn
hushed hinge
#

I'm looking it up now

rich adder
last grove
north kiln
#

Ah, ground2, the better ground

#

the sequel to ground

last grove
#

trying to add in the players rotation over rotates the capsule which makes no sense because it only has a y value

queen adder
#

isnt it animated lol

polar acorn
#

Is that animating a sprite property on a sprite renderer

#

or a sprite property on an Image

queen adder
summer stump
polar acorn
hushed hinge
last grove
queen adder
#

this or is there another tool?

summer stump
polar acorn
last grove
polar acorn
last grove
summer stump
#

So those are all DIFFERENT projectiles showing, hitting the wall, destroying themselves, and spawning a new one

At least that is what it looks like

queen adder
polar acorn
queen adder
#

what do i change here

polar acorn
summer stump
# hushed hinge

So... is _objectToSpawn supposed to be a projectile?

I really should have noticed that earlier notlikethis

summer stump
#

Why would you spawn a new projectile when it hits something?

#

Probably supposed to be some visually effect

#

Definitely comment out that instantiate line and the first destroy line and see if that fixes it

#

Lines 67 and 68

hushed hinge
#

my teacher made the script

summer stump
hushed hinge
#

yeah

summer stump
rich adder
#

Probably not a real teacher

#

Probably some online course

#

Time to get a new teacher 😂

hushed hinge
summer stump
#

Debugs aren't super performant

#

You want to remove them before bulding usually

verbal dome
#

Debug.Log is pretty slow yeah

summer stump
#

But now we know the issue. You have a projectile in _objectToSpawn, and that's not what it should be

hushed hinge
#

I do not wnat it to spawm like that right now

hushed hinge
summer stump
summer stump
#

I assume it's supposed to be a visual effect

hushed hinge
#

comment it out? what does that mean?

summer stump
#

Make the line a comment by adding // in front of the words

hushed hinge
#

the proejctiles disappears after hitting the wall, thnk you

jovial peak
#

what does it mean by cant be non nullable value types, if it doesnt exist in the dict, wouldnt it be null?

north kiln
#

use that

#

value types are never null

jovial peak
#

ah thx! didnt realize -- oops,

hushed hinge
#

a betatester told me this

vast yoke
hushed hinge
#

hmmmmm.... maybe I can ask chatgbt?

verbal dome
#

Floating makes me think, are you changing rigidbody gravity anywhere?

hushed hinge
#

hmm... hard to say

summer stump
hushed hinge
#

hmmmm...

wind flower
#

Any youtube videos that you guys recommend to watch to learn unity? (not the !learn where it takes you to unity)

eternal falconBOT
#

🧑‍🏫 Unity Learn can offer you over 750 hours of free live and on-demand learning content for all levels of experience! Make sure to check it out at https://learn.unity.com/

summer stump
wind flower
#

I’d like to learn as much as possible and try to practice with what I’ve learned so far

queen adder
#

This might be a reeealllly dumb question

#

but

#
    {
        VeesInputManager.Playercontrols.BaseMap.Move.performed += OnMovePerfomed;
        VeesInputManager.Playercontrols.BaseMap.Move.canceled += (context) => _movement = Vector2.zero;
        VeesInputManager.Playercontrols.BaseMap.Attack.performed += (_) => StartCoroutine(AttackDelay());
    }

    void OnDisable()
    {
        VeesInputManager.Playercontrols.BaseMap.Move.performed -= OnMovePerfomed;
    }```
#

If its a lambda function do i have to do -= (context) => _movement = Vector2.zero? Is it a actual method under the hood?

wintry quarry
queen adder
#

I didnt think so

#

But was worried lmao

wintry quarry
#

Either use real methods or save the lambdas in a variable to unsubscribe them later

queen adder
#

Seems more convenient to just have the subscribed and not have to worry unsubscribing 🙂 thank u p... you always come in clutch

trim sun
#

!code

eternal falconBOT
#
Posting code

📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

opaque mortar
#

i made a simple script for crouching but now when you crouch the only whey to stop is to sprint there is my code https://hastebin.com/share/duruxacufa.csharp

vestal valve
#

The restart function is not working.
I mean the if condition.
Any mistakes?

gaunt ice
#

You set the game=false after game==true

ivory bobcat
#

The log will spam though but that isn't an issue with your release.

vestal valve
#

Thanks catto

spark ember
#

my game is 2d by the way

ivory bobcat
#

What do you mean by

the builds will not follow my mouse pointer

spark ember
#

ive tried to make it so that the ghost build prefabs follow my mouse pointer'

#

instead of just staying in front of my playher

ivory bobcat
#

What does it do instead?

#

Does it move as you move the mouse?

#

Is there a pattern?

spark ember
#

no

#

it just moves as I move my character around

#

it has snapping working but dosent follow my cursor at all

ivory bobcat
#

What does it do instead?

#

Does it follow a particular pattern? Like moves relative to the mouse but at an offset.

spark ember
#

i’ll try and get a video

ivory bobcat
#

If you do ```cs
void UpdateGhostPosition()
{
if (ghostBuild == null) return;

    // Get the mouse position in the world
    Vector3 mousePos = mainCamera.ScreenToWorldPoint(Input.mousePosition);
    mousePos.z = 0f;

/*
// Use the defined snap values based on the current snap mode
float verticalSnapValue = isHorizontalSnap ? ghostWallVerticalSnapValue : ghostFloorVerticalSnapValue;
float horizontalSnapValue = isHorizontalSnap ? ghostWallHorizontalSnapValue : ghostFloorHorizontalSnapValue;

    // Offset the ghost position for a better visual alignment
    mousePos.x += horizontalSnapValue;
    mousePos.y += verticalSnapValue;

    // Snap to the nearest grid position
    float snappedX = Mathf.Round(mousePos.x / buildSize.x) * buildSize.x;
    float snappedY = Mathf.Round(mousePos.y / buildSize.y) * buildSize.y;

    // Set the ghost's position to the snapped position
    ghostBuild.transform.position = new Vector3(snappedX, snappedY, 0f);

*/
ghostBuild.transform.position = mousePos;
}```Is the mouse at the correct position? I understand it will not snap but determining if it's related to your cam/mouse or the snapping algorithm.

spark ember
#

let me try

#

heres what it does with the script you sent me

ivory bobcat
spark ember
#

its an mkv

#

ill re record mp4 if u dont wanna download it

ivory bobcat
#

I'm not downloading that.

spark ember
#

ok lemme change format

ivory bobcat
spark ember
#

yes i tried that and it did the same as the video i just sent

#

execpt that one dosent have snapping

ivory bobcat
#

I don't understand the video.

spark ember
#

you can see

#

im moving my cursor around

#

and it dosent follow it

ivory bobcat
#

Are they suppose to follow or be at the exact location?

spark ember
#

i made it follow

#

and it dosent do that as you can see

ivory bobcat
#

Moving the mouse around with them jittering all over the place isn't showing me much. Maybe explain what is working and what isn't.
If you completely disable the moving do the objects still move? I'm not able to understand by the mouse moving and objects moving in the video. Maybe only move right and see if they move right. Randomly moving doesn't help me understand what's going on.

#
        if (isPlacing)
        {
            //UpdateGhostPosition();
            if (Input.GetMouseButtonDown(0))
            {
                if (CanPlaceBuild())
                {
                    PlaceBuild();
                }
            }
        }```
#

^ to test if physics or whatever may be playing a part in their displacement (I'm not sure if you're using physics or have them as non trigger etc)

#

Else move one direction only and see what the pattern is.

#

Break it down: (it's obviously not at the correct location)
Moving right does what?
What about up or down?
And left?

#

Explain the behaviors. I'm not able to interpret them from the fast random or circular movements in the video.

burnt vapor
vestal valve
burnt vapor
#

I'm not sure why you're saying "it worked" when it's a clear flaw in your if statement

#

And yes, the rest of your code is also wrong, because you have a single frame to press the spacebar before it is no longer possible to restart.

#

Considering I haven't seen the reason why you have that game variable, I can only suggest you remove it and the check in the if statement. The issue is then fixed.

eternal needle
burnt vapor
#

Indeed. Very little reason to have this, unless the right predicate has to evaluate something, even if the left predicate passes.

#

But you're right, I assumed this would not return the expected result.

vestal valve
# burnt vapor I'm not sure why you're saying "it worked" when it's a clear flaw in your if sta...

I said "it worked" since I could see "Retry" in console.
The update() function continuously runs code until the game stops, so the spacebar will work anytime.
The reason of "Game" variable is that to stop the infinite running of if statement.
Assuming u haven't, Just look at the image below mine.
I just transferred the statement "game = false" from outer to inner if statement.
And it worked perfectly fine.

burnt vapor
#

Yes, because the first if-statement no longer evaluates to false since you don't set game to false the first frame it's called, allowing you to check for the space key.

#

I still advice you to change & to && since I doubt you mean to use the former.

#

So it's fixed then?

vestal valve
#

yeah
I just used it since I'm learning.
Now I use only one if statement

tired gulch
#

Hello, Sir, how to not destroy an object when it hits something? Already tried other.tag != "Player", but it does not work 😦

fickle karma
#

Hello. What would you guys recommend to be the easiest method, when working multiple people on a unity project on different Pc's?

ivory bobcat
ivory bobcat
languid spire
honest haven
#

Im trying to get my player to return to its original pos after hammer attack https://gdl.space/aribehosob.cs my debus show this Moving from (1.94, 0.01, -1.78) towards (1.20, 0.01, -1.47) Finished Moving. Current position: (1.20, 0.01, -1.47) what can be stopping it from returning im lost

ivory bobcat
#

I'm guessing he doesn't move?

honest haven
#

He does move

tired gulch
ivory bobcat
ivory bobcat
honest haven
ivory bobcat
eternal falconBOT
#
Posting code

📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

honest haven
#

i just cant get him to go back to original pos seems to stop half way

fringe pollen
honest haven
honest haven
tawdry rock
#

If you have a prefab that you gonna instantiate to a empty gameobject, does the prefab XYZ transform / rotation matter? I guess it should not since the empty gobject has its trans/rot as well

spark ember
#

the camera wasn’t orthographic

tired gulch
fringe pollen
ivory bobcat
#
    private IEnumerator MoveTowardsPosition(Vector3 targetPos)
    {
        Debug.Log("Moving from " + player.position + " towards " + finalPos);
        while (Vector3.Distance(player.position, finalPos) > 0.1f)
        {
            player.position = Vector3.MoveTowards(player.position, targetPos, walkSpeed * Time.deltaTime);
            yield return null;
        }
        Debug.Log("Finished Moving. Current position: " + player.position);
    }```You're moving towards the delta and not a position where final position seems to be a delta but is being used as a position. Try this instead.
honest haven
#

thanks guys

fringe pollen
#

Oh my bad, looked at the wrong function

ivory bobcat
# tired gulch https://paste.ofcode.org/373edEuVa8zBQBypNEfieTn Hello Sir, I did what you told...
    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("Player"))
            return;
        if (other.CompareTag("Enemy"))
        {
            other.GetComponent<EnemyController>().DamageEnemy(damageToGive);
            //Not sure what you're trying to do here.
        }
        Debug.Log($"{name} was hit by {other.name} with a tag of {other.tag} and has been destroyed");
        Destroy(gameObject);
        Instantiate(impactEffect, transform.position, transform.rotation);
    }```
wheat cypress
#

Hello i'm trying to do a Pause menu, but for what ever reason when i press my key down, nothing happen, may i have some help about it please ?

ivory bobcat
tired gulch
ivory bobcat
#

The console log should have shown something if you hit something other than a player tagged object.

tired gulch
#

Oh, looks like it hit itself?

ivory bobcat
ivory bobcat
#

Update doesn't occur if the object isn't active.

wheat cypress
ivory bobcat
#
    void Start()
    {
        pauseMenu.SetActive(false);
  
    }
wheat cypress
#

AH

ivory bobcat
#

ie bullets shouldn't be able to hit other bullets - unless that's your game 😉

tired gulch
ivory bobcat
wheat cypress
ivory bobcat
#

Use the profiler when you finish your game, if optimization is a concern.

ivory bobcat
tawdry rock
#

I need some help how to spawn a prefab as a child to a specific gameobject.
Namely i want to spawn Can of Beef(prefab) to spawn on "spawn_loc_3"(empty gameobject) and be the child of "drawer" or the "spawn_loc_3" gameobject.

I made a GameObject refference to spawnLoc3 and dragged the spawn_loc_3 GO to it. Then i use this code to spawn my prefab:

Instantiate(canOfBeef,
            spawnLoc3.transform.position,
            Quaternion.Euler(spawnLoc3.transform.rotation.x, spawnLoc3.transform.rotation.y, spawnLoc3.transform.rotation.z),
            );

This spawn my prefab to spawnloc3 but it has no parent. If put a simple transform after quaternion then my Can prefab become a child to the "Drawer" not to the "drawer" (i should rename it Drawer root or something..)
I also tried something like Find("drawer") then transform.SetParent but im not sure if it using it correcly and also if i have multipe Drawers in my world how it will be able to find "drawer".

#

Also what i don't understand if my drawer has box collision at the sides and bottom and my can of beef prefab has rigidbody+ mesh collider with convex it stays perfectly in the drawer but when i move the drawer it falls out of it.

spark ember
ivory bobcat
tawdry rock
#

I want the Can be the child because when moving the drawer it falls out from it (idk why), besides i have perfectly made box collisions for the drawer, so im ok if the Can moves with the drawer with no physics applied to the Can. I will read uppon ur links and see if i can make something work, brb. 🙂

outer oxide
#

Hey, I need some help on making an object appearing or disappearing when its animated or not, I am doing a FPS animation which consists on the arms picking up a box, but I don't know how to make the box disappear at the end of the animation and when it is not animated at the start, I was told to use "SetActive()" but I don't know what the hole script will consist of, I also don't know how where does the script needs to be added, is it in the prefab or only in the object, I also don't know how can I tell the code if the animations playing or not, I tried using a bool parameter in the animator but I didn't got it to work. Some help will be deeply appreciated

ivory bobcat
ivory bobcat
outer oxide
#

yeah I want it to not be rendered not to disappear completely

#

but again, I dont know how to do this

ivory bobcat
#

You'd want to disable the objects renderer component

#

It should have one to be visible

outer oxide
#

And how can the script know when the animation is starting or ending?

ivory bobcat
outer oxide
#

I will try this thx

ivory bobcat
toxic cloak
#

why do my text get low res when setting the scene to free aspect

ivory bobcat
toxic cloak
#

Thanks for the help

slender nymph
#

also crossposting is against the server rules too

wintry robin
vestal valve
#

I could not see the text changing in the game but the console debug is working fine

slender nymph
#

you're destroying the object your coincount is stored on (assuming it isn't static). so every time you enter one of these triggers it increases the coin count from 0 to 1 (assuming nothing else is increasing it in this class) then assigning that 1 to the text

#

store your coin count on another object that isn't being destroyed and have that assign to the text object. also that if statement is 100% unnecessary

lean basin
#

Hello, I'm currently trying to move from Visual Studio to VSCode for mostly performance reason. In Visual Studio, I can do Ctrl+Click on a class and it will go to the script that has it. What is this operation called, is there a way to do the same with VSCode?

slender nymph
#

that's the Go To Definition. F12 should also do the same thing when you've clicked on a symbol and should work in both vs and vs code. though i do strongly recommend sticking with visual studio instead as its integration with unity is less likely to break

#

oh and it's also in the right click menu

keen dew
#

VSCode does the same thing with ctrl-click by default

#

If it doesn't, there's something wrong with the configuration

lean basin
#

It doesn't do that in my vscode. Also go to definition said, No definition found for 'ThisThing'.
I'm using Unity 2022, and have Unity extension in vscode installed.

slender nymph
#

welcome to using vs code with unity

#

you think it is properly configured because you've followed the steps. but something went wrong somewhere and it just doesn't work

lean basin
#

well, I'm not sure if it's properly configured or not. What I do know is, it doesn't work and I don't know why.

slender nymph
#

well you can try configuring it again and regenerate the project files. !IDE 👇

eternal falconBOT
#
💡 IDE Configuration

If your IDE is not autocompleting code
or underlining errors, please configure it:

Visual Studio (Installed via Unity Hub)
Visual Studio (Installed manually)

VS Code*
JetBrains Rider
Other/None

*VS Code's debugger plugin is unsupported.
We recommend using VS or Rider instead.

slender nymph
#

or you can switch back to visual studio which will offer a more robust experience and won't just randomly break

#

or at least is much less likely to randomly break

vestal valve
sage mirage
#

Hey, guys! I have a question. I have searched so many times in google what is an Instance but I still don't understand it clearly? When we write for example instance = this; what does this mean?? Can someone explain to me very carefully what is an instance?

slender nymph
#

that is assigning a variable named instance to the current instance of the object this code is running on.
this is part of how the singleton pattern is typically done in unity

queen adder
#
using UnityEditor;
using UnityEngine;

[ExecuteInEditMode]
public class DisconnectPrefab : MonoBehaviour
{
    void Update()
    {
        if (PrefabUtility.GetPrefabType(gameObject) == PrefabType.PrefabInstance)
            PrefabUtility.DisconnectPrefabInstance(this.gameObject);
        DestroyImmediate(this);
    }
}```
#

now i can keep changing something in my prefab without manually disconnecting it or worrying it will affect already existing prefabs UnityChanwow

main karma
#

hello, so I have these 2 functions

  private void Mover_OnContinue(object sender, System.EventArgs e)
    {
        transform.DOPlay();
    }

    private void Mover_OnPause(object sender, System.EventArgs e)
    {
        transform.DOPause();
    }

the functions work as intended, but the DOPause (dotween) is supposed to pause my tween, but when DOPlay happens, instead of resuming my tween it continues to stay paused until the tween ends and the next one starts, if anyone used Dotween before I would appreciate some help

tawdry rock
#

Im back. So i successfully managed spawning prefabs as child to another gameobject in my scene. UnityChanThumbsUp However there is a problem i was affraid of.
If i pull the first drawer out of the Drawer Root(the left drawer on the picture) the spawned loot on the second Drawer Root(right drawer on the pic) start to move as well.
And if i move the second Drawer Root's drawer it has no affect on the prefab it contains.

I used GameObject.Find("drawer").transform to set the parent when instantiating and as it looks like it only finds the first gameobject in the hierarchy that is called 'drawer'.
Any idea how to find Drawer Root's drawer and spawn my prefab there in a way that will work if i put bunch of Drawer Root prefabs in my scene?

slender nymph
tawdry rock
#

What i was thinking about is to make a list and put each gameobject the Root Drawer has into it so i would have a list from 0-3 then i could instantiate somehow according with it.. like if list index = 0 then set parent to that gameobject... is this dumb?

sage mirage
#

Hey, guys! I ve got an error here any help??

slender nymph
vestal valve
#

How to enable/disable gameobject?

slender nymph
#

SetActive

tawdry rock
#

I simply want to make this prefab called Drawer.
It has a script on it that will randomly choose a loot type(prefab) out of 3, then choose a random place to spawn in 8 different place and it also has a spawn count so each time i reload the scene the Drawer has randomized loot.
I managed to spawn the loot as child to drawers so they move with the drawer when its pulled out. It's all working.
The problem occur as i said when i put two Drawer prefab to my scene, because the Find method only finds the 'drawer' and populate it. So if you look the picture when i pull the left drawer top drawer that 2 loot comes out with it, but the loot on the right Drawer's top drawer moveing as well.
so i just want a simple solution when i instantiate the loot and set the parent it should set it individualy per Drawer prefab.

ivory bobcat
vestal valve
slender nymph
#

enabled is a property on components so it will only enable/disable that specific component. SetActive is a method on the GameObject to activate (or deactivate) the entire game object

ivory bobcat
#

Enabled is for components.
SetActive is for Game Objects.

sullen rock
#

is there a way to pause execution (= a breakpoint) every time a variable is changed?

slender nymph
#

use a property instead and set a breakpoint on the setter

#

otherwise you'd need to go through and set breakpoints at every location you assign to the variable

sullen rock
ivory bobcat
#

What is it? (the class)

sullen rock
#

a data entity that is serialized/deserealized from a JSON

slate bear
#

Hello everyone, I am looking for someone to work with me on a game I'm working on. As a first time game developer I am struggling with finding the motivation to keep going at a consistent rate when running into constant barriers of issues.
In any case, if anyone is interested in working together feel free to reach out 🙂
Alternatively I am also looking to just get better as a programmer overall and I am willing to join other people's projects as well.
I would like to grow and learn and doing that in a group (for me) is always better!

ivory bobcat
eternal falconBOT
tawdry rock
eternal falconBOT
#
Posting code

📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

ivory bobcat
#

A good advice is to:

#

Can be found in the pinned messages of this channel

ivory bobcat
tawdry rock
ivory bobcat
#

(I think you should use arrays though if you want to refactor the code for better design pattern and readability)

#

Other than that.. if it's this line:cs var position = spawnLoc3.transform.position; var rotation = spawnLoc3.transform.rotation; var parent = drawer1.transform; Instantiate(canOfBeef, position, rotation, parent);

tawdry rock
tawdry rock
oblique gazelle
#

jelli

#

hello

#

my weapon is too big

#

help me

#

wepaon is too big oon pickup

ashen ferry
oblique gazelle
#

weapon.transform.SetParent(hand.transform); //
weapon.transform.localPosition = Vector3.zero;
weapon.transform.localRotation = Quaternion.Euler(Vector3.zero);
weapon.transform.localScale = Vector3.one;
weapon.GetComponent<Rigidbody>().isKinematic = true;
/* weapon.GetComponent<Collider>().isTrigger = true;*/

#

here is the code

#

pls help

burnt vapor
oblique gazelle
#

no'?

burnt vapor
#

Advice you increase the scale

oblique gazelle
#

here is no pickup

#

it has a boxcolider

#

and rigidbody

#

pls help

burnt vapor
#

Please type your message in a single sentence

#

My point still stands. You can increase the scaling and make it smaller, or see what affects it to increase it so much.

#

The code is not explaining a whole lot...

oblique gazelle
#

My weapon is too large scale on pickup its not wokring to pickup it

ashen ferry
#

set localScale to knife scale / parent local scale

#

or try idk how scales work exactly lol

oblique gazelle
#

weapon.transform.SetParent(hand.transform); //
weapon.transform.localPosition = Vector3.zero;
weapon.transform.localRotation = Quaternion.Euler(Vector3.zero);
weapon.transform.localScale = Vector3.one;
weapon.GetComponent<Rigidbody>().isKinematic = true;
/* weapon.GetComponent<Collider>().isTrigger = true;*/

ivory bobcat
oblique gazelle
#

i have this

#

weapon.transform.SetParent(hand.transform); //
weapon.transform.localPosition = Vector3.zero;
weapon.transform.localRotation = Quaternion.Euler(Vector3.zero);
weapon.transform.localScale = Vector3.one;
weapon.GetComponent<Rigidbody>().isKinematic = true;
/* weapon.GetComponent<Collider>().isTrigger = true;*/

#

its not wokring good

rich adder
#

can u not spam the same code

ashen ferry
#

weapon.transform.localScale = weapon.transform.scale / hand.transform.localScale

rich adder
#

we get it

queen adder
rich adder
#

this dude is on sum

oblique gazelle
#

ok

#

but need help

#

i have struggelted 3 days

rich adder
#

you and everyone else

#

doesnt mean you have to obnoxious about it

queen adder
rich adder
#

/iamthemaincharacter

ashen ferry
#

how do u struggle 3 days with 5 lines of code tho

rich adder
#

its not the code probably. lack of understanding how scaling/parenting works

queen adder
#

Oh come on he spammed his issue in another 2 channels

rich adder
#

weapon.transform.localScale = Vector3.one;
this scales it according to parent scale, so parent is probably bad scaled

oblique gazelle
#

i this t´his

rich adder
#

parent it to something that is only 1/1/1 scale?

#

show scale size for hand

oblique gazelle
#

hand scale

#

anyone know the problem?

rich adder
#

what is scale of weapon when its parented to hand?

oblique gazelle
#

I havea child gun container

#

for the hand

#

here'

#

"gunContainer"

rich adder
oblique gazelle
#

this isi where the weapon should be

#

here

rich adder
oblique gazelle
#

yes

#

that true

#

now the problem is the scale is too big

rich adder
ashen ferry
#

just parent it in editor see how it changes gigabrain

oblique gazelle
#

did it

#

but not wokring

ashen ferry
#

if scale doesnt change then u dont change it in code

oblique gazelle
#

wdym

ashen ferry
#

actually now that I think abt it why do u change the scale lol

#

weapon.transform.localScale = Vector3.one; this part why u need that

oblique gazelle
#

yeah``?

ashen ferry
#

delete that line and try

oblique gazelle
#

whta

ashen ferry
#

aight bro nvm

oblique gazelle
#

remove that line?

#

lok

#

maybe wor,ing now

#

mayne working?

#

maybe

#

how to make the wepaon and everything aim at target?

tawdry rock
oblique gazelle
#

guys

#

how to make the aim work ?!?!!

uncut dune
#

guys my curser sprite is blurry what do I do

ivory bobcat
rich adder
uncut dune
#

its always blurry

drowsy blade
#

hi there, i have a really simple script, which tries to swap between avatars: ```public class AvatarSwitcher : MonoBehaviour
{
public Camera[] cameras;
public GameObject[] avatars;
private int currentCameraIndex = 0;
public GameObject[] rightHands;
public GameObject[] leftHands;

private void Start()
{

    for (int i = 0; i < cameras.Length -1; i++)
    {
        cameras[i].gameObject.SetActive(false);
        avatars[i].gameObject.SetActive(false);
        rightHands[i].gameObject.SetActive(false);
        leftHands[i].gameObject.SetActive(false);
    }

    cameras[0].gameObject.SetActive(true);
    avatars[0].gameObject.SetActive(true);
    rightHands[0].gameObject.SetActive(true);
    leftHands[0].gameObject.SetActive(true);
}

private void Update()
{
  
    if (Input.GetKeyDown(KeyCode.Tab))
    {
        Debug.Log("Kamera: "+ currentCameraIndex);
        cameras[currentCameraIndex].gameObject.SetActive(false);
        avatars[currentCameraIndex].gameObject.SetActive(false);
        rightHands[currentCameraIndex].gameObject.SetActive (false);
        leftHands[currentCameraIndex].gameObject.SetActive(false);

        currentCameraIndex = (currentCameraIndex + 1) % cameras.Length;

        cameras[currentCameraIndex].gameObject.SetActive(true);
        avatars[currentCameraIndex].gameObject.SetActive(true);
        rightHands[currentCameraIndex].gameObject.SetActive(true);
        leftHands[currentCameraIndex].gameObject.SetActive(true);

    }
}

}``` But when i try this script, the position of the hand controllers dont change (they are still on the first position) Im using XR Origin. Can someone help pls?

uncut dune
ivory bobcat
uncut dune
#

thank you

vestal valve
#

how to trigger a button using an input key(spacebar)?
I'm using mouse click.

drowsy blade
#

you mean on the console? yes, the camera index

sullen rock
#

I work with a different VR framework, so I'm not sure about this particular implication, but wouldn't simply moving the original avatar be easier?

rich adder
#

or you mean using spacebar to use button?

#

just link up the same method

vestal valve
rich adder
#

yeah probably

rich adder
ivory bobcat
# drowsy blade hi there, i have a really simple script, which tries to swap between avatars: ``...

What does it print: ```cs
private void Update()
{

    if (Input.GetKeyDown(KeyCode.Tab))
    {
        Debug.Log($"Kamera before:\nIndex: {currentCameraIndex},\nCamera:{cameras[currentCameraIndex].name}");
        cameras[currentCameraIndex].gameObject.SetActive(false);
        avatars[currentCameraIndex].gameObject.SetActive(false);
        rightHands[currentCameraIndex].gameObject.SetActive (false);
        leftHands[currentCameraIndex].gameObject.SetActive(false);

        currentCameraIndex = (currentCameraIndex + 1) % cameras.Length;
        Debug.Log($"Kamera after:\nIndex: {currentCameraIndex},\nCamera:{cameras[currentCameraIndex].name}");

        cameras[currentCameraIndex].gameObject.SetActive(true);
        avatars[currentCameraIndex].gameObject.SetActive(true);
        rightHands[currentCameraIndex].gameObject.SetActive(true);
        leftHands[currentCameraIndex].gameObject.SetActive(true);
    }
}```
oblique gazelle
#

I need help to make the player aim right in unity

drowsy blade
summer stump
vestal valve
oblique gazelle
#

hello my knife not aiming at the right target

#

only my hand

rich adder
sullen rock
oblique gazelle
drowsy blade
oblique gazelle
#

my weapon is not aiming in that direction of hand pls help

#

???

languid spire
#

<@&502884371011731486> Can someone please explain the rules of the server to @oblique gazelle Again

rich adder
#

they have

#

they just dont care because " i need help plz"

#

they have main character syndrome

ivory bobcat
oblique gazelle
#

anyone jump in voice to help me ??

vestal valve
rich adder
frosty hound
#

I honestly think they don't realize people are actually talking to them. Language thing? No idea.

summer stump
rich adder
#

well they can't follow basic instructions, explains why they're struggling

sullen rock
#

I'd like to help more, but it's tough without knowing the framework, I'd recommend #🥽┃virtual-reality if nobody here is able to help

rich adder
drowsy blade
vestal valve
drowsy blade
rich adder
#

where you can link method in inspector ?

#

wdym "implement the button"

ivory bobcat
sullen rock
#

It yes, enable/disable them directly

ivory bobcat
vestal valve
# rich adder wdym "implement the button"

When I click(using mouse) the button executes the function assigned to it.
Now I want the same but instead of using click(using mouse), I just need to hit spacebar(keyboard).
Yeah, I think yes, I might need another on click but it must be triggered by spacebar.

sullen rock
#

As in, what components

rich adder
drowsy blade
sullen rock
#

Okay, probably last question, we are getting there... do you want the avatars to be in the same place or no?

drowsy blade
#

hm, would be nice, but i guess it doesnt matter, i just want to show the differences between them

#

so right now my camera teleports to the corresponding position of the avatar if i use the script

sullen rock
#

In that case create 2 avatars and rig them to the same target gameobject and then, instead of enabling/disabling the camera and hands, just enable/disable the avatars themselves

#

I'd suggest adding a short "fader" just to make it look a little nicer, but that's extra and adds no functionality other than being prettier

drowsy blade
sullen rock
vestal valve
rich adder
#

or some other place where you can affectively poll for inputs

hushed hinge
#

I don't know what happened

vestal valve
polar acorn
sly lintel
#

best way to keep a third person camera from clipping into walls?

rich adder
polar acorn
#

If you're not using Cinemachine, use Cinemachine

sly lintel
#

What if its a first person camera in third person?

polar acorn
sly lintel
#

Think of how doom looks but instead of the character being on the UI its right in front

#

Trust, I'm doing it for the vibe

fringe pollen
vestal valve
summer stump
hushed hinge
clear steppe
#

why is newtonsoft not working ?

ivory bobcat
ivory bobcat
lost hinge
#

Hi everyone, I have an old project in which I tried to simulate different states (through an FSM) but sadly because of poor commenting I dont perfectly remember some steps I’ ve taken. Is there someone willing to help me fix some bugs?

ivory bobcat
eternal falconBOT
lost hinge
#

I dont really think we could call this a collab, but I get it! Thanks I’ ll try on the forum

outer oxide
#

Hey, Using a script and Animation Events I made an prefab disappear when its animation was not playing, I got it to work but now the animation won't start, I believe it is because the script for making the prefab disappear is present in a parent of the it but the script that launches the animation is in the prefab itself and that maybe causes a bug when the two got to start at the same time, I tested and saw that the animation was not starting at all in the Animator, is there any way to fix this?

summer stump
outer oxide
#

"Iphone" and "Iphoneprefab" got an animator but the purpose is different, "Iphone" is for setting Iphoneprefab to inactive while Iphoneprefab launches the animation

regal totem
#

Confused. Arn't I supposed to see a culling mask option on my lights? I've turned on show extra settings aswell.

summer stump
clear steppe
clear steppe
#

look i'm just tryna learn how to use newstonsoft

#

it doesn't seem that i have it

ivory bobcat
clear steppe
#

there's no tutorial explaining how to use newstonsoft

outer oxide
ivory bobcat
summer stump
outer oxide
summer stump
#

Otherwise it is bad for that

#

Disable the renderer for just making it invisible

outer oxide
#

gonna try this, thx

clear steppe
#

i just wanna how to set it up

#

and also that uh

#

jtoken thing

ivory bobcat
clear steppe
#

yo thanks man sadok

regal totem
#

@rich adder I've checked the HDRP Settings, Light Layers are enabled. I also to just to try did the 2nd part and did it manual on the camera to enable light layers. Still not seeing the culling mask. I'm still not seeing the additional Properties

#

It would be talking about the general section in the light inspector right?

regal totem
#

got it already =\

#

ohp

#

derp I found it.

rich adder
#

😅

regal totem
#

It was under the quality of hdrp

#

instead of of HDRP global settings

#

bastards tricked me

rich adder
#

which version of HDRP

#

maybe i sent older version of docs?

regal totem
#

would be for 2022.37 of unity I have

rich adder
#

ahh

#

HDRP @ 14

#

idk still says same spot when i switched it 🤷

oblique gazelle
#

Hello i need help to make the chacter shoot at target

regal totem
#

oh well 😛 ty kind sir

queen adder
#

are you trying to shoot with Raycast or projectile?

oblique gazelle
#

the body and whole character should rotate to aim direction

queen adder
queen adder
dusk minnow
#

It keeps telling me towerScript.impactTime is not set to an instance

polar acorn
dusk minnow
#

it isnt

slender nymph
polar acorn
#

That means there's no CannonTower component on this object or any of its parents

polar acorn
dusk minnow
#

it even logs

polar acorn
#

Try logging specifically towerScript

slender nymph
#

and share the !code correctly

eternal falconBOT
#
Posting code

📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

dusk minnow
polar acorn
slender nymph
#

and what is line 19 of MoveCannonBullet

dusk minnow
#

it is debuglog towerScript.impactTime

#

but there iam setting it then instantiating the bullet

slender nymph
#

would you look at that, towerScript is null

polar acorn
dusk minnow
#

towerscript

#

cannon tower

#

is not null

polar acorn
slender nymph
#

it's not null there. but it's null on other objects

polar acorn
#

Try printing it

#

see

#

There is 100% certainty that there exists a MoveCannonBullet for whom towerScript is null. This is not up for debate

dusk minnow
#

ok

slender nymph
#

add this line to the beginning of your Start method
Debug.Assert(towerScript != null, $"Oh look, boxfriend and digiholic were right! towerScript is null on {name}", gameObject);

ebon lark
#

use a debugger pls,

merry rapids
#

guys i found an .prefab file and i know nothing about unity how can i open this file?

slender nymph
polar acorn
#

It'll show that towerscript is null and which object it's null on

slender nymph
#

and you can even click the error message when it appears to have the object highlighted in the hierarchy

dusk minnow
#

so i have cannonTower and the script attached why is it null then

ebon lark
polar acorn
dusk minnow
polar acorn
#

The presence of one of these scripts with the value set doesn't mean that all of them are set

dusk minnow
#

why is it looking in the object itself

polar acorn
# dusk minnow

So, when you click on that error, it will highlight an object in the hierarchy. Does that object, or one of its parents, have a CannonTower

dusk minnow
#

ah ik the issue

#

thanks

tawdry rock
#

How performance heavy is shooting a ray in every frame thru update method?

polar acorn
slender nymph
#

also if you have performance concerns you should use the profiler

polar acorn
#

It's not free, if you can reduce your raycasts you should, but don't be afraid to have a whole bunch every frame

slender nymph
#

because it pretty much always Depends™️

summer stump
tawdry rock
#

Nice, i made a simple ray that check for collides that provides information to the player, for example press F to pick up or hold F and move mouse up/down.
the problem is if the ray collide with the loot, and the player pick it up and the ray is just shooting to thin air and doesnt collide with anything the UI doesnt get turned off (untill it finds something that has collison), how do i do that?
i tried something hit.collider.transform.tag == null but that didnt worked

summer stump
tawdry rock
#
RaycastHit hit;
Debug.DrawRay(Camera.main.transform.position, Camera.main.transform.forward * rayRange, Color.white, 2f);

Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit, rayRange);

if (hit.collider.transform.tag == "F Button")
{
    fButt.gameObject.SetActive(true);

}
else
{
    fButt.gameObject.SetActive(false);
}


if (hit.collider.transform.tag == "Mouse UI")
{
    mouseButt.gameObject.SetActive(true);

}
else
{
    mouseButt.gameObject.SetActive(false);
}
slender nymph
#

this is going to throw an NRE when the raycast hits nothing

summer stump
#

Raycast returns a bool. (True when collides, false when it doesn't) I would make it into an if statement, and put all the rest INSIDE that statement

slender nymph
#

use the Physics.Raycast call as the condition for an if statement, then put what you want to do when nothing is hit in the else block

summer stump
slender nymph
#

NullReferenceException. you know, that error in your console you've been ignoring 😉

tawdry rock
slender nymph
#

you should enable error pause, especially if you aren't seeing the console

ebon lark
#

you can use hit?.collider to avoid

slender nymph
#

if an error happens the game will pause so you can see what it is and view the state of your scene when it happens

dawn sparrow
#

I'm trying to get a reference to an equipment slot field on my character and set it to a new equipment object, but it's telling me this

slender nymph
dawn sparrow
summer stump
#

God typing code on a phone sucks

ebon lark
tawdry rock
slender nymph
# ebon lark good to know..always thought its an object

even if it were a reference type, using the null conditional operator with UnityEngine.Object types can result in errors because it doesn't use the overloaded equality operator which is how unity checks if an object has been destroyed. so it wouldn't be null but it could be destroyed which means you'd end up with a MissingReferenceException or some other similar exception when accessing any of its properties

#

always use the equality operator to check unity objects for null to avoid issues with that fake null

ebon lark
#

thx, just wanted to ask that

dawn sparrow
#

What does this mean? How do I get a reference to a field?

slender nymph
#

why are you using ref there? what are you actually trying to do?

dawn sparrow
#

I'm trying to get a reference to a field on a given character, so that I can set it to a new equipment

#

Should I be sending these with one of those code pastebin websites?

slender nymph
#

yes, large blocks of !code should always be sent in a bin site

eternal falconBOT
#
Posting code

📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

dawn sparrow
#

Gotcha, apologies

dawn sparrow
dawn sparrow
slender nymph
#

you also don't "reference" fields. it sounds like you should be passing the object that has the field and just assign to it through that. but you're being incredibly cryptic about what you are actually trying to achieve

#

there's technically the option of passing something by reference as a parameter to a method, but that's typically not what you want/need

dawn sparrow
#

I don't understand coding terminology fully so I'm not able to ask my question very effectively, sorry

slender nymph
#

why is this method static

dawn sparrow
#

It doesn't need any information from the an instance of the Toolbox class it's housed in to perform its function

ebon lark
#

is GameItem a strut?

dawn sparrow
#

GameItem is a class

slender nymph
#

so why do you have some other class handling assigning to fields on your CharacterManager class?

#

also a much easier way to handle this would be an array with a set number of slots using your EquipmentIndex enum as the index for that array

ebon lark
#

the first come in my mind is to use an inteface to do that

dawn sparrow
#

I use the Toolbox class as something to chuck all my helper functions in

slender nymph
#

this sounds like you are overengineering yourself into a corner

dawn sparrow
#

Maybe a Dictionary<enum, GameItem> ?

slender nymph
#

sure that would work just as well

#

it doesn't really enforce a set number of slots though. and if you're passing an int anyway you'd then have to cast to your enum

dawn sparrow
#

Yeah

#

I think I have a good idea for my second approach to this

slender nymph
#

but it still seems like you're way overengineering this stuff and also trying to force it to be functional rather than object oriented

dawn sparrow
#

I'll keep that in mind, thanks for the advice

lofty sequoia
#

Does Unity use either .NET framework or .NET runtime?

slender nymph
#

the current supported backends are .net framework 4.8 and .net standard 2.1

#

it also depends on the version of unity you are using though. for example 2020 supports .net standard 2.0 instead of 2.1

#

they are currently making an effort to switch over to the CoreCLR which should (hopefully) happen within the next year. and once they do that should give access to the latest .net versions

lofty sequoia
#

So having .NET framework or .NET runtime is essentially a prerequisite of using Unity?

slender nymph
#

yes. unity's scripting language is c# which is built on top of .net

lofty sequoia
#

gotcha, thank you

oblique gazelle
#

could anyone help me aim right at target=

slender nymph
#

what part about that are you unsure how to do?

polar acorn
oblique gazelle
#

pls help me rotae player to aim

slender nymph
#

you should consider reading the messages that were in direct response to your question. if you don't you're not going to get help

oblique gazelle
#

I mean i want to make the knife hitting the aim at center om game

summer stump
# oblique gazelle pls help me rotae player to aim

Bro, look at the message right above yours. And the one right below, and the ones I sent a long time ago, and the ones people keep sending.

GIVE US MORE INFO! Lmao.

The things you're saying are too vague to even be worth responding to

slender nymph
summer stump
#

Share code of what you've done maybe

oblique gazelle
#

this is my rotation

#

but its not working properly

slender nymph
#

!code
also define "not working properly"

eternal falconBOT
#
Posting code

📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

autumn cargo
#

so I made this to spawn a line between two points that I intend to make a bow string. The line does not appear between the gameobjects set in the inspector

#

checked layers on the camera

#

also checked to see if the cam was set to solid color

oblique gazelle
#

anyone could help me rotate the playre to aim direction?

#

pls

#

??

oblique gazelle
#

!code

eternal falconBOT
#
Posting code

📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

oblique gazelle
#

help me

slender nymph
#

holy shit dude

summer stump
oblique gazelle
#

The problem is to rotate player to aim target, with mouseposition?

#

Cant rotate the, body and hand or weapion in my game

slender nymph
#

i genuinely cannot tell if this person is trolling or not. i'm going to go ahead and assume they are and just block them

autumn cargo
#

perhaps language barrier ?\

oblique gazelle
#

do you want image picture of my problem

#

??

ivory bobcat
#

Which part is not working? Break the problem down.

#

Is mouse input not correct?

#

What part have you gotten to that's not what's expected?

#

Place some logs.

swift sedge
verbal dome
# oblique gazelle

What is the point of using Clamp with a range from 5 to 5? It's the same as just setting it to 5

oblique gazelle
#

wanna make my player aim to target

#

with guns

verbal dome
#

Also your x and y in the first Rotate seem flipped

oblique gazelle
#

wdym?

verbal dome
#

X mouse should rotate the Y axis

#

And vice versa

oblique gazelle
#

yes

#

but i have problem to do it

#

with all of the body

verbal dome
#

I just pointed out a couple of problems in your code 🤷‍♂️

oblique gazelle
#

wdym

#

i will show

limpid dawn
#

I need help

#

in photon

polar acorn
limpid dawn
#

but that chat is ded

ivory bobcat
polar acorn
ivory bobcat
oblique gazelle
#

how to make aim to mousepos unity

polar acorn
young smelt
#

Ok so I want to make a projectile barrage and have no idea how to get started with it. Projectiles should lauch from the player while making some initial curves before straight up lauching at the target

#

Let me send a picture

ivory bobcat
#

The arc and rapid barrage can be implemented later.

ebon lark
young smelt
ivory bobcat
young smelt
young smelt
ebon lark
#

if you dont need a per-projectile handler,maybe particle system can do the job

dusk musk
#

Hey everyone! Can someone help me getting my Enemy prefabs to face my Player? I already have them moving towards my Player, with the below script. I've tried all kinds of things for rotating, but no luck. I tried local.transform, and AddTorque to the Rigidbody, but no luck yet. Can someone help me? Here's also a video showing what currently happens, and my full script.

        Vector3 lookDirection = (player.transform.position - transform.position).normalized; //Moves the enemy towards the player
        enemyRb.AddForce(lookDirection * enemySpeed, ForceMode.Impulse); //Adds force to the enemy's Rigidbody

https://gdl.space/uhezetomap.cpp

young smelt
ebon lark
dusk musk