#💻┃code-beginner
1 messages · Page 113 of 1
Wait lemme read the context because I have no idea what it's even suppose to do
bet
https://www.youtube.com/watch?v=2ysd9uWmUfo should be the code from this video, save me typing it all out i got the code from the comments haha
lets create a simple and easy head bob system for our fps games in unity3d.
in this part you will learn a basic one and for the next parts of this series we will have a much more advanced head bob dydtem.
#unity3d #fps
scripts are avaipable in discord server:
https://discord.gg/BzZMFvmdKW
_________________________...
when u stare at something soo long 😄
it has trig functions and I have no clue how trigonometry works because I haven't even finished school yet
😭
not at all
have you tried setting a breakpoint into the startheadbob function?
ion know what that means
or if you don't know about debugging yet try putting a print statement into StartHeadbob()
im still kinda a beginner
just add a new line inside the function and type "print("whatever here")"
i added it and nothing
did you save the script
yeah
Debug.log is better b/c u get context and console functionallity (click to view gameobject) etc
yes ik but he's still a newbie
then best to learn that debug is better than print 😉
good habits should be taught early
I thought he would learn that 100% later on but ok
but yea, print works too
Debug.Log should've been the first thing they learned
teach me your ways
Debug.Log(someVlaue)
basics
wha
soo did you try moving left/right with your keyboard when on play mode?
i tried every direction i could
why is the stopheadbob in the update loop right after startheadbob occurs?
it would stop it even if it ran
yup, that'll inform you when ur if statement is running true 👍
im not 100% sure, like i said i got the code from the comments to save me rewriting all the code
okay im getting my warning!
anything happening?
which means theres something wrong functionailty-wise right?
yupp
I think the StopHeadbob() call should not be in the update method
because it will literally stop the headbob right after you've invoked it
i removed it and still nothing
ok now try replacing CheckForHeadbobTrigger() with this
private void CheckForHeadbobTrigger()
{
float inputMagnitude = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")).magnitude;
bool isMoving = inputMagnitude > 0;
if (isMoving) StartHeadBob();
else StopHeadbob();
}
so now you can see, when the player is moving, it will start the head bob, and when it's the opposite it will stop it
oh and also is the script attached to your camera?
because it should be
ok and I assume PlayerCam has a Camera component
and that camera is the main camera of the scene
correct?
okay good
lemme send you a video
nah you don't have to
I don't know how I can explain the code that may work without your brain exploding lol
could you set the "amount" field on your script to a higher value?
hold on
you have a "MoveCamera" script?
it must also be accessing the camera then
ya
so there may be a conflict where both scripts are trying to modify the transform's properties at the same time
hello
and because they don't seem to have any communication between eachother, it will not work
so would i implement the code that im trying to use into my move camera code?
wait lemme rewatch
so your MoveCamera script is modifying the position of the cam holder
maybe delete the headbob script from the cam holder
and add it to the cam holder's next child
Player Cam?
yes exactly
still nuthin
so then MoveCamera modifies the transform on the holder and the bob modifies the other one
unless i make a new object
in which i put the cam holder in that
and use the code to move that
nah I don't think it's necessary
check if Player Cam's transform position is being modified
when you try moving
Hello, need help?
Nah, im fine
alr
as you can see the amount the position is being modified by is very tiny
that's gud what is it about?
change the [Range] attribute you have on top of the Amount variable to be something bigger
or just delete it entirely for clarity
I gtg sleep in like 5 minutes so let's hope we get this done in that time
okay its working
but its kinda wweird
great!
cause it feels like the character is slowing down each time it bobs?
oh yeah that doesn't look normal
the Z value isn't being changed so that isn't the issue
maybe it's just your eyes messing with you idk lol
dont you see it slowing my character down?
it can't be if it's not accessing the movement script
quick question
shoot
ask away
um how do we use destroy if we want to destroy the object where the script is
the bobbing is huge, I imagine it's just a perspective problem
On the same object: Destroy(gameObject) on a different object Destroy(other.gameObject)
also that ^
k thanks
okay guys i wanna make a very simple horror game, and i have a few basics down, i need to make a list so i can hold multiple items
is there a good place you guys can refer me to?
inventory system?
yeah
maybe be able to view the inventory system
but that comes later on
i just want fuinctionality first
yeah
let me find a video I used for this when working on a 3d game a while back
it teaches about SOs and layout groups and stuff like that
if anyone also knows of any good free low poly forest packs then im your man!
cool pixel effect
https://www.youtube.com/watch?v=oJAE6CbsQQA
this was that video I believe
🏗 @TamaraMakesGames building system video: https://youtu.be/G2w78Xk6UhU
🏞 FREE assets download: https://www.patreon.com/posts/72631393?s=yt
🎁 Support me and DOWNLOAD Unity project: https://www.patreon.com/posts/72632413?s=yt
This tutorial guide will show you how to create a full inventory system with draggable items, bottom toolbar, full inven...
thanks!
for me, just watching the video, even when fully focused was not enough to grasp the concepts, so you should google stuff when something is not completely clear
it's also 40 minutes long soo
it doesn't matter because there's only 2d ui, no 3d ui
2d and 3d games both have 2d ui
like in Minecraft for example, the ui is 2d
even tho it's 3d
tbf just thinking about it i can grasp the concept from previous knowledge
https://assetstore.unity.com/packages/3d/environments/landscapes/free-low-poly-nature-forest-205742
https://assetstore.unity.com/packages/3d/environments/landscapes/low-poly-simple-nature-pack-162153
https://assetstore.unity.com/packages/3d/environments/landscapes/low-poly-woods-232818
the three i use for prototyping
alr well you do you
also just realised I'm past my bedtime soo
time to say goodbye I guess
hopefully someone else helps you l8r
so i can create the image/UI then from that i can make it so that a button eg. esc can open this image, in which it also enables the scripts that gives the menu functionality?
yeah, that's pretty high level but could work
oh damn, im surprised i got that
u can use a gameobject to hold a scriptable obect as well.. with slots for everything like the image etc
and just change out the scriptable object.. each one having a different image, different functionallity, etc
also this video will teach you how to make a minecraft style system (where you can stack items, drag them around and stuff) so might not be the best system depending on your game
tbf i think i only plan on having classic horror game things, so a key, a crowbar or sumn, a flashlight
that sorta thing
wwhat?
then I don't think you need such a complex system for your game
is there a name for what im looking for?
a hotbar might be enough idk
do you expect a save / load system in your game later on?
i do
ohh ok
i honestly haven't seen a video for a system you're looking for so
maybe try looking for one yourself
but I'm going to bed soo tired
cya
cya! thanks so much for your help!!!
could someone please explain why I am getting this error on line 23 of my PatrolState script, Im new and have been trying to fix it for so long
Enemy or Agent are null/not referenced
Ur missing a reference to the enemy
What even is enemy in this scope?
Ah, from BaseState probably
It looks like it's from BaseState
A NullReferenceException occurs when you try to access a non-static member from a reference-typed object
mmmm words
Yes
it happens when you don't have a thing and try to use it anyway
Could someone dumb it down for me
So where do you assign the enemy variable?
enemy is null or enemy.Agent is null.
Did u copy and paste the code?
Where do you tell unity which enemy you want?
I'd guess agent is fine if it's actually on the same object as Enemy
Id be surprised if u knew about inheritance and statemachines but not NREs
the state machine is probably from a tutorial
It’s in the picture of the enemy script
At the top
Thats the patrol state
no, that second image has nothing to do with the enemy variable
that's the definition of Enemy
Ohh shit
you've defined the concept of an Enemy with that script
Its ok i figured u did that on accident
Its giving plankton eating that hologram burger on spongebob
even more abstract than that
I can when I get home
If you don't understand this, you should consider starting with something a little smaller.
So the problem is the enemy variable isn’t assigned
Yes pretty much
Prolly a good idea
Is the Enemy script on the same Gameobject as the PatrolState script?
No
A quick note. What you have is a Declaration of a variable. It points to a value called null right now (some things have a default value, but a reference type like a Class, which enemy is, points to null).
You want an Assignment. That means using the = sign, or dragging in something via the inspector. If you don't do one of those two things, but try to use the variable, the compiler will say "hey, you just gave me null, that isn't right. You promised me it would have a reference. This betrayal forces me to give you an error!"
a declaration says "I can store an X"
alas, having a box to put my hamburger in does not create one
Very good explanation
Thanks a lot
I’ll get back to y’all when I’m home and check it out more
time to manifest a hamburger
guys im trying to make a second canvas for my inventory, but its sticking to the 1st canvas i have ?
i cant resize the second canvas or anything?
ScreenSpaceOverlay?
That is expected by default. Screen Space cameras are fitted to your screen size
Not in that mode
Resize the things you put in the canvas
for example, this image is stuck to the bottom of its parent, covers 100% of the available width, and is 300 pixels tall
yeah but then its in the same place as my screen space one?
Yes, that's expected
dont i want them in seperate locations?
or do i just end up turning one off and the other on when i activate it?
the "Screen Space - Overlay" mode draws directly onto your screen
the canvas doesn't really have a meaningful position in the world
this is just how Unity decide to position it in the scene view
(it has to go somewhere)
You can do that, or change the mode.
You can even parent it to the other canvas
changing the mode sounds irrelevant here
Screen Space - Camera would be the same issue; it's automatically positioned in front of the camera
and World makes no sense for an inventory display
If you want to make the inventory appear on only part of the screen, you need to set up your UI elements accordingly
I was thinking world space. I use that for inventory sometimes
that would be an answer to Y
"how do I make the canvas smaller?"
but X is "how do I make an inventory window?"
also, this isn't a code problem at all
#📲┃ui-ux would be most relevant
im still extremely new to all of this so alot of this is kinda going over my head, so i do apologise haha
It's fine. UI took me a hot minute to figure out, haha
yeah im kinda tryna make it
are you trying to make UI display on Render Texture ?
i just thought positioning was a big thing?
You don't really position the canvas itself
You position stuff that's attached to the canvas
(unless you're doing world-space UI, where the UI is physically placed at a specific spot in the world)
noooooo
I'd give that page a read
as well as the subsequent "Basic Layout" page.
im following the first 2 mins of this video https://www.youtube.com/watch?v=-IPjFSWeyrg
so people can get abit of a grasp as to what im trying to achieve
An Inventory System that replicates Minecraft's, featuring equipment slots, switching items and basic movement.
Project Download ► https://github.com/ItsPogle/Minecraft-Like-Inventory-System-Unity
Discord ►► https://discord.gg/EevPKhxs34
Twitter ►► https://twitter.com/ItsPogle
Inventory Equipment Placeholder Art ► https://game-icons.net/
Inve...
I bet there are also some Unity Learn courses on UI
you didnt answer my basic question lol
what is problem? is the UI not showing on Render Texture
@rich adder
i havent got to that part yet haha
I am curious why there's a RenderTexture involved, yes
faking Low-Poly / pixel look
!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.
correct
makes level design a teensy bit easier on me too hahaha
isnt it showing this on your end ?
I meant more like, post your issue with relavent code not me exactly. I haven't made much car controllers, i mostly get one from Asset Store and just put my own mesh onit :
oh okay
also use links for code because this doesnt show on mobie
Oh right sorry, never knew that
guys how do i make an "empty transform"
you dont, you create an empty game object
Empty gameobject
every gameObject has a transform
and vice versa, but gameobject is kinda the whole container
Issue im having : Visual mesh of WheelColliders are flipping randomly on the Z axis
Source Code:
https://hastebin.com/share/ikicobilom.csharp
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
Update: The error resides in the conversion from Quat to V3 and vice-versa
a tip, use a parent container... that way u can rotate it (steer) left and right.. and u wont be fighting against the normal rotations of the tires
u can spin the tires within that extra container to keep the two rotations seperate
I fixed my actual problem simply by avoiding the infamous conversion i mentioned earlier
the problem really is in quaternion.eulerAngles
if (hit.normal.y < 0f) {
playerVelocity.y = Mathf.Min(playerVelocity.y, -1f);
Debug.Log("Hit Ciel " + hit.normal);
return;
}```
how exactly is it getting into this block if the y component is 0.00?
The Vector3 ToString only reports 2 digits, if you care about precision use .ToString("F7") or similar to get more digits
log hit.normal.y to find out what you're actually getting
I mean, what if it was 0.0000000025, -0.000000001, 1
You would never know with that debug
it shouldn't be, since its exported from hammer editor which you have to use a specific tool to even get anything which isn't grid aligned
Which is why you should probably have a less precise check
Every tool that uses floating points suffers from floating point innaccuracy
You can't even represent a value like 0.2 as a float accurately
I am at my limit with this stupid collider
why is it so hard to get VECTOR OF WALL I HIT
Draw the collision using Debug.DrawRay
guys im a little confused with this inventory tutorial
so im pretty sure i have everything in place
but i dont know how to actually make it so that an item is equipable and how to actually ADD it into my inventory?
I just wish there was a collider that could actually tell me the vector of the wall I hit
not some random vector that kind of relates
Well, with no screenshots of the setup and little debugging, nobody can help you
this doesn't even make any sense
was that for me i assume?
how???
Makes a lot of sense to me
its the same variable
that's -0.0000000476837
oh its really small
why can't I get the vector of the wall I actually hit though
its the stupid capsule shape the collider has, nothing makes sense because its using tangents or something
in the debug view the ray is displayed as expected
pointing down, despite the wall being vertical
I mean, ~0, 0, 1 sounds like a normal vector for a wall
yes but that's not the vector it's giving me
that's the vector of the wall, in the mesh
if I Looked at the vericies I guarentee you there is no y component do the normal
because it's a brush exported from hammer
There's barely a y component here, it's a floating point error
your logic just doesn't account for any error, which is not how to program this sort of logic
ok, yet, if I set the condition to hit.normal.y < -0.1f which is well within error it still doesn't work, gonna try it again
It shouldn't trigger when hitting the wall with a value like that
ok yeah it seems fine now. the log still seems weird but the movement itself seems correct
mostly
still seems a bit jittery when I jump against a wall
that might be fps tbh
I still need to find a way to figure out what wall I collided with though, this collider can collide with an edge without colliding with either surface which contains that edge
and so the normal is just compeltely unintuitive
but whatever ill do that later
nevermind this is definitely not fps
if I hold into the wall it's stuttery
but that might be an issue with my code and not collider nonsense again
hey man, sorry for the late response i´be trying to figure out the problem for the last two days and i only resolved today, the article you send was really helpful so thank you : )
hi guys, could you guys help walk me through this variable inventory system?
https://assetstore.unity.com/packages/tools/gui/variable-inventory-system-174157 this is the asset im trying to use
or if its uneccesary ill just use a plain one
would prbs be better tbf if i used a plain one
hi uhm, do you by chance know how i can reference my canvas object using code? im trying to set it so that when i press tab it opens the view
do people typically name the variable timeElapsed to simply 't'?
https://pastebin.com/BJaJJHsY this is the code im working with
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.
really simple but i dont know how to reference my canvas?
People that don't care about readability(bad people) do.
Drag it in
some wanna make it simple, smth that they will reconize
I will not recognize it the next week without reading through all the relevant code and understanding it.
I use t when I am about to plug that variable into a lerp
I do not use t when the variable is going to live for a long time
I want to see the variable name and know what it's for.
float t = Mathf.InverseLerp(lower, upper, amount);
float result = Mathf.Lerp(from, to, t);
It might be justifiable in this case👆
t is also more valid than elapsedTime if I'm counting up towards 1 from 0
public class Explodinator : MonoBehaviour {
public float duration;
[SerializeField] Renderer targetRenderer;
private float t;
void Update() {
t = Mathf.MoveTowards(t, 1, Time.deltaTime / duration);
targetRenderer.material.color = Color.Lerp(Color.green, Color.red, t);
if (t == 1) {
Debug.Log("Explodination time!");
Destroy(gameObject);
}
}
}
something like that
I don't use it in most other contexts
quick question if i add a event to the animation from the project files instead of it via clicking on my player does that change anything
because this is what i see
how do i have it set a bool to smth
how do i have it set it for that script though
and how do i reference the correct variable
video im watching has this
I've never seen that. Can you share the link of the video?
Ever wondered how games like Dark Souls give you frame perfect dodging, or Mortal Kombat gives you frame perfect combos? The answer is Animation Events! (Or it would be if those games were made in Unity)
Check out how you can make frame perfect timings for your games right here!
Join me and learn your way through the Unity Game Engine, the C# ...
Normally, it would call the function name specified function on all the scripts on the same object as the animator
well slight problem is the script would be on a parent object of the one with the animator lol but its animator reference is the correct one
Attacks/Methods/FinishAttack ( ) set that as the function ??
and what goes for object
an object parameter you can pass afaik
Then you'll need a proxy script
Ah, I guess animation events are a bit different for animations you made in unity and that's what you see in the video
do you have like a image of what it should look like
The event?
yeah like the paramaters
Just type the function name same as in your code and change whatever params you want to be passed in.
what if i have multiple functions with the same name
All of them will be called
You'd usually create a function specifically for the animation event
FinishAttack so thats good
like OnAttackAnimationEvent or something
public void FinishAttack()
{
canAttack = true;
}
for that one
FinishAttack
do you have the animation inside the animator controller?
so thats the problem because technically no
i use animation overides for my attack combo system
how works the getContact?
it gets the cotnact I guess. You'd need to provide some more details for a better answer.
oh, is that the differentiator?
I was wondering about that
Probably if you create an animation in unity tied to a specific object, it has a reference to it, so it can show available functions..? I don't know for sure. Just a guess.
Had a good look around the internet but couldn't find any guidance that worked.
I am trying to bake a navmesh at run time. If I do this manually everything works just fine. When I attempt to use "using UnityEngine.AI;" to create my mesh as per some tutorials, I'm faced with this.
Assets\Scripts\DungeonManager.cs(9,12): error CS0246: The type or namespace name 'NavMeshSurface' could not be found (are you missing a using directive or an assembly reference?)
The reason I'm baking at runtime is because Im procedurally generating a map at start.
I have the Unity AI Navigation package installed.
Here is an example of my script.
{
SpawnMobs();
if (navMeshSurface != null)
{
navMeshSurface.BuildNavMesh(); // Build the NavMesh
}
else
{
Debug.LogError("NavMeshSurface is not set.");
}
} ```
Any advice would be greatly appreciated.
that shouldn't be an issue.
that means that they arent in there
NavMeshSurface was added in the Navigation(I think?) package. When the navmesh was integrated in the engine, there was no such class afaik.
well it seems to be one because only the first one does it
Thank you for the reply.
I am using the NavMeshSurface component and baking manually from there works. If there is no such class do you know why I'd be getting this error?
Wait, so you are using the package?
I am.
Hi ! Today I'll be showing you a unity package allowing us to bake navmesh during runtime aka Playmode.
Package name : com.unity.ai.navigation
📄 Documentation : https://docs.unity3d.com/Packages/com.unity.ai.navigation@1.1/manual/index.html
🐦 Follow me on Twitter : https://twitter.com/thecodefriend
👪 Join the Discord server : https://www.disc...
Oh thank you!
I was using UnityEngine.AI; and tried UnityEngine.AI.Navigation; but it appears my second attempt was a mistake as it drops the "Engine".
This worked. Really appreciate the help.
You can always google the api, to see what namespace it belongs to:
https://docs.unity3d.com/Packages/com.unity.ai.navigation@1.0/api/Unity.AI.Navigation.NavMeshSurface.html
put both the AnimatorController and the AnimationClip in question inside the AnimatorOverrideController.
in the target GameObject, throw an Animator component on it AND your script containing the method(s) (functions) your targeting, then feed the Animator your AnimatorOverrideController.
with the GameObject select, head to the Animation tab, select the animation containing the event from the dropdown menu, and select the event.
now you should see the AnimationEvent window properly on the inspector.
I shall bookmark this, Thanks.
Don't lol. bookmark "google" if anything
you just need to google "unity API apiNameYouSearch".
this is what it looks like already
it just swaps the punching one with 3 different punch animations
more than often, an ALT + ENTER will find the correct namespace (not always though!)
in case you're using VS of course.
Is this a plugin? I'm using VS Code and that shortcut does nothing.
A quick google found Resharper?
Are you getting proper autocomplete and error highlighting?
None of that.
!vscode
poor thing...
to answer your question, no.
it's not a plugin, it's the built-in Quick Actions feature in Visual Studio (not the Code one)
but if I'm not mistaking, VS Code also provides such built-in utilities.
here's a list for VS Code.
Add missing usings / imports
I've got VS Code set up correctly and it's helping me now :D
Thanks @queen adder @north kiln .
How could I add a delay to instantiate an object?
👍
That's amazing! It takes everyone else hours to days to set up correctly. You're on the right track . . .
i have done that but it doesnt fire for the other 2
I'm by no mean an expert on AnimatorOverrideController nor have I found the need to use them before, can't really advise you on the topic any further.
update, cant figure out how to create a coroutine
you saw the examples ?
private IEnumerator WaitAndPrint(float waitTime)
{
yield return new WaitForSeconds(waitTime);
print("Coroutine ended: " + Time.time + " seconds");
}```
I thought another advantage of using coroutines is to avoid the update method...
I saw the examples, they just don't make much sense to me
which part exactly? most of it is pretty self describing
WaitForSeconds
I get the terms mostly, just utilizing them is confusing. If that maeks any sense
Can you provide a specific example?
call it with StartCoroutine(WaitAndPrint(2.0f)); // wait 2 secs
Like creating the coroutine,
What part exactly? They mention in the docs that you use StartCoroutine to start/create one.
MonoBehaviour.StartCoroutine returns a Coroutine
I guess I'm not getting how to actually use it within context.
Well, use it to delay the instantiation.
Wait, something just clicked.
yield return allows you to pause the coroutine for the specified amount of time.
which makes me wonder... what's the point of returning one?
would you know?
returning what?
a Coroutine
to stop it usually
To have a reference to the instance of the running coroutine.
I've figured it out. Thanks a ton.
I-... don't mind my question...
this sounds out of blue but anyone willing to help me out with my project? im running late on deadline. I will literally pay u and price is negotiable.
!collab
We do not accept job or collab posts on discord.
Please use the forums:
• Commercial Job Seeking
• Commercial Job Offering
• Non Commercial Collaboration
woah. thats cool
I would've loved to help you for free, except...
I'm not really a game dev, wouldn't be of use, only a burden on top of yours.
thats alright. thank you for the kind words tho
how would I change the color of the name text here?
RichText
<color="red"> sometext</color>
thanks that was easy
Helo does anyone know the code to like
Make a script wait for like 2 seconds
Then execute the next part of the script?
Coroutines with WaitForSeconds
Enemy's spawning in and going towards players spawn pos, instead of the players current pos.
Does wait for seconds only work in coroutines?
Yes
Nooo
please help with this issue
you havent shown code
There's also async await, but I'd be careful with it as a beginner.
We have no context to help you
{
public GameObject blood;
public GameObject player;
public float speed = 5;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
private void Update()
{
gameObject.transform.position = Vector2.MoveTowards(gameObject.transform.position, player.transform.position, speed * Time.deltaTime);
}```
If this object is moving towards what was the player's spawn position, then you've probably incorrectly assigned that object to player, instead of the actual player.
I'm spawning in the enemy prefab and that doesn't seem to let me assign the actual player.
only the player's prefab
Then the script that spawns the enemy should have a reference to the player
then it can be assigned from there
Oh it's mostly sad because I'm gonna have to reprogram some code in script A to turn a function into a coroutine then reprogram code in script B to call the coroutine rather than the function
But I see
Refactoring is a programmers routine. There's nothing to be sad about.
prefabs cannot reference scene objects, and having it reference the prefab directly wont be too useful. one simple way is just having some singleton which the enemies can use to access the player.
sounds like you just need to change like 3 lines
Yeah true but it takes time ah well
you could solve this by using singletons, or another way to find the proper reference to the player
singletons?
Don't bring singletons into this... There's nothing requiring a singleton here.😅
e.g.:
private void Update()
{
if (player == null) { player = FindObjectOfType<PlayerMovement>().transform; }
transform.position = Vector2.MoveTowards(transform.position, player.position, speed * Time.deltaTime);
}
from what I understand, their issue is that they can't reference the player object in the enemy's prefab -- what would you suggest instead?
True, tho it's like a thing where I'm making variations of a script tho maybe I should modularize it so I only have to do it once then just call the thing instead hm.
It's a bit weird to explain I guess. I'll figure something out
Just properly reference this from the inspector or with the manager that spawns the object.
I appreciate the thoughts tho
there isnt much room to suggest otherwise, given only the words enemy and player. A game manager holding a reference to the player would still require the game manager being a singleton or dragged in as a reference in scene, which is slightly more tedious to do
Whoever spawns the enemy should be given a reference of the player.
An spawner/manager object in the scene can pass in the required references to whatever it spawns.
They'd pass that reference to the enemy after spawning itcs var enemy = Instantiate(enemyPrefab); enemy.player = player;
Or if Player was a singleton type:
private void Update()
{
transform.position = Vector2.MoveTowards(transform.position, Player.instance.transform.position, speed * Time.deltaTime);
}
I mean, the game manager can be a singleton for sure, but it doesn't have to be in this context. You could get a reference to it via Find methods or even better, pass the references from whatever spawns these objects.
true for the last part, the Find methods isnt really a valid option imo though
I personally dislike both Find and assigning a reference from the manager, unless it's part of the game design
(e.g.: you want SOME enemies to target non-player objects sometimes, but want to keep it really simple)
Singleton isn't really an option for multiplayer games without introducing more complexity.
#💻┃code-beginner message
the example you gave directly used FindObjectOfType 🤔
idea is:
- if you're going for fully simple, singletons is the simplest choice
- if you're going for more than that, passing reference via manager won't be enough anyway, and you'll eventually need a FSM that deduces target
Lemme drop a little more confusion here for @lapis halo
Check this out
https://unity.huh.how/programming/references
Why wouldn't passing references be enough?🤔
singletons is the simplest choice
Opinionated. Passing a reference is the easiest method - you're going to instantiate the object and an extra single line does not hurt.
And what do you mean by FSM? Finite State Machine? What does it have to do with referencing an object?
in a multiplayer game, given the complexity, you probably want complex enemy logic -- vs just chasing a pre-determined object forever
This has nothing to do with assigning dependencies though.
Constructing and maintaining the aberration to provide global access of variables isn't easier.
we're exactly dealing with assigning dependencies xD your choice is to add a dependency of EnemySpawner to Enemy.target, therefore to Enemy
whereas in clean architecture the Enemy should be able to retrieve its target by itself (either its FSM, or a fixed static reference, if that's enough)
It depends. If we're talking about AI, there's a lot more involved. It might have sensors that would get the required references themselves. But that's a totally different story.
But what you said here has nothing to do with assigning dependencies.
#💻┃code-beginner message
It has to do with how to use those references and dependencies. A secondary topic
In my opinion, it's best to have patterns that are self contained where little to no outside calls are made.
that's a valid architecture choice as well -- as long as you follow through.
from my experience I found avoiding external dependencies to important variables allows for a more flexible design
like -- sry.. I mean avoiding direct assignments to those important variables from outside the class
Initialization and configuration from others who have reference to the instance is okay in my opinion. An instance accessing more than what's given to it would be a red flag for me.
It's definitely less of a hassle to directly have access to everything though.. (extreme: global/public everything)
This sounds great in theory but could end up with extreme complexity to make up for that loss of accessible references and ability to spaghettify.
e.g.: you could initialize with ITargetSolver, IMovementSolver, IAttackSolver instead of creating a new class for each combination.
..which is great but overkill in a lot of cases and would likely end up requiring multiple times the code, especially if solver code has more dependencies (e.g.: animator).
I love that pattern but haven't found much success pulling it through besides basic alterations without going for a full-pledged AI system.
(e.g.: basic aka configuring only AttackPatternSettings, EnemyStats, etc)
Guys can anyone give any good starting mobile game ideas
an Infinite Runner sounds like a good start
Like 3d good game except the runner ones
Okay..... What about a good AAA racing game?
But @grand badger can you help me by saying where to get good high poly models for free??
bro . . .
Okay
congrats, i am way more confused than when I asked
we are antimeme society
nooooo
remove that meme before the cops get you
where am i supposed to post funny unity memes now
somewhere else 
No 😛
You still need to know more than it. Otherwise it will feed you straight garbage.
not just because it's doing the work for me, but it's also explaining how the bits work
i know absolutely nothing about programming in C#
it's helpful for biginner stuffs, but can hinder your learning a lot. it can be a frustation when you at intermediate level already
good thing im a beginner then
you'll get there eventually
Been doin it for months i still dont know what im doing

yeah im hoping i can figure out most of the practical stuff with this game im making. then i can always just refer back to it and copy paste bits of old code to new programs like everyone else does!
i have this code
and when i take damage the fill amount just drops to zero?
my healt is still 95 and the print says its zero?
i have this cvode where the fillamount works dine
fine
where's the part that tells the code that damage was dealt?
integer division
the hecky is integer division
i usualy make my health floats so it make sense
meaning no decimals
you gotta cast one to float
yeah sorry my brain had a slow moment and i thought it was like a string sort of thing and the "/" was just a visual separator, but strings need ""
yeah making it float is working nw
i feel like a neanderthal trying to understand why it's health divided by max health
fill amount has to be 0 to 1 . so 95/100 is 0.95
health is 95 and max health is 100
and if you dividehealth when its full or 100 to max health which is 100 you will get 1 so the fill amount if full
ooohhhhhhhh
don't make it float, just cast it to float 😄
difference?
health makes sense to be an integer
thanks for explaining that, makes so much more sense
semantics, mostly
if you don't want floating numbers in the UI, int makes more sense
so like what is casting? just turning it int to float?
yeah
nah keep it float
float c = intA / (float) intB;
just format the float via text
eh im sure thats on ones prefrence
btw like how do you guys make something thats not on tutorial. i have very hard time making something new
ok
repetition is key basically
hmm maybe start with your own project and look up tutorials for piece-by-piece
e.g.: design your thing first, what you want (maybe a top-down roguelite puzzle with immovable enemies)
then search top-down movement, triggers, tilemap, etc, until you have something close to what you want
@glacial blade I say make it a float,
and keep the value between 0 and 1, then when displayed, multiply the value by 100
multiplication is faster than division* anyway 😅
MaxHealth is not a great variable to have if it's intended to be always 1 😛
maybe there's going to be a thing later where max health can be upgraded?
lots of things do that
yea 0-1 is silly
but making health/max health floats is normal and prob better
dealing with casting every time is annoying
this is just a useless optimization tbh, makes it harder to code in the future because your health is always 0-1 rather than its true value
it wasn't meant to be an optimization, it was just a cherry on top...
but understandable! at the end of the day, what's important is to make the game itself XD
and I wouldn't say it becomes harder, having a property that calculates the desired value is a thing in C#
you only have to write it once.
0-1 you have no room to expand max health
then why have it 0-1 in the first place if you only use a property to get its true value?
just store the true value
is there a thing people don't argue about in this discord? xD how is this possible lol
I guess makes sense since there are tons of people, each having different practices
i think its just a regular discussion dont think anyone is arguing lol
but a float casting? XD
we're just talking, no ones breaking out the weapons dude
You'd need a global value that scales the health, damage, and any effect applied value. That seems like more work to me. The entire game must change based on an 0-1 structure . . .
it is impossible to get rid of division in your case
then how would you deal damage? multiply with 1f/their max health (though this can be precalculated, actually you will get wrong answer, but i think that fine in game software....)?
🔪 👀
yeah, I can tell -- it's just that answers to beginner questions tend to get deep in no time -- which I bet looks like an argument to the new person that asked the question
yes because beginners tend to provide questionable answers, then people in here will try to guide them in a better direction while explaining why something isnt desirable
!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.
id like not to squint to view code
assign a reference to the enemy and make sure Enemy has a reference to Agent
how come this gives 101? i am confused even
could you show me what that would look like
im honestly just watching a tutorial and still very new
it prints iteration, not hp, lol
You need too assign a value to theEnemy variable . . .
yes, i know that.
Keep watching the tutorial and see if they do that . . .
100 + 1 because of late set oh nvmhp=1
they were able to run the code
so you copied wrong
🤔 did you read the code carefully, they set iteration back to 0.
ive looked at the tut over so many times and it seems i have everything right
I would go back over the video and see what they assign the Enemy variable . . .
we hear that alot , you'd be surprised how its usually a simple thing 🙂
is vector2 =
any different from vector2.set() performance wise
so is the problem Enemy or enemy
yeah no it's a mystery 😆
floating point error
uhh just use =
if you need to pass a new vetcor2/3 you can't, as only takes 2 floats
I will say, this is abnormal. I know you saw two (at least that I saw) deeper conversations. But I wouldn't say it tends to go that way any more than any other group of nerdy people 😸
I only suggested to keep the value in the range of [0-1] since it made sense for the health to be [0-100], but of course, it doesn't have to be [0-1]!
could easily be [0-2] or anything else really...
properties are commonly used to used to prepare your value before getting/setting it.
or simply do something for it.
however, you should implement your things as you wish, I was merely suggesting.
It's the field enemy from the BaseState class . . .
so the problem lies in the BaseState class
hehe fair enough 😛 I'm not a regular here so mostly judging by just what I saw today and what I would expect in a #💻┃code-beginner channel
0-2? oh godno.
just cause it can be anything doesn't mean it should be
No, that's where the field enemy originates from. The problem is in the PatrolState, which derives from BaseState. You do not assign enemy inside of the class at all, but you are trying to access it . . .
yeah im an idiot
thanks a lot
i really did just miss a very small thing
usually is
We all knew. It happens all the time. If you're following a tutorial and it doesn't work, then you missed smth. Always go back and watch carefully; there is no rush . . .
I was worried that maybe it wasnt working because the navigation component was changed since the video was made
but i was wrong
so thank you
ah yes! reminds me of myself when I used to believe that I LITERALLY copy-pasted the tutorial, and that the tutor had done something wrong just because I know I don't make mistakes... (I do make mistakes, ever hour of my time being alive, in fact! me being alive is a mistake XD)
i am very confused
i have a vector3 rb.velocity and i'm trying to scale it to avoid side drift of a vehicle
but even scaling it by local 1,1,1 doesnt work and the vehicle completely spazzes out ...?
scaling it with world space vector3 doesnt work because it's unable to turn, then.
//TEST: scale velocity to local 1,1,1
//forward: 0,0,1 right: 1,0,0 up: 0,1,0
rb.velocity = Vector3.Scale( transform.forward + transform.right + transform.up , rb.velocity);
//reduce sideways drift
rb.velocity = Vector3.Scale( transform.forward + transform.right * 0.2f + transform.up , rb.velocity);
how to activate this by coding ?
.enabled
Idk if this is UI but when I attempt to use an inputfield I need to click on it to actually interact with it, is there a way to make it auto-clicked on scene opening?
https://docs.unity3d.com/ScriptReference/Vector3.Scale.html
scale doesnt do what you think it does. that first line literally does nothing
Activate i think you want
no
Select
Where would I find that?
[SeriliazeField] private TMP_InputField input;
input.Select();```
there might be another one you may need
well you need a reference to Inputfield
if I just throw it into the keyboard class would that work?
it just needs to be run on scene
if it already gets input mind as well
Digiholic has a counter for exactly this. I need to tell them to update it . . .
yes, please do the ++
// Start is called before the first frame update
void Start()
{
autoClickText.Select();
}```
I can't actually put the inputField into the thingy (I don't know the name of it, it's in the image)
you didn't even copy it correctly xD
is TMP important?
how do I know if it is
read the label ?
I changed the name to text area for some reason
yeah it's the pro one but it's make an error
you need to add Namespace
using TMPro
Namespace is just a "group" scripts belong to
yea usually a dll
Ah ok
think of it as a folder to your C# script files XD
yes. the first line SHOULD do nothing.
but with it, the vehicle goes glitching into the sunset
is there a way to see if something is visible or not?
trying to make a button that shows a list but removes it if it is already shown
maybe floating point errors cause it to not be exactly 1
holy guacamole it's 3:30 am
yall
what would be the index for crouch layer
im not sure if c# starts counting from 0 or from 1
ok thanks
yo how do i smoothly transition between animation layers
Lerp the weight
i tried but its not really working
i havent used lerping before
use a coroutine its easy, replace the v3 with Mathf.Lerp
https://unity.huh.how/lerp/coroutines
That will always evaluate to roughly 10, because Time.deltaTime is small
i mean thanks but im not really sure where to place all of this
im assuming this is a function?
not sure tho
IEnumerator LerpWeight(float targetValue, float duration = 1)
{
float startValue = anim.GetLayerWeight(1);
float elapsedTime = 0;
// Wait until the time has reached the target duration.
while (elapsedTime < duration)
{
// Increment our timer.
elapsedTime += Time.deltaTime;
// Normalise our timer, and use it to interpolate.
anim.SetLayerWeight(1, Mathf.Lerp(startValue, targetValue, elapsedTime / duration));
yield return null;
}
}```
You need to at least understand how Lerp works https://unity.huh.how/lerp/overview
So you can comprehend the rest of the logic
ok thanks
yo i mean
its working but
for some reason theres a delay when uncrouching
like a 1-2 sec delay before the coroutine starts
this is how its looking rn
you might be triggering multiple ones, also the layer weight max is 1
10 is overkill since its fully activate only at 1
oh youre right
setting it to 1 fixed
but i thought that at 1 it would be kinda in between base and crouch
isnt that how weight works
.5 you mean?
yea lol
so now i also gotta lerp the camera and the collisions?
i mean i guess i dont need to lerp collisions i could just set them normally
but the camera
if you want things smoothly moving
you mean lerp the collider ? thats also common
there are also tweening libraries out there (DOTween is good)
Coroutine simple enough, the result is pretty good when done correct
ok thanks
so should i make another function for lerping vector3s
or should i try putting it all into one
and also what uhh
type? i guess
are objects
like strings ints floats etc
what do i use when getting the camera for example or the player model
Camera
model is part of the Mesh FIlter, Mesh renderer displays how it will look aka texture/material
all the components are found in !docs
wait what if i just change the center of the collider instead of lerping the camera down
yeah
this dude does that and with lerp
they actually lerp correct too which is rare on YT
?t=624
yall how can i move the camera position up while still keeping it on the character
you mean change the camera's height while maintaining its movement relative to the player?
I have two varaibles i want to track, the prefab of an object and its interface. I want to store a list of these two varaibles, should i be using dictionary or classes?
Think of it like an enemy pool.
yeah
The convo for this is in #💻┃unity-talk , don't cross post
you don't have the camera as a child of the player's head, do you? (you don't need to btw)
it's also not currently a code question, keep it in #💻┃unity-talk
brother i dont wanna be mean but youre really being a pain
jus let us talk
Follow the server rules ¯_(ツ)_/¯
mods will handle it if they wish to
I see!
its not a log
thats a Null Reference
something on line 85 is null on Night Background
can you help me with code
what is interactable object?
i dont know
then we dont know ofc if you dont know what this type is
and there is a method called as TryGetComponent
bro it's don't work but i don't have "InteractableObcject"
and i create code "InteractableObcject" and now its work
thanks
you're welcome!
@wind meteor and try dis, it's 🤵♂️er
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
/// if (Physics.Raycast(ray, out RaycastHit hooray) is false) return;
if (Physics.Raycast(ray, out var hooray) is false) return;
/* TODO: ... */ _ = hooray.transform;```
how to create cod like photo
like this
!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.
read inline code section
Call of Duty?
cod like the fish
Hey i have an animation for a 2d character (the player) attack (dash attack) so the animation move the sprite. Id like to know how could i make the player collider and position match the animation
The attack is the sweep
Error
MissingReferenceException: The object of type 'GameManager' has been destroyed but you are still trying to access it.
Its on this line
DontDestroyOnLoad(Instance);
I know what the error means but like i dont know a fix
private async void Awake()
{
try
{
await UnityServices.InitializeAsync();
}
catch (Exception e)
{
Debug.LogException(e);
}
SetupEvents();
await SignInAnonymouslyAsync();
await EconomyService.Instance.Configuration.SyncConfigurationAsync();
if (Instance == null)
{
Instance = this;
DontDestroyOnLoad(Instance);
}
else if (Instance != this)
{
Destroy(gameObject);
}
}
The singleton setup should be before all the async stuff
What?
Which part is unclear?
yes, why would you initiate all the async stuff to just then go and destroy the object it's running on?
I just never heard the name singleton setup before
Probably not a good idea to use code that you don't understand
but the singleton setup is from the if (Instance == null) line onwards
I understand the code i just never heard the name before
I mean it's the code that sets up the singleton
I fixed the code now i got a new error
NullReferenceException: Object reference not set to an instance of an object
MainMenuManager.Awake () (at Assets/Scripts/Managers/MainMenuManager.cs:26)
line of error
PlayerBalance playersCoinBalance = await coinCurrencyDefinition.GetPlayerBalanceAsync();
here is my code
private async void Awake()
{
await EconomyService.Instance.Configuration.SyncConfigurationAsync();
var gemCurrencyDefinition = EconomyService.Instance.Configuration.GetCurrency("GEMS_DATA");
PlayerBalance playersGemBalance = await gemCurrencyDefinition.GetPlayerBalanceAsync();
var coinCurrencyDefinition = EconomyService.Instance.Configuration.GetCurrency("COIN_DATA");
PlayerBalance playersCoinBalance = await coinCurrencyDefinition.GetPlayerBalanceAsync();
gameManager = GameManager.Instance;
coins = playersCoinBalance.Balance;
coinsText.text = "Coins: " + coins;
gems = playersGemBalance.Balance;
gemsText.text = "Gems: " + gems;
}
i am using visual studio, but it give me the "The type or namespace name 'type/namespace' could not be found" error, but the game works fine (without error) when i launch it via unity, but i can't code if it can't access the namespaces (this error started when i switched pc)
(the namespaces should be referenced i check in the solution explorer, i thus have no idea what to do)
(i am using assembly-CSharp definitions)
This script might be not a part of your game, that's why it cannot access other scripts
fixed my GetCurrency("COIN_DATA"); needed to be GetCurrency("COINS_DATA");
may you explain?
because it should be
Mind trying to find this class in your Unity Assets?
yes?
Does it open the same class with errors?
yes :' (
And you don't receive any errors in Unity?
none
just in vs?
yes
That's strange
It seems to be a bug? Have you already tried to refresh unity?
yes over multiple weeks
Over multiple weeks? Do you have this error for so long already?
yes
when i changed pc
What about other scripts? Do you have the same weird behavior there?
Could it be bc you're missing some .net stuff, or bc your visual studio installation is missing the unity addon thing?
i have the unity addon and it seems to be a reference issue so i doubt it would be a .Net
Error
The best overloaded Add method 'SortedDictionary<int, string>.Add(int, string)' for the collection initializer has some invalid arguments
Line of error
{1000000000000.ConvertTo<int>, "T" }
Code
public static class AbbrevationUtility
{
private static readonly SortedDictionary<int, string> abbrevations = new SortedDictionary<int, string>
{
{1000,"K"},
{1000000, "M" },
{1000000000, "B" },
{1000000000000.ConvertTo<int>, "T" }
};
public static string AbbreviateNumber(float number)
{
for (int i = abbrevations.Count - 1; i >= 0; i--)
{
KeyValuePair<int, string> pair = abbrevations.ElementAt(i);
if (Mathf.Abs(number) >= pair.Key)
{
int roundedNumber = Mathf.FloorToInt(number / pair.Key);
return roundedNumber.ToString() + pair.Value;
}
}
return number.ToString();
}
}
idk how you can convert long to int
I also dont know but if i remove the .ConvertTo<int> it still does not work
fixed just used Convert.ToInt32(1000000000000)
try to run it
i think you will get an overflow error
you should change the generic parameter int to long
ye OverflowException: Value was either too large or too small for an Int32.
i finished my first movement system and now idk what to do
should i make a map
or
interactions
or something else idk
Make the mechanics then the visuals
thats what i would do because if you have some mechanics you can make a map if you need a map just make a little prototype map
Dont think this is normal
so like doors and stuff like that?
im tryna make like a low poly horror game about cleaning up murder scenes
if you need a door opening mechanic just make a door and make it work then after that make a map when you are done with all mechanics
with ps1 graphics
ok
you mean the -1T?
yea like i have 5 gems and it says i have -1T i will just try and find another way of formatting my numbers so i can get K, M, B, T, Qa, Qi, Sx, Sp (sp is 100e24)
i am not sure if it is due to some number type conversion (the rounded number is -1), try to change all the type to long first (except the i in for loop)
oh wait it shouldne fall into the if block, it should return "5" directly
yea thats why i dont understand
I try to reproduce it but it works....
Works now i use a double
but now the problem is that i want it to only show 2 decimals and it works but the gems that is 11 it shows 11,00
one trillion modulo 2^32 is 3567587328
which wraps around to something like negative one billion
I presume that's why you tried to use ConvertTo. Any numeric literal that's too big for an int will automatically become a long.
long will give you some more headroom. You can also use double if you want to use extremely large numbers, but note that you'll pay for it in precision
i gave my player controller the ability to crouch but i honestly have no idea how to make it to where the controller checks if there is a ceiling there to keep it crouched
for example, the first number can be stored in a long, but if you convert it to a double, it'll be off by quite a bit
i have checked
Mathf.Abs(5)>=1000000000000L
```returns false, so sorted Dictionary<long,string> works (tested)
so i have no idea why it returns -1, if he has changed it
they said it works correctly now
it was wrong when they had a dictionary mapping ints to strings
since one trillion overflows to a negative number when stored in an int
Fire a sphere cast from the top of your character( or better yet a capsule cast) and if you hit anything there is a ceiling
will try this
Just use any casting method to check for anything above the player's head . . .
hm-
this should select a new chosentargetlocation if its closer than the already selected one, but this doesn't appear to work- where did I make a mistake?
You don't store any of the distance values so no one knows what the numbers are. Log the values to the console to see if the target is closer than the chosen target . . .
what is chosenTargXXX at first? the first element?
well, here is the placeholder that serves as the first chosen target location. One might guess that its further than any enemy ( red boxes )
This doesn't help us. Log the values of the distance to see if it becomes less than the chosen target distance . . .
right yeah okay-
yeah I guess ill need to log- but you know
the red square in the firing range ( white circle ) is certainly closer than the placeholder at X=500
is there a way to comment enum elements ? so when i hover them i can get some text showing in VS
I guess like a summary for individual enum entries
i mean the VS tooltip
Oh, comment!
like i can hover
whateverenum.whatevervalue
a triple slash starts a documentation comment
You can put these in quite a few places
In your example the summary goes to the field, not the enum though
okay ty
idk why i didnt try the default way of commenting first, in my head enum were "special"
looks like that was just an example of seeing a doc comment when hovering
Man, I like having documentation (summary info) for all members of a class. I did that for one of my packages and the entire thing is just comments everywhere! 80 lines turned into 400 . . . 😄 🤣
ok looked at the Documentation and implemented it to the best of my knowledge
and im still clipping through the ceiling
hi, why i'm starting to get this type of errors on everything i do?
it used to work only with Debug.Log();
Bc you have two namespaces with the same type: Debug. The IDE does not know which Debug class you want to use . . .
ty, now i've seen that it added somehow
You need to specify which one by using the fully qualifying name . . .
You don't need the System.Diagnostics one . . .
why doesnt this code work (trying to make a bullet collide)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class bulletDistroy : MonoBehaviour
{
public string tar;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
void OnCollisionEnter2D(Collision2D collision)
{
print ("boom");
// Check if the colliding object has the specified tag
if (collision.gameObject.CompareTag(tar))
{
// Destroy the colliding object
Destroy(collision.gameObject);
// Destroy the object that holds this script
Destroy(gameObject);
}
}
}
im gonna guess and say its cause there's nothing in the void Update()
First, how to post !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.
i dont think so
are you like a mod?
Second, for a collision to have occurred both objects must have colliders and one must have a rigid body
Are you new?
@unborn gale It would be easier to read your code which would help you and us so why not?
yup and I basacly joined this whole server to ask this
I dont know what !code is and the bot doesnt explain wel
📃 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.
The bot provides useful shortcuts that any member can invoke. Best to avoid spam, off topic and whatnot.
#💻┃code-beginner message is necessary.
public class bulletDistroy : MonoBehaviour
{
public string tar;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
void OnCollisionEnter2D(Collision2D collision)
{
print ("boom");
// Check if the colliding object has the specified tag
if (collision.gameObject.CompareTag(tar))
{
// Destroy the colliding object
Destroy(collision.gameObject);
// Destroy the object that holds this script
Destroy(gameObject);
}
}
}
Do you see all of the links the bot posted? It's a bunch of websites where you can paste your code, save, and send us the link so we can view it. It's hard to read (and help) with unformatted code in the channel . . .
yay
dis good?
well you didnt declare tar to anything
you just assigned it to a string
i did inside unity
It's public, they probably wrote the name from the inspector . . .
Does it print anything?
oh ok got it
before anyone ask why isnt my vscode configured i already given up on that long time ago. the question now is that i not sure if theres a syntax error since the error shown in the unity is the type or namespace names LogicScript could not be found. what is LogicScript in unity mean
why isnt it in vscode?
Did you check what Dalphat mentioned earlier?
#💻┃code-beginner message
I think LogicScript is just a class defined previously in the tutorial
both have rigid bodies and colliders
Does it print the debug message you wrote?
Did you follow the entire tutorial? That sounds like a custom made script. You should know if they created that beforehand . . .
2d colliders and 2d rigid body?
yes