#💻┃code-beginner
1 messages · Page 3 of 1
🧑🏫 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/
iirc you Step Out when that happens
hey so any ideas as to where like the text box is? im trying to make it bigger but i still cant see it
15000+ to the right
ahh oops, thank you
is it possible to calculate the neccesary x and z rotations to rotate an object while taking into account a changing y rotation?
btw you should use TextMeshPro
The text component kinda sucks
TextMesh Pro is an easy-to-use system for high-quality text. It has many text appearance and formatting options, and is an easy way to add a professional touch to any project’s user interface. In this tutorial, you will learn to prepare fonts for use in TextMesh Pro, create new TextMesh Pro objects, and alter those objects.
its just like more text options?
it gives you crisp and clean text
thanks, it would be nice to be able to see the world space as well on the moved child object
i mean the one i saw on unity was like good i guess like
but il check it out thanks
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
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
Your IDE is giving you a hint, hover over it
Is your interface created somewhere in this project?
Yes
If you've got it contained in a namespace you'll need to include that too.
Yes, but I don't see the interface in this script, so you've got it somewhere else.
I'm new to unity, what do I have to do?
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
i show
And the first time I use raycast in the project
help me please
I'm still waiting for you to show your interface definition
Where did you make IShotHit
ok
I not make
Then why are you trying to use code that doesn't exist
Hello are their any videos/classes where I can learn unity for free?
!learn
🧑🏫 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/
can i exclude type printing in tostring
You can make your own toString that prints whatever you want
i dont know how regular tostring works
You can make a ToString function for any class and it'll print out whatever you tell it
!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.
Ahh I'm sorry
yeah use site. post link
also show inspector for object this script is on
All right a minute
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
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?
Yes it is. I have a script for character controller too. It still does the same. Want to see it?
if it also uses translate to move then its wrong 😛
ohh ok , did you try using that script instead with character controller
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.
Yes the result is the same.
static speed for move forward.
not sure what you mean here, it shouldn't be any different than what u do now
instead of translate you just use .Move
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.
yeah.
Collisions are pretty much physics
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.
you said you had a platform mid-air ?
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.
screenshot the collider when it stops mid air, turn on all gizmos
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
ok coul screenshot the transform GroundCheck spot
I have an enemy who shots projectiles, but they keep on going through the walls, how can I fix that?
you want collisions
this is the projectile's script
yeah but you pput size of 0.1f right ?
In the code yes
you could put trigger or put regular colliders (you can ignore collisions between player and background objects with collider)
then u ccould use OnCollisionEnter2D to destroy projectile
uhh I don't get what you mean
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
you can debug it .
put
inside OnDrawGizmos() method Put
Gizmos.DrawSphere(groundechk.position , 0.1f)
you need colliders
what colliders?
put a collider on the house if you want the bullet to hit it
no I meant these walls
same concept applies
uhh what is this.
what size did you put
0.1
and you put groundcheck.position?
These imported assets are rather small
well then thats how big your checksphere is
{
Gizmos.DrawSphere(groundCheck.position, 0.1f);
}```
that explains the gap i suppose
I' still confused how that would remove the projectile even if it wasn't tagged anything like wall
Hm
because you can use OnCollisionEnter2D to destroy it.
put a tag if you want
okay i made it smaller but now it sometimes go below the ground sometimes stays on it.
could it be related with collision detection?
I still don't know how to do that in the script
this is so confusing
I don't get what you're saying, I'm so confused
It's the same concept for how your character isn't falling through the ground if you think about it
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
maybe take a look at what OnCollisionEnter does
For what you got there, you must have some idea cause it's looking pretty good
what OnCollisionEnter?
I still don't know how
Well, read up on the usage of OnCollisionEnter. There's also Physics2D.OverlapCircle if you want to do it manually.
what OnCollisionEnter? where?
everything is so confusing, I don't know what I'm supposed to do
If someone gives you a name of something, and you don't know what it is, you first step should ALWAYS be researching it.
Edit: removed wrong link
Look at the example code here
Ah, you're 2d? One sec
Look at THIS example code
https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnCollisionEnter2D.html
I don't know what I'm supposed to do
Does the projectile have a collider
How did you even get this far without learning how colliders work ?
I mostly got help from teachers and tutorials
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.
You should learn the tools at your disposal before doing anything
I am not a expert and coding, I'm mostly used to designing
It’s a trigger so you can’t even use OnCollision method
Learning the components isn’t much to do with code
Anyway you already have an OnTrigger method so just add the walls to it ?
how?
I guess you can put them inside a tag to recognize you’re hitting walls
they are tag to ground
So you’re half way there
also how can I make that a projectile sees that it hits a wall
Tag check
You already have it work with player
It is EXACTLY the same, but with the Ground tag (or whatever you named it)
I don't know how
but
What is that video even showing? I didn't see a bullet, or am I missing it?
the green orb there is the projectile
Ok. It hasn't gone into the wall, so it won't trigger, right? Shouldn't it be moving?
Show the inspector for the bullet again, did you change it from istrigger?
Any other colliders on it?
Yeah trigger would not be colliding
no, just box collider
Hmm maybe the movement
Is the green sphere a child?
wut?
But I guess destroying the parent would destroy the child too, so nevermind
what am i supposed to do? I am so confused
Send projectile movement script again but from site
!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.
what do you mean Send projectile movement again but from site?
Read bot message above
i uses gld now, then what?
Save. Send link
https://gdl.space/hacusudufa.cs like this?
I don't know, My teacher made it, not me
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
what components? I don't understand
All these things here
#💻┃code-beginner message
Are components
There is a little arrow to minimize them on the left of the name
!learn
🧑🏫 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/
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
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
ok, I clicked all of. the arrows
so how do i make this animated sprite be infront of this to be seen
Sprite Renderers shouldn't be on a canvas
its my logo ☠️
Bro... stop cropping it...
For the third time
It shouldn't be a sprite renderer
what's cropping?
Not showing the whole image
then what should i use
Cutting the picture to only show part of it
Image
images arent animated
SpriteRenderers don't
no it works like this
it chagnes it so its smooth
this
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
A SpriteRenderer doesn't animate things automatically. Animators do
And animators can affect an Image as well
well i animated it lol
Yes, those look like Animators
Which is what does the animating
what do i use for my animated logo
If it's on a canvas it should be an Image
is it possible to make it change itself 12 timers a secound
Yes, literally the exact same way you are currently doing it
nothing changes
you still use an animator with a clip on it
Ok, no scripts that could cause it on there either...
I dunno. Triggers should not cause that behaviour
no triggers on it
There... is on the bullet, right?
yeah
I was gonna say put some Debug.Logs around to see what is happening
Whereever the movement is set, thats a good clue
And definitely do that course navarone suggested here
#💻┃code-beginner message
like this?
why does multiplying the capsules rotation with the white slopes rotation turn my player so far?
Inside the compre tag
well it aint moving
Does your animator animate the Image's Sprite
Bro i don't have a animated im solo
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
what
Brooo.. like I said earlier, if you don't know something, look it up. All the docs have example code. You didn't even put parenthases on it
And a million times this
#💻┃code-beginner message
i jsut put this in there and thats it
do i have to use another format or
So, does your animator change the sprite for your Image component
If your clip is specifically targeting a SpriteRenderer you will need to make one that changes the sprite of an Image
And stop posting this fucking image it has no bearing on anything and we've seen it already
Imma just ask chat gpt
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
any chance I can get some advice for this?
I'm assuming you want the capsule to rotate so it looks like it's standing on that. The easiest way you can do that is by setting the capsules transform.up to the hit.normal of the floor below it
I'm looking it up now
Not smart
ive got code that is working for this. I just can't figure out why it is over rotating so much. transform.DORotateQuaternion(slopeInfo.transform.rotation, 0.1f);This code works but it locks the player to the fixed game axis and I want the player to be able to spin freely
trying to add in the players rotation over rotates the capsule which makes no sense because it only has a y value
isnt it animated lol
What is that animating
Is that animating a sprite property on a sprite renderer
or a sprite property on an Image
idk do i have to manualy animate it or is there a tool in unity
Nice! That's it!
Now write this:
Debug.Log("Projectile hit: " + collision.gameObject.name);
That what you know WHAT it hit
That's going to set your object's entire rotation to the slopeInfo's over 0.1 seconds. If you keep calling this, it's going to keep overwriting the rotation
I have a conditional statement so it only runs once, it def works cuz I have debugging lines that are showing the correct things
this or is there another tool?
Super weird. Do what I said here
#💻┃code-beginner message
And then do one more video like that, but select the bullet, and have the box collider expanded and showing
You've made one animation already. Do the same thing but change an Image's Sprite property instead of a SpriteRenderer's
my main problem is that the player keeps getting initially reset to the world axis before I can look freely again so I'm trying to cut out that period so its seemless
how
...the same way you made the first one
change ur sprite renderer to an image component
You are cloning the projectile over and over again
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
infitive - ram glitch
which one
Which what
You don't. You make an animation that changes the Image's Sprite over time
So... is _objectToSpawn supposed to be a projectile?
I really should have noticed that earlier 
ohh i gotchu
I think so
I think no
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
my teacher made the script
Did he also drag in the projectile prefab to the field for you?
yeah
I really don't know what they were thinking. Maybe tired and made a mistake?
Probably not a real teacher
Probably some online course
Time to get a new teacher 😂
also my game gets lacky right now when there's like this what the debug.log is showing
I bet, with how many different objects it's getting the name for so quickly
Debugs aren't super performant
You want to remove them before bulding usually
Debug.Log is pretty slow yeah
But now we know the issue. You have a projectile in _objectToSpawn, and that's not what it should be
I do not wnat it to spawm like that right now
oh? that what should I do? remove _objectToSpawn?
You can just comment out lines 67 and 68 for now (the one where you instantiate and destroy the new object)
You can comment it out for now
I assume it's supposed to be a visual effect
comment it out? what does that mean?
Make the line a comment by adding // in front of the words
what does it mean by cant be non nullable value types, if it doesnt exist in the dict, wouldnt it be null?
TryGetValue returns a bool
use that
value types are never null
ah thx! didnt realize -- oops,
a betatester told me this
sounds like somthing to do with velocities not getting reset maybe? not a very clear bug report it seems ;-;
hmmmmm.... maybe I can ask chatgbt?
Yeah this report is badly worded, not sure whats going on
Floating makes me think, are you changing rigidbody gravity anywhere?
hmm... hard to say
Maybe show the player script with a site like you did earlier?
hmmmm...
Any youtube videos that you guys recommend to watch to learn unity? (not the !learn where it takes you to unity)
🧑🏫 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/
Why not the unity one? It is one of the best, if not THE best resource, other than direct tutoring or college
Just curious
I know that unity is probably the best way, but I’d like to see videos with different options you know?
I’d like to learn as much as possible and try to practice with what I’ve learned so far
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?
You cannot unsubscribe those lambdas as written
Either use real methods or save the lambdas in a variable to unsubscribe them later
Seems more convenient to just have the subscribed and not have to worry unsubscribing 🙂 thank u p... you always come in clutch
Fair enough. Makes sense
!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.
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
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
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
The restart function is not working.
I mean the if condition.
Any mistakes?
You set the game=false after game==true
Thanks 
any idea why the builds will not follow my mouse pointer as ive made it: https://pastebin.com/qGxESAgp
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
my game is 2d by the way
What do you mean by
the builds will not follow my mouse pointer
ive tried to make it so that the ghost build prefabs follow my mouse pointer'
instead of just staying in front of my playher
no
it just moves as I move my character around
it has snapping working but dosent follow my cursor at all
What does it do instead?
Does it follow a particular pattern? Like moves relative to the mouse but at an offset.
i’ll try and get a video
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.
I'm not downloading that.
ok lemme change format
Did you try this yet?
yes i tried that and it did the same as the video i just sent
execpt that one dosent have snapping
I don't understand the video.
Are they suppose to follow or be at the exact location?
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.
Your if statement has a bitshift, rather than a proper equality check. You need to change & to &&.
that ain't matter
cause it worked.
only the inner if statement was not running
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.
& would just evaluate both sides while && cuts short if one is false. Itd still function the same in the code but yea it should be && for sure
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.
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.
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?
yeah
I just used it since I'm learning.
Now I use only one if statement
Hello, Sir, how to not destroy an object when it hits something? Already tried other.tag != "Player", but it does not work 😦
Hello. What would you guys recommend to be the easiest method, when working multiple people on a unity project on different Pc's?
Use compare tag and do an early exit if the tag was player: cs OnTrigg.. if tag was player return if tag was enemy do stuff do everything else
Wrong channel #💻┃unity-talk (version control with github relative to programming)
Think about your logic.
atm you are saying Destroy this game object if it is NOT an Enemy or a Player
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
I'm guessing he doesn't move?
He does move
What is not working?
By "return", do you mean I just put return 0?
Does he move then teleport back?
That function has no return type so you'd just call return
Alright, thank you
If you posted it using the !code guidelines we could have shown you valid code rather than pseudo code if needed.
📃 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.
i just cant get him to go back to original pos seems to stop half way
That looks like it is working to me
im using move towards
not quite the same original position
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
fixed it
the camera wasn’t orthographic
https://paste.ofcode.org/373edEuVa8zBQBypNEfieTn
Hello Sir, I did what you told me to do, but it still doesnt work
Why do you have lerps inside of lerps? It seems to be moving linearly so can't you just lerp between startpos and targetpos?
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.
thanks guys
Oh my bad, looked at the wrong function
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);
}```
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 ?
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
Try a different key, the escape key causes the editor to lose focus in the Unity Editor
Thank you, but the result is the same, it's still not working 😦
Ok, i'll try !
Something else is your problem. Show us what printed.
The console log should have shown something if you hit something other than a player tagged object.
Still nothing sadly
Place some logs and see if anything really happens.
Is the script on the object?
Update doesn't occur if the object isn't active.
You deactivate it in Start
void Start()
{
pauseMenu.SetActive(false);
}
.
AH
You may want to consider modifying the collision matrix to allow certain objects of particular collider to not hit one another.
https://docs.unity3d.com/Manual/LayerBasedCollision.html
ie bullets shouldn't be able to hit other bullets - unless that's your game 😉
https://paste.ofcode.org/3a23AQ2tXdYyYKpQBZaWszn
It's working with this code, thank you for your help, but is this costly in performance side?
Don't worry about optimizations yet. There are a lot of roundabout things to increase performance here and there but they aren't important.
Ok ! Looks like it's working somehow with few problem but that's my matter, so i'll check what i can do on my side, thanks for the help !
Use the profiler when you finish your game, if optimization is a concern.
You might get a bit of scrutiny from others though, so maybe this should be considered:
https://docs.unity3d.com/ScriptReference/Component.CompareTag.html
Thank you
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.
What can I do to make these snap properly? I want to be able to build a simple box for example and this is what happens, the alignment is completely messed up
The code: https://pastebin.com/BB6twAPy
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
You can use the overload of Instantiate with the parent parameter: https://docs.unity3d.com/ScriptReference/Object.Instantiate.html else cache the instance and assign the parent cs var instance = Instantiate(...);Reminder that childing an object will have it at the parent location by default.
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. 🙂
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
If you want to constrain it to another object without childing, you can try the parent constraint component with the would avoid messing with scaling and whatnot. https://docs.unity3d.com/Manual/class-ParentConstraint.html
Should it just visibly disappear but still be there or completely removed? Set activate would sort of remove it whereas disabling the render component could just make it invisible. Depends on your needs.
yeah I want it to not be rendered not to disappear completely
but again, I dont know how to do this
You'd want to disable the objects renderer component
It should have one to be visible
And how can the script know when the animation is starting or ending?
Google would yield you results about firing coding when animation finishes
I will try this thx
You'd probably want to deactivate the box btw and not just make it invisible.
So set active as suggested using animation event https://docs.unity3d.com/ScriptReference/GameObject.SetActive.html
why do my text get low res when setting the scene to free aspect
Probably try asking in #💻┃unity-talk as this is the coding channel.
Thanks for the help
why not just continue in #archived-code-general ?
it's the same people there
also crossposting is against the server rules too
oh, so i remove here?
I could not see the text changing in the game but the console debug is working fine
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
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?
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
VSCode does the same thing with ctrl-click by default
If it doesn't, there's something wrong with the configuration
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.
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
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.
well you can try configuring it again and regenerate the project files. !IDE 👇
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.
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
Thanks
I used the same snippet on game object which is not destroyed and it went well.
I used if statement to check whether the statement is being run or not.(I removed it)
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?
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
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 
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
Im back. So i successfully managed spawning prefabs as child to another gameobject in my scene.
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?
the Find methods just give you the first object they find that matches the criteria. you'll want to get a reference in a better way
https://unity.huh.how/programming/references
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?
Hey, guys! I ve got an error here any help??
registering the instances when they are spawned or whatever to a list is a pretty common practice. though i'm not sure that i'm entirely following what you are trying to do
How to enable/disable gameobject?
SetActive
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.
Maybe avoid Find and reference the particular Drawer?
Thanks 
Before asking, I was messing with "enabled".
What is the difference between them?
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
Enabled is for components.
SetActive is for Game Objects.
is there a way to pause execution (= a breakpoint) every time a variable is changed?
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
thats the thing, Im looking for a place where my class instance is being reinstantiated, so finding those locations is my goal
Place a break point in the constructor of your non mono class
What is it? (the class)
a data entity that is serialized/deserealized from a JSON
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!
This server doesn't support !collab
We do not accept job or collab posts on discord.
Please use the forums:
• Commercial Job Seeking
• Commercial Job Offering
• Non Commercial Collaboration
i tried that. i made a public GameObject drawer1; refference then dragged the gameobject first drawer on it and in the code when i instantiate as parent GameObject.drawer1.transform gives a error: GameObject does not contain definition for drawer1
Can you provide the !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.
It'd make everyone's life easier 
https://paste.ofcode.org/C9DScNZKpPeZyMYrgnCKmT
ignore the void pork/fish, they are disabled and only beef can spawn, on else if (chooseSpawnLocation == 3) where i work with since spawn 1+2 is on the top of the drawer
Hmm, so which line is the problem?
(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);
Sure i just made a little learning project and i didnt tought much about design pattern and the project just started to growing on me as well as the code and im kinda lazy to refactor it.
That seems like its working and it was very informative as well. Thank you

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
Guess your weapon is like that with no scaling 🤷♂️
no'?
Advice you increase the scale
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...
My weapon is too large scale on pickup its not wokring to pickup it
set localScale to knife scale / parent local scale
or try idk how scales work exactly lol
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;*/
A refactoring with arrays and a struct for can food with text would look like this: https://paste.ofcode.org/D6YPuB9QjAQc72qgHWyVrr
There could be typos.. written on the web browser with no IDE. Edited..
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
can u not spam the same code
weapon.transform.localScale = weapon.transform.scale / hand.transform.localScale
we get it
Bro you spammed 3 times the same thing
this dude is on sum
I have been struggling with an inventory system for a month, bit I don't spam my code
/iamthemaincharacter
how do u struggle 3 days with 5 lines of code tho
its not the code probably. lack of understanding how scaling/parenting works
Oh come on he spammed his issue in another 2 channels
weapon.transform.localScale = Vector3.one;
this scales it according to parent scale, so parent is probably bad scaled
i this t´his
ok
how to do instead?
what is scale of weapon when its parented to hand?
show inspector for gunContainer
so is gun container what you selected as the hand transform
so whats the scale weapon
just parent it in editor see how it changes 
if scale doesnt change then u dont change it in code
wdym
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
yeah``?
delete that line and try
whta
aight bro nvm
remove that line?
lok
maybe wor,ing now
mayne working?
maybe
how to make the wepaon and everything aim at target?
Ohh, that might come handy in the future when i start coding more friendly way.. im just a 1 month old baby in coding 🙂 i will save it and try to learn from it 😄 once more thanks again, currently everything is working as intended.
guys my curser sprite is blurry what do I do
Is it related to code?
follow a tutorial
I tried adding it thru the project settings and thru script, now Im back to project settings cuz I cant figure it out
its always blurry
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?
what channel should I go to
When in doubt, try #💻┃unity-talk
They'll send you the right way or help you.
thank you
Does anything print?
how to trigger a button using an input key(spacebar)?
I'm using mouse click.
you mean on the console? yes, the camera index
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?
OnClick method can be subscribed to
or you mean using spacebar to use button?
just link up the same method
yeah
is it related to code?
yeah probably
which method on button do you want to call ?
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);
}
}```
I need help to make the player aim right in unity
hm, my problem is, i want to show different avatars with a simple click and thought to simply swith the cameras would work... but the controlls position dont swith with it, sadly, they are still on default
Stop repeating yourself. Give more info if you want an answer. And stop cross-posting...
oik
Restart()
seems you have it already nno? whats the issue?
If I understand this correctly, you mean showing avatar models rigged onto a VR camera rig of some sorts in a mirror (or something similar)?
nope, just a switch between them, the camera should move with it. the 2 avatars have different leg modeling and i want to switch between them to show the differences
<@&502884371011731486> Can someone please explain the rules of the server to @oblique gazelle Again
they have
they just dont care because " i need help plz"
they have main character syndrome
So it's activating properly. What's the issue?
anyone jump in voice to help me ??
That one belongs to old one where I didn't use button.
Just a text to tell how to to restart.
I just simply overwritten the code(I will delete the old one soon).
I wouldnt even if you paid me
I honestly think they don't realize people are actually talking to them. Language thing? No idea.
I said to do more info and they posted that picture. I think they thought that was enough?
well they can't follow basic instructions, explains why they're struggling
I've tried similar stuff when working with a different framework (oculus integration) and honestly, there was almost always a better solution, wouldn't simply changing the active avatar visuals be easier for you?
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
yeah but what exactly do you want to do then i dont understand that part, seems you have both methods
after the switch, the vr controlls of my left avatar are still on the right avatar, if i use them, they dont update the position
Forget everything.
I just need both on click and space bar to implement the button.
On click comes by default.
But not spacebar.
So how to include it.
that sounds way easier, but i dont know how to do that 😦 im still new
you want something like OnClick you mean?
where you can link method in inspector ?
wdym "implement the button"
Well you aren't doing anything other than deactivating and activating objects.
I'm not sure how activating should change position 
Maybe you ought to do something else like parent the objects to left and right hand?
Reminder: I haven't got a clue what any of the objects being activated are.
Can your setup rig 2 different avatars to the controllers at once?
It yes, enable/disable them directly
If anything maybe update the positions after activating 🤷♂️
Or childing the objects to hand or setting a parent constraint component to the particular hand if you aren't wanting it to scale (https://docs.unity3d.com/Manual/class-ParentConstraint.html) etc
hierarchy looks like this
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.
What is on the "head vr target" gameobject?
As in, what components
public UnityEvent MyMethod```
```cs
void Update()
{
if(Input.GetKeyDown(KeyCode.Spacebar)){
MyMethod?.Invoke; }
}```
something like this maybe
hm none, it was a empty gameObject which i put down in the ik follow target skript of my second avatar
Okay, probably last question, we are getting there... do you want the avatars to be in the same place or no?
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
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
ah ok, cool. Gonna try this, ty 🙂
Let me know how it goes!
An idea struck on my mind out of nowhere, and tried this on my own.
But that ended up I must do both clicking the button and hitting spacebar to restart the game.
I'm not used to unityevent(I literally have 0 knowledge on that), if thats the only solution I will try it.
thsi wont work unless restart()was inside update
or some other place where you can affectively poll for inputs
the way you had it here was good
#💻┃code-beginner message
I don't know what happened
I changed it back as u said. Now its working.
But this is an indirect approach since the spacebar doesn't trigger the button, but directly invokes the restart() function.
Anyways, the player doesn't know that.
It's nothing important. You've just got mixed line ending characters which means if you get errors the line numbers might not be fully accurate
best way to keep a third person camera from clipping into walls?
yes thats the way to do it, the only way you can link UI buttons OnClick with Keypresses from Keyboard / GamePad
using StandAlone Input Module
https://docs.unity3d.com/Packages/com.unity.ugui@1.0/manual/script-StandaloneInputModule.html
If you're using Cinemachine, you can set up special camera-only colliders that prevent it from moving past them
https://docs.unity3d.com/Packages/com.unity.cinemachine@2.3/manual/CinemachineCollider.html
If you're not using Cinemachine, use Cinemachine
What if its a first person camera in third person?
...what?
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
First person camera shouldn't clip into walls if player's camera is large enough
Thanks for help and advice
.
Problem is I don't understand a shit in that page.
I will learn them later
.
That's just first person still
I have a problem, when I run and attack, it keep on playing that animation but it stops when I stops moving or just walking, how can I fix that?
why is newtonsoft not working ?
If it's with animation, try #🏃┃animation
This is the coding channel
What does your top most error say?
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?
You'll need to break the problems down and tackle each one individually. If you get stuck, you can ask for help here if it's related to programming else there isn't any !collab here. The forums would probably give you more dedicated help with archived messages. Discord is more for fast paced minor discussions and help.
We do not accept job or collab posts on discord.
Please use the forums:
• Commercial Job Seeking
• Commercial Job Offering
• Non Commercial Collaboration
I dont really think we could call this a collab, but I get it! Thanks I’ ll try on the forum
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?
What do you mean disappear? Disable or Destroy? Destroy can take a time parameter, so you could delay the destruction. Or you could move the animation code to the parent.
There really isn't enough information to give a good answer.
Also, I am assuming you mean an instance of a .prefab, not the actual .prefab asset?
I am just making the instance of the prefab Inactive, both the prefab and the parent of the prefab have an animator, heres a screenshot which shows how it is layed out
"Iphone" and "Iphoneprefab" got an animator but the purpose is different, "Iphone" is for setting Iphoneprefab to inactive while Iphoneprefab launches the animation
Confused. Arn't I supposed to see a culling mask option on my lights? I've turned on show extra settings aswell.
There is an OnDisable method. Maybe call the animation in there?
I guess the question is, WHEN is the animation supposed to run. And what object is the animation affecting
wdym ?
Did you follow a tutorial?
what tutorial
there's no tutorial explaining how to use newstonsoft
the animation is supposed to run when the player interacts with an object, when they do it activates it for both animators then using a trigger in the code of the object that the player can interact with
Lookup: "newtonsoft unity tutorial"
Animations can't run on disabled objects, and code can't either. So I guess the next question is, why disable it?
You can disable the renderer if you want it invisible
to make it disappear, I was told here that set it to inactive was good for this
It is, if you want it to be invisible AND not do anything
Otherwise it is bad for that
Disable the renderer for just making it invisible
gonna try this, thx
i can't find a single good result
i just wanna how to set it up
and also that uh
jtoken thing
Random link: https://rehtse-studio.medium.com/made-with-unity-newtonsofts-json-net-b64236d59e76
Go to the "Getting Newtonsoft’s Json.NET Package On Unity" section.
yo thanks man 
@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?
should be the 3 dots on the light component
General section
😅
It was under the quality of hdrp
instead of of HDRP global settings
bastards tricked me
would be for 2022.37 of unity I have
Hello i need help to make the chacter shoot at target
oh well 😛 ty kind sir
whats the issue
are you trying to shoot with Raycast or projectile?
why should it?
can you show more info? like script, setup, hierarchy
It keeps telling me towerScript.impactTime is not set to an instance
Then towerScript is null
it isnt
if the issue is that towerScript.impactTime line then towerScript is null which means this object nor any of its parents have that component
That means there's no CannonTower component on this object or any of its parents
they do
Your error says otherwise
it even logs
Try logging specifically towerScript
show the full error including the stack trace
and share the !code correctly
📃 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.
What's line 19
and what is line 19 of MoveCannonBullet
it is debuglog towerScript.impactTime
but there iam setting it then instantiating the bullet
would you look at that, towerScript is null
Okay, so towerScript is null
look at the top
towerscript
cannon tower
is not null
It is
it's not null there. but it's null on other objects
Try printing it
see
There is 100% certainty that there exists a MoveCannonBullet for whom towerScript is null. This is not up for debate
ok
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);
use a debugger pls,
guys i found an .prefab file and i know nothing about unity how can i open this file?
i need help not a clown
wdym you "found" a prefab file?
That will help you
It'll show that towerscript is null and which object it's null on
and you can even click the error message when it appears to have the object highlighted in the hierarchy
so i have cannonTower and the script attached why is it null then
use the debugger my friend, it will tell you what is null
"There exists a MoveCannonBullet for whom towerScript is null" does not mean "Every MoveCannonBullet has a null towerScript"
The presence of one of these scripts with the value set doesn't mean that all of them are set
did
why is it looking in the object itself
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
How performance heavy is shooting a ray in every frame thru update method?
Not very. Raycasts don't actually "shoot" anything, they're basically just pure math, and computers are very good at pure math
also if you have performance concerns you should use the profiler
It's not free, if you can reduce your raycasts you should, but don't be afraid to have a whole bunch every frame
because it pretty much always Depends™️
For reference, my fps movement script I use 4 casts every frame. 3 rays in a tripod for ground checking and a spherecast for aim assist
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
Is the raycast in an if statement?
Just do an else and turn off the ui
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);
}
this is going to throw an NRE when the raycast hits nothing
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
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
what is a NRE?
NullReferenceException
NullReferenceException. you know, that error in your console you've been ignoring 😉
Ohh i was testing Maximized not on focus, didnt noticed the Console 😄
you should enable error pause, especially if you aren't seeing the console
you can use hit?.collider to avoid
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
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
the raycast hit is a struct so that won't work. and you should also not be using null conditional operators with unity objects so you shouldn't use that on hit.collider either
very good tip for debuging
I'm pretty sure I'm approaching this very wrong, but I'm trying to get a reference to a certain eqiupment slot parameter on my character so i can set it to whatever i want
I mean do this btw
RaycastHit hit;
Debug.DrawRay(Camera.main.transform.position, Camera.main.transform.forward * rayRange, Color.white, 2f);
if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit, rayRange))
{
// do checks
}
else
{
//turn off UI
}
God typing code on a phone sucks
good to know..always thought its an object
but i really appreciate it :3
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
thx, just wanted to ask that
What does this mean? How do I get a reference to a field?
why are you using ref there? what are you actually trying to do?
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?
yes, large blocks of !code should always be sent in a bin site
📃 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.
Gotcha, apologies
But yeah this is what my goal is
I'll read through it, thanks
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
Here's my full function, the switch at line 17 is what I'm trying to avoid
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
I don't understand coding terminology fully so I'm not able to ask my question very effectively, sorry
why is this method static
It doesn't need any information from the an instance of the Toolbox class it's housed in to perform its function
is GameItem a strut?
GameItem is a class
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
the first come in my mind is to use an inteface to do that
I use the Toolbox class as something to chuck all my helper functions in
this sounds like you are overengineering yourself into a corner
Would a dictionary work? I split it up into 6 seperate fields for readability purposes, so I wouldn't distinguish between the slots by index but rather actual names
Maybe a Dictionary<enum, GameItem> ?
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
but it still seems like you're way overengineering this stuff and also trying to force it to be functional rather than object oriented
I'll keep that in mind, thanks for the advice
Does Unity use either .NET framework or .NET runtime?
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
So having .NET framework or .NET runtime is essentially a prerequisite of using Unity?
yes. unity's scripting language is c# which is built on top of .net
gotcha, thank you
could anyone help me aim right at target=
what part about that are you unsure how to do?
It seems you've posted this question half a dozen times, but as soon as anyone asks any follow up questions you just vanish and ask again in another hour
pls help me rotae player to aim
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
Need help to aim at target
I mean i want to make the knife hitting the aim at center om game
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
reading comprehension is required too. just restating your question isn't providing any actual details about what specifically you need help with
Share code of what you've done maybe
!code
also define "not working properly"
📃 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.
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
!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.
help me
holy shit dude
"Define "not working properly""
The problem is to rotate player to aim target, with mouseposition?
Cant rotate the, body and hand or weapion in my game
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
perhaps language barrier ?\
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.
It seems as if your VS Code isn't configured properly.
What is the point of using Clamp with a range from 5 to 5? It's the same as just setting it to 5
Also your x and y in the first Rotate seem flipped
wdym?
I just pointed out a couple of problems in your code 🤷♂️
He told you about some issues:
Clamp: #💻┃code-beginner message
Rotate: #💻┃code-beginner message
Have you tried actually asking a question instead of just saying "I need help" and expecting people to just guess what your issues are
lol sry i will try
You definitely won't get help from that channel if you don't put effort. Here's a suggestion to get better responses https://dontasktoask.com/.
Ask in that channel, it's the correct location.
how to make aim to mousepos unity
Thx
Listen, you have got to continue one of the existing conversations instead of just abandoning it and asking the original question again
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
Break the problem down.
Your first question should be
I am trying to make a projectile [to] launch[..] at a target. I've Googled X and have tried Y but am stuck. This is my code where I am able to get Z working but am stuck with W. Does anyone see anything that could be a problem with this one line of code that I've narrowed it down to?
The arc and rapid barrage can be implemented later.
you can use physics to do that,randomize your projectiles initial speed and diretion,and set an attarctor at the target
I can't send my code because my PC is dead but what I've done so far is use perlin noise at the beginning.
Fix your PC first before trying to fix this. No code means theoretical talks which do not amount to much.
Actually I could settle on theoretical talk and just make more research then do it when the light comes on but I get ur point
I'll try that thanks. Could be better than perlin
if you dont need a per-projectile handler,maybe particle system can do the job
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
Oh, I nv thought of using particle system. I should look into both of these ideas thnks
tranform.forward = lookDirection
I will give that a try, thank you.