[SerializeField] private int _enemyHealth;
void Start(){
}
void Update(){
}
private void OnTriggerEnter2D(Collider2D other) {
if (other.CompareTag("PlayerBullet")){
PlayerBullet playerBullet = other.GetComponent<PlayerBullet>();
_enemyHealth -= playerBullet.PlayerBulletDamangeGetSet;
if (_enemyHealth <= 0){
Destroy(this.gameObject);
}
}
} ```
#💻┃code-beginner
1 messages · Page 455 of 1
Well, _enemyHealth is private. It is not static. You seem to only be modifying it on the actual instance and not a prefab....
I am not sure what the issue is
Nothing here should affect other objects
Yeah.. i just wanted to kill an enemy and the HP goes from 1 to 0, the enemy destroys and the other enemies are not affected. Now if I kill 1 all the other enemies also get 0 hp.
btw why send reply like "Got it thank you" from code sent, if you're not going to end up using the code sent lol
Not sure if I understand. But all good guys. Thank you for the help. Will figure it out here.
thanks for this - got it all working now! I'll make sure to put you and Navarone in the credits of my game 🙂
maybe you should make 2 variables
static for starting health
and non static for health of instance
nah was talking about
what you're doing is redundant from earlier
checking Tag and the component instead of just doing it all one 1 like above
I tried this, but was not working and I didnt want to push it further to not bother with same question over and over. I already have a lot of issues going on to fix, and if I applied this one it would just make it harder. As I applied and it said I couldnt use it the way you wrote. So i just went back again to what I was doing
wrong?
Very
😦
I mean issue was probably me missing doing other.collider. but you can inquire if it gave you issue, its no bother esp if I made the suggestion lol
I have so many questions, I try to simplify the most my enquiry. In the past I asked too much here and people blocked me saying I was not trying enough. So I always take care not to ask too much or insist. If I see that I am not udnerstanding or not being able to apply, I just leave it for now, fix the issues that I have and maybe try it later or not. But thank you.
its never a bother if you ask questions when you're confused, no worries
Got it, thank you.
Everything else you've shown doesn't seem to be the issue. But does your SpawnManager or the _enemyList handle destroying/removing any objects?
No, enemies are being destroyed anywhere but in the EnemyHealth.
im trying to use a movement system in 2d with rigidbody using addforce forcemode.force, but its really incosistent when i test it, almost like the values are changing every time... i tried looking online and people say its because its in Update(), but im not really sure what to do.
Do not use deltaTime in AddForce.
Just a guess
its not
And yeah, always do physics in FixedUpdate
when i tried to but the same functions in fixed update its not working
do i have to make the values stronger?
Define not working
Perhaps
ok let me test a bit
FixedUpdate will often happen a lot less often if the games fps is fast or just normal
It is called 50 times per second ideally (but can be changed in settings)
when i put in fixed update i had to make the values likes 10 times stronger than update
is that normal
That makes sense for the time-relevant force modes, I think...
Yeah, sounds normal
Depending on your framerate, yes.
dam so if someone else ran this, will they move at different speeds depending on their frame rate?
If you're continuously applying a force scaled by time, it'll be relative to the physics step. So if you're applying continuous force in Update(), then you're often accumulating multiple steps worth of force into a single physics update to greater effect
Exactly
Not anymore. Not in FixedUpdate
wait so it does or doesnt?
It does not
In Update it would. In FixedUpdate, it should be the same for different users
ahhh ok
DeltaTime is included in the AddForce calculations, so it really wouldn't in update either
But it is not stably called in Update
thx 👍
Update runs once per frame. Players at a higher framerate it would run faster for. FixedUpdate runs once every fixed frame (50 per second by default) so for every user it would try and stay consistent
AddForce uses deltaTime in its calculations internally, so even at different framerates it would run about the same. It would just not be as stable because it would not run at the cadence of PhysX/Box2Ds interal update
Ah neat
I guess this is true for general use then. I haven't looked at AddForce in Update as closely
im like 3 weeks into learning unity and i was feeling confidnet with what i was learning at the beginnign with the basic stuff but now im watching tutorials and it just feels like im copy pasting everything without being able to understand it and its kinda stressful anyone else gone thru a similar experience?
Fake it til you mak eit
if the tutorial does not take the time to actually explain what it is doing (and more importantly why it is doing that) then it is not a tutorial worth watching
Where do I learn code
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
Nvm
i am to
uhm okay no offense to any worker but are unity's web servers running on a potato?
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
this is really bad
I am sorry but
the videos don't load
the site itself doesn't load
i went through the exact same lol
If the destination point is not on baked nav meshes, Can it return a path which the last point is the closest point on nav meshes?
Suppose there is a square or circle obstacle and the target point is the center of the square/rectangle. It should find the path without needing a change in the stopping distance
yes, it will return a partial path
Perfect, thanks. and the path result is completed?
if (!_agent.isPathStale && _agent.pathStatus == NavMeshPathStatus.PathComplete)
{
if (_agent.remainingDistance > StoppingDistance + 0.01f)
{
PathStatus = PathStatus.Running;
}
else
{
PathStatus = PathStatus.Completed;
_agent.remainingDistance is based on the last point or target point?
because, in my test, it can return the path correctly
no, it will return PathPartial
https://docs.unity3d.com/ScriptReference/AI.NavMeshPathStatus.html
good question, I'm guessing target point
So, it does not work as I want
I should find the distance between the last point on the path (partial) and the closest point on the obstacle
Generally I just check remaining distance and/or isStopped
you can also check agent position against the last position in the path
I have checked, the last point on the path and also destination is not target point.
It is the closest point to the target point on baked nav meshes. Therefore, remaining distance is a distance from the current point to the destination point (last point on the path) not target point we have given to it
In the above example, the target point is the center of mass. Nav mesh agent returns path complete
See. The distance between the character point and target is around 1m but stopping distance is 0.05
yo uhm
can someone help me in a vc? I need to screenshare
or I can just send them a video
You can send the video here and someone can help if they want, no need to bait someone into a 1:1 call.
bait? my native language isn't english that is why I wanted to screen share I can't really explain what is going on-
but here a video
basically the player object is an empty object
and the capsule is the body basically which is underneath the player
IDK what is causing this
So i have a codeblock right here and i dont know if i understand it correctly, so its used for an inventory drag and drop system and im trying to understand the code, so image.raycasttarget, is that just to scan if ur dropping the item on one of the slots? and if it drops on one of the slots then he sets the parent of that item to the itemslot? and he also does an image,raycasttarget = true; to scan if u drop the item on a slot? is that right?
raycastTarget sets whether a UI element is visible to the event system's raycasters.
setting it true means it will receive and block UI events
false means it won't
the rigidbody is supposed to be on the parent object, not on one of its children. also like everyone else said you are using a character controller so dont use a rigidbody, you have to choose either rigidbody or character controller they do not like eachother
also rigidbodies dont like you setting the transform, thats why they have applyforce
Hey i kind of need help with unity and VS code. When i remove restricted work space most of my code turns blue.
so if u end the dragging in this case the UI events will be blocked and because of that he goes back to his traditional position? and when u begin dragging u'll tell it that UI events are possible? but why if i drag and drop on another slot the item is not attached to the new slot? is that because u set the transform.parent to his root? so it goes to the traditional slot?
When i turn on restricted mode. My c# and unity extention gets disabled
But code becomes normal
sounds like you need to configure your !ide
💡 IDE Configuration
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code
• JetBrains Rider
• Other/None
Can you elaborate maybe?
then how am I supposed to apply physics? its an empty object
if you put the rigidbody on it, the rigidbody comes with a collider
and physics
i do that for my player
so which one is better?
actually now that i look at it you seem fine, does the code function?
depending on your preference and what game you are making, you choose one, if your game requires physics use the build in rigidbody, if you want to make your own physics use character controller
character controller requires skill to make good physics but it is worth it due to the fact you can control anything via your script
rigidbody's interact fully with unitys physics system
yay now I need to re do my movement script
amazing
yippe
you said not to use transform on rigidbodies but can I rotate them with transform?
you know cuz the body should move with the camera
you should not move or rotate a Rigidbody via the Transform
only use the Rigidbody
i would suggest looking at a rigidbody movement tutorial
it goes over all of that
alright thanks
uhm one more question wouldn't setting the velocity be the same as addforce?
So im wondering, he is using inventoryitem in this code, is this the script called inventoryitem or is it the prefab that he uses? and he gets the inventoryitem component...
your assistance is heavily required 🙂
give me a minute im getting pinged left right and center
dw man, love you
yes but there is an other script called inventoryitem and then he uses inventoryitem in this script, or is it the prefab called inventoryitem he uses?
C# code doesn't know or care about obejcts in the project or the scene
it only knows about code
InventoryItem refers to the InventoryItem class.
Aah and then he gets the InventoryItem component wich is the actual InventoryItem prefab?
it's the instance of the InventoryItem script that is attached to whatever object the pointer is dragging
definitely not a prefab
either i would follow these series of tutorials and stop to where you want it
https://www.youtube.com/watch?v=f473C43s8nE&t=189s
or these series
https://www.youtube.com/watch?v=LqnPeqoJRFY
FIRST PERSON MOVEMENT in 10 MINUTES - Unity Tutorial
In this video I'm going to show you how to code full first person rigidbody movement. You can use this character controller as final movement for your game or build things like dashing, wallrunning or sliding on top of it.
If this tutorial has helped you in any way, I would really appreciate...
Part 1 of the Rigidbody FPS Controller (w/ Wall Running) tutorial series.
Thanks for watching!
In this video, I teach you how to create basic movement. By the end of the series, you will have fps movement + wallrunning
Rigidbody FPS Controller Tutorial #1 | Basic Movement in less than 4 min
(LINKS MENTIONED IN THE VIDEO)
FixedUpdate: https://...
ty
well, he gets that component wich is basically the item right? and then if u drop it on a slot he sets that components parent to that slot?
i guess its like that?
he's setting some field or property called parentAfterDrag
on the script instance of the dragged item
from the context of this screenshot alone I can't tell you any more than that
he gets that component wich is basically the item right
It's definitely a script which is meant to represent an item.
this is the inventoryitem script
so if i understand it correctly, this is just the dragging code and if u stop dragging then he will go back to his original parent, then the second script he made is when the item is dropped he checks if the slot is empty and if so he picks the inventoryitem component and then sets his parent to the new slot?
how difficult would it be to make a grid inventory system?
like this
items have different sizes instead of just taking up one inventory slot
not that difficult
uhm guys what is drag
each item just has a list of Vector2Int positions, and you just loop over allt hepositoons for overlap and bounds checks
nvm got it
then ig the acutal grid looking part would be more just asthetic and doesnt have to do anything with code?
ill just mark the min and max lengths and widths of the inventory so items can know where to show up lol
Well there would be a grid in your data model but yes of course, visuals are always just aesthetic and not in the code
allright thanks
hi there, i tried to program and would like to get some examples for code in visualstudio but i cant find the preference tab anywhere can anyone help me with this?
is this actually a good explanation for the code?
the problem is it isnt there
I still dont rly understand what the component InventoryItem is? is that these things?
the inspector shows all the components on a GameObject
you would see it in the inspector if you attached to that object
btw how do i get my visual studio to give me examples for code in can use? because its not rlly giving me any
Anyone know how I can make it so the camera rotates and goes up so the player can see something when going downhill?
My current camera code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Camera : MonoBehaviour
{
public GameObject Player;
private Vector3 offset;
// Start is called before the first frame update
void Start()
{
offset = transform.position - Player.transform.position;
}
// Update is called once per frame
void Update()
{
transform.position = Player.transform.position + offset;
}
private void OnTriggerEnter(Collider other)
{
}
}
Configure it
!ide
💡 IDE Configuration
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code
• JetBrains Rider
• Other/None
Learn to use cinemachine
Yeah... I tried that, but the results were... laughable it just didnt work with how I wanted the games camera to be
huh, but what does he acces with the getcomponent inventoryitem then?
the InventoryItem script instance on the hovered object
as mentioned
yes but how does he drop the item in the slot then? he sets the transform of the inventoryitemscript to the slot transform?
with this code
Is there really no other way?
If you're really interested in the details maybe don't watch a "speedrun" that skips over stuff
Of course there are other ways. Cinemachine is the easiest.
guys the problem ıs When ı press A and D character not turns same rotatıon Anyone know why?
Yeah for me that wasn't the case unfortunately. When I used cinemachine the camera would spin with the character because it's a ball and the freelook just didnt work
you are affecting scale
Yeah for me that wasn't the case unfortunately.
What makes you say this? It seems like you have no idea how to code what you want, so why would you say cinemachine wasn't easier. What are you comparing it to?
oh
in some tutorıals other people doıng that too
localScale thıng
I got the camera working way faster doing it the way I did without cinemachine that's why. And I do have an idea to code what I want to just not everything I want to. I started using unity like 5 days ago
thats probably for crouching
no ıt ıs not
scale has nothing to do with rotation
ohh ı mean rotatıon for just left and rıght
did you take any debugging steps for your code @sudden pilot
What makes you think it's not working
ah yeah now that i think about it if you set scale to a negative it will flip, not sure why you would want that though 🤔 well maybe for 2d it would be good
beats me
Yes but what you achieved is something very simple that could be accomplished with just a PositionConstraint. Doing more complex things will be easier with cinemachine
I mean I agree it's not the best way but it's not really the concern at the moment
horizontal ınput works and mathf.sign can take -1 and 1 numbers they have no problem But when ı change scale X ın ınspector when playmode on It change ıtself to 1
dont know why
well yeah your code is setting it
start debugging your code
Yes I know that, but still I don't know how to use cinemachine properly. I already used hours of my time a few days ago trying to make it work to no avail so I feel like trying to learn cinemachine now would just be a big waste of time.
you shouldnt give up learning something if it goes wrong
when pressing "D" key
okay, i almost understand all of the code, only thing i dont understand is why he sets the parentAfterDrag = transform, what does it do? position the item to the new slot transform?
when pressıng A key
and press nothıng
ıt says local scale X = -1 but
player not turns left
tf xd
keep in mind localscale if for children of a parent
i believe
and from your script you are applying forces on the parent im guessing
so change it to scale
but there ıs only 1 gameobject
not chıld or parent
that is a parent object technically, since you have no children under that object why would you use localscale?
https://docs.unity3d.com/ScriptReference/Transform-localScale.html
change it to scale not LocalScale
oh that ıs rıght ı wıll do ıt
im having an issue:
NullReferenceException: Object reference not set to an instance of an object
OnEnterMilk.OnTriggerEnter () (at Assets/scripts/OnEnterMilk.cs:16)
NullReferenceException: Object reference not set to an instance of an object
OnEnterMilk.OnTriggerEnter () (at Assets/scripts/OnEnterMilk.cs:22)
this is OnEnterMilk.cs
and Areas.cs
It doesn't do anything other than set the value of that field
Why you hide the line numbers 😭
Working without line numbers is like sociopath behavior
no i meant like in the screenshot lol
Well it's hard to tell which line things are on without line numbers
Pretty clear that areas is null
That's the only reference being dereferenced on those lines
ye but areas is a script and enemy is the same but it doesnt have an error
I don't know what that sentence means
But you need to assign the reference
Regardless of anything else going on
Because you assigned the enemy reference
You didn't assign the areas reference
Also wait how would you even know?
The error happens before the enemy line
oh
So enemy might not be set up either
So what?
mb thx
Can anyone just please help or no
it works thx, i thought scripts didnt needed to be assigned in editor
You need to assign your references, in some way, always. Not sure where you got that idea.
That or you need your code to check if it's assigned before using it
This is the idea of what you need to do, you'll have to adapt it to include your camera movement.
camera.transform.forward = Vector3.ProjectOnPlane(player.transform.forward, Vector3.up);
Thanks!
so it positions the item into the new slot?
Nope it just sets that field
It doesn't do anything else at all
The field is used later in OnEndDrag as you can see
hmm but what code is used to make the dragged item click into the slot u want it in?
Idk what you mean by click but it's hard for me to say having only seen very little of the code
Presumably something in OnEndDrag
so its an inventory system im making with drag and drop, i just dont understand wich block of codes make it position into the inventory slot?
for what is this code necessary?
its for dropping the item into the inventory slot right?
Okay and that code is linked with this
yes, and when u drop it where does it tell the item to position into the inventory slot?
In OnEndDrag right here
It sets the parent
I don't know the details but I assume these are UI elements and probably the positioning itself is just handled by the RectTransform settings on the thing
if i only use this code then if i drag it on a new slot than the item goes back to its original position and not to the new slot... so the second code somehow enables the item to be positioned into the item slot
wich i dont quite understand...
he does this inventoryItem.ParentAfterDrag = transform, so i guess its this that positions the item into the slot?
Nope
Again
It's literally just setting a field on the script
I don't know how many times that needs to be said
That field is used later
okay, but why is the code usefull then?
because without it it doesnt attack to the new item slot
its something to do with the parentafterdrop, first its = transform.parent and then on the second code he sets the parent to transform, doesnt that parent the item to the item slot? im rly trying to understand it
Because the OnDragEnd code uses the field that it sets
learning how to use structs, idk what im doing. trying to set the DistanceToPlr variable, and etc
foreach on a struct[] will return a COPY not the original
the monster[] is a list of all the monsters, and im trying to play a heartbeat sound if youre within the specific radius
Read what steve said again and consoder the implications
If you are working on a copy that does not affect the original, then it will not affect the item in the array
Hello, In a fps, what would be the best way to detect if a bullet fly close to a player, to later play a fly by sound. my bullet are actual mesh with a rb and I already tried to put a collider in trigger mode around the player, but it doesn't work because the bullets are going to fast.
yes indeed, and the field is first set to transform.parent and then to transform, whats the difference?
isnt transform.parent the original parent and transform is to a new parent
transform is its own transform
Not really sure why they do that instead of setting it to null, but I missed a lot of the conversation obviously
transform.parent is its CURRENT parent btw, not original
yes thats what i meant
No I saw that already
and then he sets the parent to transform
Well he set the FIELD to it. I don't see him set the parent to it
is it just checking where the item is dropped and then the transform of that item slot is his parent wich makes him attach?
so the parent after he dragged is set to transform.parent wich is his current parent but then he sets the parent to transform wich makes him attach to the item slot i think?
Why are you watching his speedrun video? It says watch the previous one for more details. I would stop watching this video
use references in the inspector
just tryna understand it lol
Exactly
i dont know how he attaches is...
Which is why you should not watch this video, and instead watch the one where he explains......
is the setparent to transform making the item attzch to the item slot?
He doesn't setparent to transform, he sets a FIELD to it. Just watch the video where he literally explains what he is doing and why......
Is GetKeyDown better than GetButtonDown?
Am I misunderstanding or don't they both just check for if you're holding down something?
they serve different purposes
oof
Button lets you assign your own "keyword" to specific key
eg "JumpKey" rather than Keycodes, some are already predefined
you'd have to do that inside the Input Manager https://docs.unity3d.com/Manual/class-InputManager.html
https://docs.unity3d.com/ScriptReference/Input.GetButton.html
yes i know that he sets that field to it, but to what parent is the item attached then? thats what i dont understand wich i have watched in his explaining video
Well, we cannot possibly know or answer that. Especially not from the tiny snippets you showed, which do not provide that information
ah so its more of just to rename it to fit mine
its so you can have custom names for specific button
okay thanks
like drag the player component you want inside a inpsector field for your enemy?
in that case just store the reference in the enemy spawner or whatever is IN the scene spawning enemies, and have that hold the reference to player and pass it on spawn
or make the player a singleton I suppose
im trying to somewhat abandon game tutorials and really just study the functions in documentation, specifically ones i see a lot
a lot of the times they fail to explain why do they do something, or just sort of gloss over it so i just eh
its rare I dont find it on the api or manual unless its a very recent / uncommon package
its been a bit of a process to find things but its pretty fortunate there are a lot of resources
pretty much i google anything else, most of the time you find the answers on the unity discussion
well, idk what line of code attaches it to a parent
:/
its ofcourse the setparent
wich is first transform.parent
but then he sets it to transform... wich i dont understand
Again. He does not set it to transform....
That is 1) a different script 2) a field unrelated to the one in the other script
he sets the dragparent to transform right?
He sets that field on the item (you are right, i misread) to the slot's transform
The item SHOULD be a child of the slot, right?
hey all im watching a beginner tutorial by codemonkey and for handling movement he uses a capsulecast, what i don't understand is why the capsule cast specifically, and how he landed on the numbers for the player radius & height. can anybody explain this to me.
if you have a question for a reference go to docs
they are your friend
also the Playerheight and Radius are just floats
i know, but how did he land on these numbers? what if i wanted to add my own model how would i get these numbers?
he just adjusted them in game then used the numbers
that he found
also you cant add your own model into a raycast
You should, 1000%, move those to serialized or public variables that you can adjust in the inspector
no i know but the capsule is meant to represent the player
i don't really need to these are practically constants he provided. i don't really have a reason to change them
its nice to have on the spot so you dont need to go back in script every time
but you do you
alright then thanks
i might be dumb but how is everyone having their functions with color like this
my code functions fine but everything just shows up white so its somewhat hard to differentiate things
you need to configure your !ide
💡 IDE Configuration
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code
• JetBrains Rider
• Other/None
thank you
i use an extension called viasfora
would this be a correct usage of Time.deltaTime, want to make sure as i watched a video but i was still slightly confused on it?
accelerationTime += Time.deltaTime;
float accelerationFactor = accelerationCurve.Evaluate(accelerationTime);
currentVelocity = Vector3.Lerp(currentVelocity, targetVelocity, accelerationFactor * Time.deltaTime);
time.deltatime is used is a wide variety of situations, mainly being in situations that you dont want to update all your code based off the framerate your game is currently at. quake is one of the games that didnt make the game update off a in game timer and instead made the game update off of what the current framerate was, thats why it was either really fast or really slow. always be sure to check docs out for a question like this!
here is the doc below
https://docs.unity3d.com/ScriptReference/Time-deltaTime.html
but in short, yes it looks to me for it to be correct
edit: I did not see the other time.deltatime, i am blind
nope, top one is okay though but lerp is wrong
https://unity.huh.how/lerp/wrong-lerp
yeah the curve part is fine
thanks this is awesome info 😄 just what i needed
i actually didnt even see that other time.deltatime
You will definitely want to make them serialized variables. This is one of the bad habits that Code Monkey teaches. Please do not fall into that trap
thats not what they're talking about. Their IDE is not configured.
But viasfora is pretty much useless now vs2022 now allows colored brackets/parenthesis
🤷♂️ i downloaded it as part of the tutorial
it wont let me install the package i might be doomed
plus it looks nice
it just says to unlock
and then when i go out of it and go back into it, its locked again
what says what ?
unlock? you mean package manager
ye
are you doing vscode or VS
yes
then that one
VS you dont need to unlock/remove anything
VScode is blue
was i suposed to be using vscode
huh? you can use either one
oh
visual studio is a bit easier to setup
no, they are mainly chose by preference
you only need the Unity Workload, then select it in external tools unity
I have just learnt abOut SerializeField, does it have any use other than for testing stuff as a dev?
its not for testing no
its a solid way of ensuring your references are set/filled
what does that mean?
its just for exposing the field that is private so you can Drag n Drop a reference inside
a reference is a specific object/component you're looking for
yeah i dont know what im supposed to do next
i changed the external script editor to VS and then went to package manager, but then it just says unlock
follow the link
there is nothing to do here for VS
you need to check for the Unity workload in the Visual Studio installer
for some reason my y fotation goes to -360 or smth like that https://www.toptal.com/developers/hastebin
Hastebin
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
you aint even send the code
oh sorry
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
//Monster looks at player
vel = monsterHead.transform.position - playerHead.transform.position;```
This is backwards too
the script is in the player not the monster
then the comment is wrong
i tried it backwards but it looks the other way
ooh yea srry bout that
Why sheep spawn but destroy instantly
Pastebin
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.
This video shows very little. At least show the inspector for a sheep
where do you put the sheep into gameManager.SelectedItemsList? because if it isn't in that list, it gets destroyed in CleanupInvalidSheep
keep in mind that the instantiated object is not equal to the prefab 😉
how
wdym how? they are completely different objects at that point
you and i are both people, that doesn't mean we are the same person
ok going through this again, it seems i cant individually affect these because they're tied to the engineering thing
seems i actually dont need most of the ones in there
i only need the visual studio one
why are you touching any of that..
I sent you the link on the instructions , follow them
well i was
each player? wdym by that I'm confused on your setup
but then when i get to the part about installing the unity editor thing, it doesnt really allow me any of those
"installing the unity editor thing"
where does it say that
i feel like my horrible way of phrasing is a problem let me clarify
did you check the unity workload ? that was the only important part..
yeah i clicked that one
and i think i already start with it?
it seems to download the entire engineering thing, which has 7 packages inside, including VS, VScode, and JetBrains Rider
ohh so if they are already part of the same environment doesnt that hold reference to the player in that environment ?
but I don't seem to be able to individually interact with those packages because it says it was installed as a dependency
clicked what
Game Development with Unity, in Visual Studio
Get rid of the engineering packag
Oh, thought it was vs code
I'm starting to think I already have those stuff
why do you need to interact with any packages.. all you gotta do is check the workload and set VS in external tools
i did :(
show that you set Visual Studio in External Tools
close VS, click regen project files, open script from unity
is the enemy not in the same enviroment? im not familiar with the ml agents workflow too much . I see #archived-machine-learning was archived
seems new channel is #1202574086115557446
THANK YOU
hard to explain for me seems there is limited knowledge there on how references work ?
well prefabs cannot reference scene objects, thats about it in terms of differences
so if you spawn it from a scene object, that usually has the reference you need from scene component, you can pass it on spawn
can your enemy spawner not reference the Player ?
if you have multiple players , a singleton is probably not a good fit
wait , does each environment have the player ?
you only need 1 environment with everything plugged in, once you duplicate that they all have their own instances
iirc yeah if they are training on the same model
you probably can do more than 25 depending on how much pc can handle
i haven't touched unity ml since 2020 so I may not have the up to date memory on it
Yes indeed (: so i was right?
I honestly have no idea what you were saying
That was my issue
It sounded like you were misunderstanding WHICH transform the word transform was referring to. It was referring to the slot.... which is what I said at the very very beginning
Quick question: Is there something like a SphereCast but that returns multiple RayCastHit variables or something similar? I forgot which function does that.
Preferrably an array of RayCastHits
SphereCastAll
You can look in the docs to find this stuff
Thanks mate
how can I take a gameobject and instantiate a new gameobject as its child?
Instantiate takes a parameter for the parent
oh thanks, i wish there was a way to see all the overloads in vs
aaah so the transform.parent is the current slot and the transform is to the new slot where u drag the item on?
they want this to be a Transform but the api says any object should work no?
Why would you Instantiate a new GameObject
Instantiate would be for a prefab
If you're just making a new object get rid of Instantiate
oh
Also read your error messages
Seems like it 🤷♂️
okay, thank u verry much!! appreciate it
does anyone know why I cant import a fbx object with textures to unity (the objects imports completely fine, but leaves the materials/texture behind)
cant even change the material
it's working much better now, had to do some changes in the code too, ty for the help
I've written this code from a tutorial for a basic car control. What should I improve, what better practices should I use?
public class WheelController : MonoBehaviour
{
[SerializeField] WheelCollider frontRight;
[SerializeField] WheelCollider frontLeft;
[SerializeField] WheelCollider rearRight;
[SerializeField] WheelCollider rearLeft;
[SerializeField] Transform frontRightTransform;
[SerializeField] Transform frontLeftTransform;
[SerializeField] Transform rearRightTransform;
[SerializeField] Transform rearLeftTransform;
public float acceleration = 1000f;
public float brakingForce = 750f;
public float maxTurnAngle = 15f;
private float currentAcceleration = 0f;
private float currentBrakeForce = 0f;
private float currentTurnAngle = 0f;
private void FixedUpdate(){
currentAcceleration = acceleration * Input.GetAxis("Vertical");
if (Input.GetKey(KeyCode.Space))
currentBrakeForce = brakingForce;
else
currentBrakeForce = 0f;
frontRight.motorTorque = currentAcceleration;
frontLeft.motorTorque = currentAcceleration;
frontRight.brakeTorque = currentBrakeForce;
frontLeft.brakeTorque = currentBrakeForce;
rearLeft.brakeTorque = currentBrakeForce;
rearLeft.brakeTorque = currentBrakeForce;
currentTurnAngle = maxTurnAngle * Input.GetAxis("Horizontal");
frontLeft.steerAngle = currentTurnAngle;
frontRight.steerAngle = currentTurnAngle;
UpdateWheel(frontRight, frontRightTransform);
UpdateWheel(frontLeft, frontLeftTransform);
UpdateWheel(rearRight, rearRightTransform);
UpdateWheel(rearLeft, rearLeftTransform);
}
void UpdateWheel(WheelCollider col, Transform trans) {
Vector3 position;
Quaternion rotation;
col.GetWorldPose(out position, out rotation);
trans.position = position;
trans.rotation = rotation;
}
}```
Why when I play my game in the editor my gpu spikes it 80% and even though I have the
{
QualitySettings.vSyncCount = 0;
Application.targetFrameRate = 60;
}```
running
Don't think vSync apploes to edit window, why you can only set it on game window in drop down
you could toggle the more intense items off from visibility in the heairchy perhaps to reduce GPU load
Make an enum for direction, a separate class for wheel which contains the motor, collider etc and store those in a dictionary
Well ok I just deleted the fishnet network manager and suddenly the GPU usage is fixed. Guess I have to talk with them
Maybe you have a tight while loop with excessive drawcalls in it? Sorry really not sure so just throwing out ideas on that
Damn I didn't understand a thing
Guess i gotta go learn c# now..
Usually a good thing to learn before Unity heh
C# is the absolute baseline to know before even touching Unity imo
Think of it this way, you have four wheels. They’re physically different objects but fundamentally the same type of ‘thing’. Each wheel has a transform, collider and some other fields. These wheels are organized by quadrant (front left, front right etc). Therefore it simply makes sense to describe the concept of a wheel as a class, with each actual wheel being an object of that class. Since we will be accessing the wheels by quadrant, it also makes sense to use a dictionary<direction, wheel> to store them
How you define Direction depends on your game. If every car has four wheels, then an enum is fine. If you want something more flexible, I’d personally define a record and place a vector in it describing the position of the wheel on the cars bounds
I'm trying to get the Normal point of a Navmesh sample position, however, it seems to be always returning "Up" Or in this case, 0.
if (NavMesh.SamplePosition(pointInBox, out hit, 1.0f, NavMesh.AllAreas)) {
float slopeAngle = Vector3.Angle(hit.normal, Vector3.up);
Debug.Log(slopeAngle);
Anyone happen to know why this might be happening?
float slopeAngle = Vector3.Angle(Vector3.up, hit.normal);
this should work
(i think)
Still 0.
For reference, Yellow dot is what is being hit, and, you can see it is on a slope.
"hit Holds the properties of the resulting location. The value of hit.normal is never computed. It is always (0,0,0)."
Hello all. I'm making a traditional roguelike and I currently have each enemy's Stat (an object with a StatType enum and an int, essentially) in a list of Stat objects. There are some issues with this, as you could have an enemy with two of a single stat type, which I would never want, and could also have enemies missing certain stats, which I would also never want. I would like it if when I drag the enemy component onto something, the component initializes with all the StatTypes in the Stat List that I would need and am unsure how I should approach this. Anyone have any ideas?
Perfect. Seems to work.
And for those curious, building out a debugger for some AI. Basically, Red means they can't shoot the player, yellow is a low priority location where they can shoot the player, and green being where I'd prefer them to be.
Sounds a bit confusing, have some code to show or inspector views?
you could have a StatTrack script on your enemy and when initialized in game you could access that script and take what you want from it
So GetKeyDown is for pressing it once and GetKey is for holding?
Check the Unity docs to read their description . . .
sometimes here just to clarify
docs clarify
i am not the sharpest tool. i struggled a bit to figure out the difference between button and key
The docs are absolute (rulers of the Unityverse) . . .
Yo I need help
lay down on the couch and start from hte beginning
Sure, here are my Stats and Stat classes. Stats is a component that any enemy or player character requires. Stat is a class that contains a StatType and int for the stat's level. The problem is, if I make a new enemy or player character, I have to manually access the statList via the inspector, and add a stat of each type which is prone to mistakes. Perhaps making each enemy initialize from a scriptable object is best for this?
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class Stat
{
public enum StatType
{
HEALTH, MAXHEALTH, STRENGTH, DEXTERITY, INTELLIGENCE, MELEEATK, RANGEDATK, STAMINA, MAXSTAMINA, STAMINAREGEN, MANA, MAXMANA, MANAREGEN,
}
public int statValue;
public int effectiveStatLvl;
public StatType statType;
public Stat(StatType type)
{
statType = type;
statValue = 1;
effectiveStatLvl = 1;
}
public Stat(StatType type, int lvl)
{
statType = type;
statValue = lvl;
effectiveStatLvl = lvl;
}
}```
Soo much help required so I was creating a game we'll fps multiplayer game it's all working fine but when I add sliding the code seems fine but when I slide it doesn't work animations is there lol so I leave it there then I tried to do like switching animator which basically like switch from player movement animations with no guns to animations with guns
Yea idk what I'm doing
then why are you making a networking game? that requires a massive amounts of experience
I'm making it to play lol and publish on steam
if its not good and buggy, nobody is going to want to play it. Start with an easier project
It's going to be good
and it wont be good because frankly, if you need to ask You're not ready
It is
its broken, clearly not
Beginner is not a channel to ask about networking issues #archived-networking
Or for this specificly, #🏃┃animation
But networking is a very advanced topic.
Oh wait dang this a beginner's
Create a constructor with a collection (array/list) parameter to pass in stats through code or a preconfigured list. You can also read from a ScriptableObject . . .
The thing is it's not bout networking or animation but code
Can you try restating your question a bit more clearly. Using more punctuation too (or ANY punctuation)
I ain't good at grammer but will try so the thing is its bout to switch from different animator controller to another oh wait it is bout animations. basic player movement to player movement with weapons like rifle idle or rifle walk
There is literally not a single period or comma in this...
It is like a stream of thought impossible to follow.
I have no clue what your problem is at this point. Something about... movement and animations?
I'll give an example so like GTA V the player movement walk, run and other but when player holds a gun it like switch animations rifle walk and other stuff.
U understand now I didn't use commas or stuff
Ok I see. I didn't realize things like Awake on ScriptableObjects are called only when the ScriptableObject is created and not while the game is running. Sweet :). Thanks
so you want to know how to make an idle, walking, running, and shooting animations for guns?
if so i would ask in #🏃┃animation
weapon switching?
or if you are holding a weapon, change movespeed to that weaponspeed?
How is this not animations? You want an animation for walking, and an animation for walking with a rifle, right?
do you want to change playermovement depending on what you are holding?
Yes
Yep
you can use an if statement with an enum or boolean to and make changes to your movement depending on what you are holding
parts.Add(Instantiate(smallCircle, targetPos, Quaternion.identity ));
What is wrong with this? parts is a list<Transform>, i dont get an error in the code, but in the editor, it says "Object reference not set to instance of an object" even though all the fields are filled in??
Ohhh i see
Explain
How could I make an object still be moveable but after letting go of said object it freezes in place? I'm trying to make a camera that I can place somewhere and it stays there when I can move it somewhere else when need in game.
@uncut trench This is..... an extremely basic issue then.... i recommend going through the learn course so you can have the foundation needed to actually solve these kind of basic things of your own
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
Our understanding is on another level
You could consider an FSM though, for different states the player can be in
But will do
I know, that is why I suggested learning
U mean playmaker right
thats
? No
he didnt even mention playmaker
True
if you are using playmaker i would suggest going to thier discord server
Couldn't you just disable the physics components when movement isn't needed?
and asking this question there
I don't use it lol
then why did you mention it
Idk
I don't really know how to. I kinda just have a rigid body component attached
Is there a specific support channel or is this it?
Every channel is (with a VERY few exceptions)
Well it's been pleasure talking even tho understanding is hard
depends on the problem
you could freeze the position of the rigidbody via contraints or setting it to kinematic
easiest way
Rigidbodies cannot be disabled, but they can be set to kinematic. Didn't see what was going on, just thought I would say that
I tried making in kinematic but all movement stops
make it kinematic when you want it to be
not always
Oh sorry, I misread your question. How is it moving right now? You might be controlling the movement through code, which could be overriding the physics engine. Is the rigidbody dynamic? Can you post your movement script?
My camera controller just isn't working in-game. Works how it's supposed to in scene but once I start up the game, it's stuck. I've been working on the problem for the past few days and can't seem to figure it out.
By stuck, I mean it's zoomed in on a tree and won't move.
This whole thing is being done in vr. I have a grabbable script on my object. gimmie a sec I'll get the script
we would need to see some code
inside the game you mean when you press play ?
So when you let go, set isKinematic to true
Yes
When picked up, set it to false
take a screenshot of the Console window when that happens
Is there a way I can specify this for a specific object and not the rest?
How can I do that?
im guessing you are using a package for vr so you can either make another script that references the grab script and just take what the object grabs and get the component on it.
it most definitely has a either private or public GameObject type in it for whatever object it is currently grabbing so use that when you want to get the rigidbody component from it.
if this doesnt help you, i would suggest !learn ing some basics
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
Of course. Referencing is one of the first things you should learn in unity.
https://unity.huh.how/references
And also see this
you got these loaded for situations like these 😂
add in some Debug.DrawRay()'s to verify rays are going where you think they are?
They are cause they play the sound that is given in HitTarget();
The Hit:ColliderName does work but the Debug.Log("Shot") doesnt
whats that?
your code editor
is that important?
so the object you check doesnt have that component
very much so
it does but it doesnt register it idk?
how do I do so sir
!vs
Visual Studio guide
If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
thanks
according to the code it doesnt
I dont get it, its on it
what's the difference between save and save project?
well then the object you're grabbing may not be the same as what ur looking at
Thats crazy
It wasnt working just because I was missing a Effect Decal that i deleted
how does that make any logic...
thanks for everything tho
are we supposed to know if pos is even correct 🤷♂️
Know how to fix this?
Cannot implicitly convert type 'UnityEngine.Rigidbody' to 'HurricaneVR.Framework.Core.HVRGrabbable'
nvm got it
how do i make it so Vector3.MoveTowards(); doesnt go all the way to whatever the target is and have a distance between each other so they arent pushing each other around
these are separate issues
oh, alright thank you
First, Vector3.MoveTowards already doesn't 'snap' to the target, it moves based on the maxDistanceDelta param
If it seems to be snapping to a position instantly, what's likely happening is you're applying it in update and not using Time.deltaTime, so the full step is being applied each frame rather than each second
oh okay, yeah i forgot Time.deltaTime
Hey could someone help me figure out why my code doesnt work, this is my first time using unity im following a youtube tutorial right now
For the 'pushing' issue, you should offset where you're trying to move to based on the bounds of the objects involved
Read the exception and then move your eyes slightly to the right
What does it say next to "Lol"?
And the exception says "UnassignedReferenceException: The variable Lol of blahblahblah" so yes
ill try that thank you
It's on the GameObject, but it's not set as Lol, so Lol is still null
you need to drag it into Lol, or grab it via GetComponent in BirdScript
The more you dig into this the more likely you're going to wind up needing to look into actual pathfinding
Not a problem, just a heads up to start looking in that direction if this comes up frequently
that sounds like a pain but ill need it in the future anyways, thank u for telling me
In all honesty its easier
So I drag "Rigid Body 2D " into None (RigidBody 2D)?
really? thats good to hear
A bit weird to get your head around at first, especially if you're not familiar with graphs
but once you have it implemented once it's very, very easy to work with
i suck with graphs 💔 ill try my best though
If you want to get started, I'd say go ahead and take a shot at making a flowfield based pathfinder
that's (imo) the most intuitive
whats flowfield?
It's a type of pathfinding that's best suited to reaching fixed points from anywhere. Essentially you create a graph where each node only flows to one other node
And you determine that 'flow' based on weights
a flowfield of gravity could look like this
ohh that sounds fun, ill try watching a tutorial to understand it
Much simpler than Djikstra or A* to get started imo, and very useful for any game with large numbers of units as the actual 'pathfinding' is O(1) for the agents
Yes
thank you
im looking at it right now, its cool thanks
in case it's handy, here's a basic implementation (you will almost certainly want to 'reverse' the flow so it goes towards lowest concentration/cost. My terrain costs are inverted from the usual so higher = cheaper)
that looks hard but ill try my best, thank you i appreciate it
Uhh idk if this belongs here, but I cannot find a way to configure the old input system for Mouse X and Mouse Y. Can anyone tell me what to do?
abstract classes are so nice bros
It gives me this error
ArgumentException: Input Axis MouseX is not setup.
To change the input settings use: Edit -> Settings -> Input
it's "Mouse X"
not "MouseX"
thx
Yeah I just saw it sorry :/
If I have a list of possible drops (GameObjects) and I want to check in each of them an specific component variable in order to know which of them should be instantiated them is it too much to do a foreach in which I do GetComponent ?
Anyone know why the forward goes from the Object Transform and not from the Transform attackPos???
Why don't you already know what's in each?
Think of your overall structure
Rather than worry about what GetComponent costs, I think you should consider why you've wound up in a situation where you want to use it in this way
How could we know without seeing code?
I sent a pic
Because I have this "DropComponent" which has Lists of GameObjects(Drops) depending on which tool or weapon was used to get them. These drops have ranks (S,A,B,C) and depending on the weapon rank the drop will be different. That is why I want to distinguish each drop by a OVERWORLD Item script which has the rank information. In order to check the rank should I create a foreach that checks each of the drops in the list if they have an specific rank?
its just a empty object in my Hierarchy
but it still goes forward from the Collider
sounds like you can just have a list of DropComponent. very rarely should you actually need a reference to GameObject
the dropcomponent contains the list
public class DropComponent : MonoBehaviour
{
public List<GameObject> FistDrops;
public List<GameObject> AxeDrops;
public List<GameObject> PickAxeDrops;
public List<GameObject> HammerDrops;
public List<GameObject> BladeDrops;
public List<GameObject> ShovelDrops;
Ok, show the attackPos object
Do not crop
I got it I need to change the pos and not the direction lol
Create a drop class and add the gameobject + rank information to that
Then still, apply what I said to these items. Reference the actual component you want
then store Dictionary<weapon, List<drop>>
I did it 😁
But I need to instantiate a GameObject anyway
Are there multiple instances of DropComponent?
You can instantiate from a reference to a component and itll spawn the whole thing
yes
And they're all different?
yes
alrighty, so this might be the one time in history I'm going to say just use a scriptable object
what do you mean? sorry I´m not getting it
It means just directly use the type of the component you want to use rather than GameObject. Whatever component that stores the rank
Okay, sorry for the confusion, now I get it
thanks, both of you!
I think there's a better way to organize this, let me just throw something together real quick
https://hatebin.com/stifdbqnba Here's how I would go about it
This way all the actual organization is handled upfront and fetching a drop is nice and quick
you'd have a single list in the Dropper editor and just drag and drop over some Drops from your assets, no need to worry about makign sure they wind up in the Axe list or the Sword list or whatever
Bro Can you help me? what does this mean
Well this is sure a nasty little thing if (Physics.Raycast(ray, out hit, groundedMask)) it happilly took groundedMask and turned it into maxDistance lol
It means it expects a semicolon at the end of that line
Don't ping specific people for help
It is a basic syntax error. All standalone statements need a semicolon to complete.
thank you
im sorry im new to unity
this is my first time making a game
he helped me before
my bad
That´s an interesting way to see it, I haven´t used dictionaries for now but I managed to understand what you were showing me
Have you done a pure c# course before? I always recommend this one
https://www.w3schools.com/cs/index.php
It will help a lot with the foundation you need
There are also pinned materials in this channel
My general rule of thumb with this sort of thing is that it's almost always better to organize data long before you actually need it, that way you can frontload all the processing. Players don't really care about an extra couple milliseconds when a game first starts, they will notice it if the frametime is inconsistent once they're actually playing though
I´ll keep that in mind whenever I try to organize data this way, thanks a lot for your help!
ty bro
!code
Posting code
📃 Large Code Blocks
Use 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 format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
we can wait dont worry man, take your time
Here is UI_Shop
https://hatebin.com/hcejoqyqwd
_closeButton.onClick.AddListener(CloseShop);
I believe
i dont see anything about a camera in this script, i think we would need to see the camera script then
please answer after your work so we can help you better
I need help with something, I'm making a 2d top-view car minigame, and I did all the mechanics, like the car moving, drifts and physics. But I don't know how I can make the car not be able to leave the track, right now it can go anywhere without problem, like can get out of the track. But I want to keep it inside the road. Not being able to go out.
you can add colliders at the edges of the track
to make sure the car cant go out
Figured it out. I tried colliders for like 5 hours. Found out the background had a box collider. That's why it was glitching
that will do it
Thank you
Anyone know why Target0 is being assigned for all these slots given the heirarchy?
GetComponentInParent<Transform> is equivalent to .transform
It searches itself before going up the hierarchy
why would it do this
It's convenient
For many things
Plus for Transforms those functions aren't that useful since you have.parent etc
ig, but they should have a separate method then
Probably
is the InvokeRepeating method a good way to do tickers?
instead of running stuff every frame
You should avoid InvokeRepeating always. Use Update, Coroutines, or Tasks
I have an AI pathfinding monster in my game and i have it able to walk up slopes so it changes the rotation of the monster to match the rotation of the stairs. But it stays rotated forever while walking around so how do i make it not rotate vertically at all?
btw just wondering bc google is extremely unhelpful, is there a way to mesh.RecalculateNormals(); but without normal smoothing?
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
I'm new to unity, and I wanted to learn visual scripting. does anyone know of a video tutorial on how to get something started.
Can someone look over my text and see if they have a fix to it?
should i learn some more oop before learning algorthims?
i havent been very focused with it
Might wanna ask in the visual scripting server
#763499475641172029
I do recommend just learning code though. It is arguably easier, or less arguably just as easy.
You should be completely comfortable with every basic feature of C# before moving onto algos and data structures
okay! i watched a video about flow field and how to make it and i was really confused when i tried understanding what was happening
that's a bit advanced if you're just learning OOP and basic C# . . .
yeah, I’m gonna work on getting better before trying something like that
Anyone got a quick fix for this?
Don't add force if it would cause it to exceed the max speed, and increase drag rapidly as speed exceeds maxspeed
How would I go about procederally making an ammo indicator in unity without having a different prefab for each gun type?
I don't know if there's a better way but I'd consider making a custom shader for the indicator and changing the bullet count with the material properties
this is really more of a UI question, but if you want something graphical you're just going to use the ammo represented as a percent, and if you want numbers just... get the numbers
im going graphical, but how then would I make the small grey things in between
ive never touched shaders, so im not thinking about going that route
did you look at any tutorials on how to do this?
i couldnt find any
but prov cause im searching the wrong thing
idk what its really called
Well, if you are not doing shaders, then making each bullet section out of one UI element and disabling/enabling them to change the bullet count might be an option
what about when a different gun has a different max bullets
thats the hard part
cause for a a gun with 4 max bullets, i have to make quarters
but for a gun with 5 max bulelts id have to make into fifths
and make them both occupy the same space
you most definitely wouldnt want each tiny bullet UI to be its own game object.
You could just go with an image and use the fill with like radial as the choice. I dont exactly remember what it was called
That would require masking the gaps out though
Whats hard about that? just placing an image on top to act as gaps would be sufficient
but then that'll be a ton of gmae objects
and id have to make more of them for smthing like a mahcine gun
where tehres a ton of bulelts
what im suggesting would literally be 2 objects
and really, you're gonna need custom stuff per gun no matter what you do. Unless you wanna go the shader route
Image with fill options should get you pretty far as well, the only custom part would be the images used above/below the filled image
I think that unfortunately using shaders would be the only plausable way to do the indicator dynamically change for any gun type without any extra work for each gun. Luckily I don't think it would be that hard of a shader to do though
can you elaborate on the fill options?
like what setting exactly?
these options
unity took a bit of time to open, and honestly i couldnt even find it on the docs
? It should be one
have a base polygon representing the shape of that guns bullets, and just draw it on a texture X times
What do you mean it would change the shape?
It'll take whatever shape you write it to take, you'd scale the individual bullets based on the number you want to fit, and I assume you'd probably alter the overall layout to match the type of weapon being displayed
No, not in the inspector, on the texture itself
whats the differencebetween raw image and image?
iirc raw image uses a texture rather than a sprite, hence being raw
Practically, different parts of unity expect different inputs. Technically, it's that a sprite encapsulates a texture and includes some extra information. It's very easy to generate sprites from textures and access textures from sprites
Regarding Raw Image, it has other uses but 99% of the time it's just there for render textures
If anyone is up and has any idea why my camera won't move, it'll be helpful. I've set up the inputs in unity, checked everything that my knowledge will let me, and well, no dice. The scene allows me to scroll perfectly fine, it's just once I press "play", it's zoomed into a tree and doesn't let me click, scroll, or do anything that resembles any kind of movement.
https://hastebin.com/share/vozawofaza.java
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
you're using touch inputs regardless of whether it's actually supported
Well it's going to be for mobile, should I disable touch inputs until I'm ready to release for mobile?
What's throwing me is that youre checking if touch supported is false, but then not actually respecting it so far as I can tell
Honestly, I'm not sure if this is just a thing with the new input system, but this entire thing seems hideously overcomplicated
That could just be me, but without any comments or documentation in there I cannot really follow what you're trying to do
Like you're initializing with about a dozen magic numbers, and some of them are readily apparent but others I can't make heads or tails of
Is it possible to hide a Canvas in the editor, but show/enable it when loading the scene?
I have tried "unchecking" it in the editor, and using this code:
canvas = GameObject.Find("Canvas");
canvas.GetComponent<Canvas>().enabled = true;
But it doesn't do what I want.
I also tried the following:
var objectCount = objects.Length;
Debug.Log("Found objects to activate: " + objectCount);
foreach (var obj in objects)
{
Debug.Log("Found an onbject to activate: " + obj);
obj.SetActive(true);
}```
But it didn't find all deactivated objects, I guess they arent loaded to the scene?
That method specifically states it doesn't grab inactive objects.
gotta read the tooltips
This is what I followed for camera control. https://youtu.be/kaU11fqe5yE?si=fbMCP5LdaYIPb-pr
Unsure if it helps clarify things. But the camera controller is similar to what you see in isometric games like Clash of Clans.
In this video tutorial series I will make a massively multiplayer online real-time strategy (MMORTS) game like clash of clans. I will be using a TCP networking solution that I have already published and also use MySQL database to store players data.
Discord:
https://discord.gg/FWwDgKjcKQ
GitHub Links:
https://github.com/developers-hub-org/unit...
Awesome, thanks!
What editor is this?
Rider
Thanks, gonna check it out. Tooltips looks awesome 🙂
that's not exclusive to rider. a properly configured IDE should show the code's XML comments. i know it works in Visual Studio. vs code may be iffy
you can find the same info in the online docu as well https://docs.unity3d.com/ScriptReference/GameObject.FindGameObjectsWithTag.html
@steel stirrup s method of just hiding the objects in the editor did the job perfect 😉
that was the other guy
honestly just log the inputs it's actually using, because I'm pretty sure they're not what you expect
how do I check the last value of a variable
cause i wanna do smthing the frame that the variable 'state" changes from air to walking
Cache it.
Use another variable!
so store it as another variable?
Yes
but thats a waste of a whole variable
There are a bunch of ways to do it, but if you just want to do 'something' on change, then make it a property and throw whatever you want to do in the setter
Well, how else do you expect to store it then?
alternatively, you could use a property that does whatever it is you want to do when its value is changed
Waste? That's a first for me
They're literally made to store values
can someone give me an example of a situation where you'd use Awake instead of Start?
ex
I'm reading the documentation and looking it up, and I'm kind of getting an idea of what its supposed to do, but I can't think of a situation of when I'd use anything except Start
As far as I understand, Awake runs at the start regardless if the script is active but I don't really understand why
and here I am wishing we also had a LateStart()
The only thing console is telling me is: https://i.gyazo.com/365db41276329ac9fb620729179c89ab.png which will be line 20 since i removed the namespace. https://hastebin.skyra.pw/waxololowu.csharp
For example, you have an object that instantiates other objects, and you need to reference these instantiated objects from a third object(your script). In this case you'd instantiate on awake and get the reference to the objects in start.
Because in awake there's no guarantee that they have been instantiated yet.
In general, don't try to debug when you have an unrelated exception, they tend to cause unpredictable and nonsensical behavior
Solve that before you try to fix your camera
The camera issue was happening before this, I just skipped the camera issue and figured I'd come back to it.
Yeah, and it's almost certainly unrelated, but exceptions can cause really, really bizarre behavior. Basically you can't trust that anything in your game is actually running correctly if you have exceptions popping up.

okay so
if im using something that the other scripts are going to need to use on Start, then i use Awake to do it first?
I'm getting no issues in VS so I'm really lost as to why it's telling me this.
is it missing a reference in the inspector?
IDE usually won't help with a null ref unless it's like HashSet whatever = null; whatever.add(x)
is there an attribute that tells "you can only have one of this type in a scene"?
AddListener should be yellow but for some reason, it's white. So I know it's not being read correctly, I just am not sure how to get it to read it correctly.
like [DisallowMultipleComponent] but for whole scene
I've never used VS, so 🤷🏻♀️
It's a matter of execution order. Start is guaranteed to run after awake, so if there's some initialization that needs to be done before your code, the initialization should be in awake, while your code that depends on it - in Start.
https://docs.unity3d.com/Manual/ExecutionOrder.html
No attribute, but there's a singleton pattern.
easiest way is to just have a static reference and register to it on Awake or OnEnable (depending on usecase), throwing an exception if its not null and not self
Is your !ide configured correctly?
💡 IDE Configuration
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code
• JetBrains Rider
• Other/None
#if UNITY_EDITOR
void Reset()
{
var pm = FindObjectsOfType<PanelManager>();
if(pm.Length > 1)
{
DestroyImmediate(this);
}
}
#endif```can have this, but not really fun to write each time
I mean the first question is why, right?
Why are you in a situation that this is actually an issue
You could make it into a static utility method or something.
This is putting a bandaid on a wound that shouldn't exist
also the least efficient way of doing that possible
If you really need to check, then just use a static reference so you aren't searching everywhere
I'll check right now, I just laid back down because I opened the Main UI script and saw the colors for SeralizeField disappeared and decided to lay down in defeat. Everything should be installed correctly but I'll go back and check again to make sure so I can rule that out
what you talking about, im using editor reset already, why would i need to put extra runtime load 
same approach works for editor, just have it run in editor and register
Well, you never specified that it should prevent the user from putting that script in the scene.
pretty sure this did
is there an attribute that tells "you can only have one of this type in a scene"?
Restricting a developer from placing things in a scene is just kind of a strange ask
Ok, my bad for misinterpreting the question.
This is the actual purpose of the singleton pattern. There is no attribute for that though.
The real question is the "attribute" part
Ive written dozens of singletons in my life
You can write your own if you really want to. Attributes are not magic. They're just some more code.
I want the quaternion rotation to basically be whatever it is of what I'm instantiating. How do I do that?
Like... I don't want to change the default orientation
If it's a child, Quaternion.identity, otherwise just copy the rotation
Use original.transform.rotation
It's a child to the canvas
Despite it being a child, as hyu said?
when you say you want it to be the rotation of 'whatever you're instantiating'
do you mean literally the one saved in the prefab?
Yes, exactly
you shouldn't need to do anything
That Rotation is always in world space
I shouldn't but apparently If I want to assign position AND have a parent of the object, then I also need to provide position
There's no overload that only needs position and parent transform
so just do them separately?
As in.. assign the position later?
you don't gain anything by using the overloads, it's just convenience
Like... instantiate with the [object, parent] overload. Then do object.transform.position = position; correct?
The overloads reduce the number of transform updates and recalculations of the hierarchy
Practically it really doesn't matter
Until you make a real game 🫨
Like this:
GameObject textInstance = Instantiate(randomTextPrefab, position, randomTextPrefab.transform.rotation,canvasTransform);
It's configured correctly
Yes, but mind that root prefab‘s transforms are not supposed to have pos/rot values that have any meaning, they aren’t saved and respected like other overrides. You can use them, they just aren’t great for workflow reasons.
Understandable. I'll keep that in mind 🫡
Is there any editor tool to have an icon on an object shown in editor? The object doesn't have a visual representation in the game, but it would help to see it clearly in the editor
you can draw a gizmo
This is even better, thanks a lot
a very dumb question but how to stop random animations from just playing on start
i tried disabling the animator but i feel there is a better solution
nvm did it
Ok, then take a screenshot of the issue in your ide.
hello all, this is my first time using unity on my own and i'm trying to make a flappy bird clone, anyways im trying to check if there's a pipe under the player. So I'm using this code csharp if(Physics.Raycast(transform.position, Vector3.down, out RaycastHit raycastHit, 2f, PipeLayerMask)) { Debug.Log("pipe?"); } however it's not logging anything, anyone have a clue why? this code is in the player class
if its not printing then its not hitting anything or you placed it in wrong spot
show your declaration and value for PipeLayerMask
any Idea, why I cant assign a gameObject to a Script on a Prefab?
because you cannot assign scene objects to prefabs
damn youre fast
It's a question we answer 100's times per day
ah, ok, then how do I get a reference of my player to a Prefab? It can be disabled at the time it searches for it, so find() doesnt work
yea but i only got to type 2 words lol
hold a reference in the script that instantiates the prefab and then pass it to the instantiated object
this is the relevant file https://hastebin.com/share/okiqoxotoj.csharp
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
as for the value its just a layer i made
ok, thx
Show you setup layers on the inspector of this script and the pipe object
but looking at your screenshot your cylinder is on the Default layer
yes but the parent is of the layer Pipe