#π»βcode-beginner
1 messages Β· Page 298 of 1
right mouse click the method/ var/ type -> find references
the sensX and sensY
what?
sensitivity
I don't understand how that answers my question
basicly i want my game to stop responding to my mouse when i pause
i tried making sens 0 but it gives me error
I'm asking you, which PlayerCam do you want the variable cam to hold a reference to
in unity or visual studio
Take a wild guess, it's kind of obvious
not so good approach. You could use your update function where the code actually responds to click and make some if statement about when they actually should respond. So basically if you pause, then don't respond. Easy as that?
for this you will have to use either some sort of bool like public bool isPaused = false/true; or maybe some statemachine with state like PAUSED: or maybe as you pause the game, you invoke something so it shuts the input down
but you carry on with clarifying what for instance are they intending to hold π much love
I'm answering their actual problem
There's a null reference because they don't understand how to reference an object
they described their actual problem in the screenshot I just sent )
also they told why they get null reference error. And I told them it's because they are approaching the problem from bad side π But well... how about we are both right?
It's just me not "?" your messages
this was their question that started the whole thing . . .
#π»βcode-beginner message
but they changed their problem and I got a screenshot of it π
maybe they understood what they are trying to do while discussing?
and had no idea before? Altho Ill go read that initial message )
Okay lemme translate that: they wanted to make new instance of their whatever float for the reason: they wanna pause and for that they wanna use another instance of the value for the state where game is paused.
I knwo you guys are all damn smart here. So smart, that you simply don't get what actual beginners and newbies are asking about. Because they themselves have no idea
All they (currently) need to do is assign their cam var..
Then move onto the next issue
They want to change a float in cam. In order to do that they need to reference cam. I am asking leading questions to try to get them to understand what referencing even means while you're posting some word salad about state machines for some reason?
that was just their end goal, but the original (current) problem is stopping them from doing that . . .
And I don't intend to mean that anyone isn't smart. Actually smart. That's sometimes is a problem. Experienced guys can really have 0 idea what newbie is talking about. I experienced it myself many times.
@visual hedge Why are you continuing with this? The issue was already clarified to you.
Okay I will shut up, sir. Have a nice evening though )
hey can someone help me out with a issue im having?\
No idea if we can until you ask π
so im following this tutorial https://www.youtube.com/watch?v=XtQMytORBmM and im having trouble with the gameObject step around 20:35
π΄ Get bonus content by supporting Game Makerβs Toolkit - https://gamemakerstoolkit.com/support/ π΄
Unity is an amazingly powerful game engine - but it can be hard to learn. Especially if you find tutorials hard to follow and prefer to learn by doing. If that sounds like you then this tutorial will get you acquainted with the basics - and then gi...
what is "having trouble"
i cant get a second option to show up in the code component
if it's a private "option" then use [SerializeField] on top of it
which option are you referring to ?
What do you mean by "option" and "second option"?
a second script
do what he does in the tutorial π€·ββοΈ
What do you mean "second option"?
public GameObject pipe; he types that and it just works
Yes it will work for you too
Okay, and what does yours do
unless you messed something up
its not tho
well, he saves it too
maybe compile errors
he doesn't show, or say, to save the changes to your code
ive saved them
ok, so .. let's stop guessing.. and you SHOW us what you've done
if it works, there's no need to carry on..
After you save the script, you wait for unity to compile. After it will update the inspector. Guys in tutorials may have a powerful pc that allows to compile in split of a second, especially if that's simple flappy bird. While your pc may take longer. idk
Why does unity tell me my scripts are missing, even though they are in assets, I got my code to work i think, theres no more errors with the code. But unity is telling me it cant find my scripts
You have a GameObject that has an invalid script attached
find it and remove it
Thank you
Do you have any compile errors and does the file name match the class name
No compile errors, but it is the file name thanks, sorry for asking dumb questions
i got it to work i had to reference from object i was just picking up script with null properties i got fixed now
hello
im trying to get a model to follow my cameras x rotation but it seems to be spinning forever
unless the cameras x is 0
the more closer it gets to zero the slower it is
well for one you should not multiply mouse inpuit by deltaTime
and your last line is the culprit
the transform.Rotate. Get rid of that. It makes no sense.
It's unclear what p2 is but Rotate is cumulative, not absolute.
p2 is a reference to the player gameobject
but what else can i use to make the player rotate around the camera
wdym rotate around the camera
is this a first person script?
SET the rotation, don't add to it.,
well alright then
rotation.x = transform.rotation.x
does that work
well what else could i do
It's hard to say exactly what to do here without knowing:
- The camera style (FPS? TPS)
- Which object is which
what is tps
set it properly like you're doing for the camera
third person
fps then
@wintry quarry do you recommend any coding lessons after finishing the beginner coding and intermediate coding lessons from unity learn
the tytpical thing is:
player.rotation = Quaternion.Euler(0, yRotation, 0);
cam.localRotation = Quaernion.Euler(xRotation, 0, 0);``` assuming the camera is a child of the player
I recommend some pure C# https://dotnet.microsoft.com/en-us/learn/csharp
i assume yrotation is just x rotation's complete opposite?
@snow girder hey I'm also 2008
Birthyear
same thing
No it's whatever your player's y axis rotation should be
What? All of this is software.
so just p2.transform.rotation.y?
you are not correct
y is left and right?
damn when was that
MoujseX would be for the y rotation
y is rotation AROUND the y axis
x is rotation AROUND the x axis
neat
well there's also another issue
for some reason the model would just
be like a few inches above the collider
wait hold on let me make the collider more visible
the pink thing is the collider
and the player is above that fsr
Aaaaah... just move it?
it didn't happen before
it only happens in the play mode
and even if i do try it snaps back to this
if it was this simple why would i bother π
is it possible to change find a script on an object that is disabled
and change an int on it
can't you enable it, take the variable and then disable it again?
What is snaping it back?
Sure. But maybe reference it ahead of time is better.
maybe the character controller script?
but i don't know the issue
this
Any of these seem to move the collider itself. Just the GameObject; isn't it?
anything connected to the collider?
well its a gameobject with a collider containing the model
is that stupid?
you can put the collider on a seperate child game object
sure
I would have the collider in the parent GameObject separate from the model
But shouldn't matter
gonna attemp that
I mean move the collider within the GameObject, like offset it so it stands where you want it to be
i have placed it on the mesh
and it did 0
as in nothing
usually I put the collider and model seperate from one another and both children to an empty
that way you can move the collider around
i doubt it will do anything but alright
show us the collider component and hierarchy
yellow is collider
did nothing
also im trying to say that it worked before without any changes
so i think its an issue with code
but idk what
Hey all, im new to unity! Can someone please attempt to help me fix my camera jitter? It might not even be my camera jittering, but when I move around objects, they jitter and I dont know if its my camera or something else. I've had no luck with finding a solution and frankly I'm at a loss as to where to go next. I've also already tried using cinemachine but I still come up short, and nothing else has worked so far.
PlayerMovement Script : https://gdl.space/kizodiqeri.cpp
Camera Script : https://gdl.space/esadejigib.cpp
More info : https://discord.com/channels/489222168727519232/1226261265110929429
mayhaps late update shenanigans idk
try normal update
Does anyone know how I can make an enemy using navmesh avoid a dynamically moving area around a player that doesn't have a physical obstacle? My enemies find a random location to move to a certain distance from the player but they just walk right past the player to reach it.
just like follow one of those enemy sight tutorials on youtube and break the function if the enemy spots one?
Jittering typically occurs when some movement is not updated at the same rate as the rendering. Physics being one of such things. That's why there's an interpolation option on the rb. Do you have it enabled?
so anyone know why...
nothing in your code seems to be even touching the collider
it's moving a gameobject that has a collider?
i swear it didn't happen like two moments before
and it suddenly just happened
I've no clue whatsoever what the issue is and that screenshot doesn't make it any clearer. Maybe try recording a video and provide a proper textual explanation
basically the pink thing is a collider and the model is floating above the collider
they might not walk directly into the player that way but I don't think they'll stay in a circle around them. They would just probably end up walking next to the player.
imean have you tried tho
Is it above? Not behind? It's really not clear from that screenshot
does it matter? i mean the only issue that it's above
sorry if that was rude
woah okay
it works without an animator?
like it doesn't float above collider if there's no animator?
does that make any more sense?
my code doesn't touch the animator either
yet somehow the animation makes it float above the collider
It matters very much. One is horizontal offset. The other is vertical. Which one is it?
If it's due to the animator, it's probably root motion. Try disabling it.
Assuming it's not just an animation issue
root motion is disabled...
Then it's an issue with your animation
i guess mixamo can't be trusted anymore
I was using normal update for a while and neither that nor LateUpdate did anything
trying instead of making the camera follow, inside the player object
Yeah, all my rigid body's are set to interpolate
Then make sure the interpolation is now broken
Record a video demonstrating the jittering
he did in his thread
i don't get this
the animations are perfectly fine
why is it doing that
Are these all the animations?
all of them
And all of them are from mixamo?
Does it jitter when you're moving without rotating?
Ideally,comment out the rotation code entirely for testing.
Yeah, moving without rotating causes them to jitter. Rotating without moving is completely fine
can someone help me this isn't loading and it just says checking for updates
Okay. Can you put the animations in different states and try them one by one? Or even just an animator without animations
have you installed any assets
sure
without the blendtree thingy it works
Yes a photon thingy
mad respect for attempting a multiplayer game anyways try switching the packages thing maybe
lmfao why he do this with no animations
I'm watching this tutorial and i'm at 16:59 https://www.youtube.com/watch?v=KBcsX0uCNi4
Unity Hub: https://unity3d.com/get-unity/download
Gorilla Locomotion: https://github.com/Another-Axiom/GorillaLocomotion
Photon PUN 2: https://assetstore.unity.com/packages/tools/network/pun-2-free-119922
Photon Voice 2: https://assetstore.unity.com/packages/tools/audio/photon-voice-2-130518
Photon Website: https://www.photonengine.com/
Pho...
idk the package manager just wont load
I also just started using Unity like 1 hour ago
@snow girder
have you logged in :trollface:
yes
what version are you on
im on the same Unity account on the application and website
lateast?
How do I check that?
Oh wait
I know
1 second
Take a screenshot of your blend tree settings again
after i just deleted it?
damn
what?
I mean, if you don't need it, then problem solved?
no i was replying to the other guy
no i meant like deleted it to try
oh ok lol
anyways try an older version
And it worked. So we've got a clue from that.
Will I still have my full project
and how do I switch to an older version?
well yeah
Ok
try it
I click on installs and what?
well i'll add another blend tree under your guidance then
im kidna stupid it was the wrong way
click here and somewhere it should say
I suggest going through the beginner pathways on unity !learn if that's the case
:teacher: Unity Learn β
Over 750 hours of free live and on-demand learning content for all levels of experience!
We're not gonna teach you the basics of working with unity here
right also try posting this issue not in code beginner?
i don't think its a code issue
Do I need to close the editor first before switching?
yes
right so i added it and now it floats again
grrr
Take a screenshot of the blend tree settings. Also, did you try all the animations in separate states?
the version you showed me in this screenshot you sent me
sure
ok
Do you just want to call and I can screenshare
Don't need to talk btw just share screens maybe?
none of his is code related
im guessing like half of this i don't think i can help any more
Make a default transition into a state with the idle animation
oh
my bad
sorry bro
1 more thing would this version work maybe?
or this one?
maybe the second one? idk
god damn i should gotten some animation practice
Thanks!
i don't know jack about this π
no problem?
okay maybe you are right
cause when i tried without blend tree
the anims
the guy still floats
how dose one make it so that a sprite moves when i hit wasd cuz i dont see a premade scrpit for that
look it up :trollface:
Just drag the idle anim clip into the animation controller outside the blend tree and configure a transition.
And yeah, should probably go through the beginner pathways too.
well i did and it still floats
!learn
:teacher: Unity Learn β
Over 750 hours of free live and on-demand learning content for all levels of experience!
There's no premade script
Good. Take a screenshot of the scene view
It should if setup correctly
well i could if i knew the issue!!! god this program is tough
With the hierarchy and the inspector visible and the character selected.
is bolt free
yeah?
bro just look it up it doesn't take that much effort
oh shit fr?
π
well good luck to you i suppose
visual scripting π€’
Expand you collider settings
what i could do is manually go in the anims using blender and set them 0
No. Forget about it for now.
How do I play my Unity game in VR? cause I got a Quest 3 and a link cable
still not a code question man π
Center y should be set to 1
but im pretty sure its a plugin
sure
Ok. Im new here sorry
oh my god
i am actually so stupid
im so sorry for making you go through this
!learn
It's not something a beginner should do out of the bat.
:teacher: Unity Learn β
Over 750 hours of free live and on-demand learning content for all levels of experience!
thank you so much dude π sorry for making you go through this cause of my stupidity
mad respect
yay!
Hey guys
I need help a bit
I have a shop, I used SO to load the items in it.
If I click buy something, a different SO will be added to a list of scriptable object for the Inventory.
How do I drag the images, texts and stuff into the element of the list ?
Left is Youtube, right is my screen. So, we does mine not have this mouseWorldCoordinates keyword ? it throws a red squiggly line underneath if i try just to write it in anyways.
This is not a code question
oh never mind I just realized I had to get the Vector3 mouseWorldCoordinates variable higher up on the line above my current variable
because the compiler has no idea what that mouseWorldCoordinate is if I go by that order
makes sense
Hello! π
Does anyone know a way to get the position of a RectTransform as if it were a direct child of the canvas? I know I can just change the parent and then get the data and change it back but that seems pretty inefficient.
Thanks for your time!
as if it were a child
What does that mean? Like the offset position (localPosition)?
Yes, exactly. Like in the hierarchy I can drag it to be a child of the canvas. As it stands it is a child of a child of a child of the canvas
GrandparentPosition - grandchildPosition
I think that should work
Is it that simple? I don't have to factor in intermediate positions and anchor
That gets a vector that equals the distance and direction (synonymous with vector haha) from the grandparent to the grandchild (which is essentially all a local position id)
My worry is that it won't work well with recttransform
hey uh sorry to bother you again but how do you make animations play on a parameter of the animation?
Thanks very much!
Well, I could be wrong on it haha
π I am going to fiddle with it now, I'll let you know if it works out!
Either way, thanks for your time β€οΈ
By using the parameters in the transition conditions. I recommend going over the manual of animation system
whats the function for it i meant
animator. ?
Isn't unity game development
You again haha
it's software used for game development. that's not the same . . .
Check the animator documentation
right
I ended up getting a value that was normalized between -9 and 9 on the x axis, and -5 and 5 on the y. Uncertain how these values were being calculated I didn't want to risk using them in case they were not consistent for different use cases. I'm sticking with just changing the parent, doing my calculations and switching it back. So far the performance hit is negligible. Thanks again!
Fair enough, thanks for letting me know!
Video games are a type of software
Ah ok
But it's different though right
Console.Writeline is like Debug.Log or something
It's the same language
Once you know C# good enough, you would know how to use the unity api
Ah
using Unity.Netcode;
using UnityEngine;
using UnityEngine.UIElements;
public class PlayerController : NetworkBehaviour
{
[SerializeField] private float speed = 3f;
private Camera _mainCamera;
private Vector3 _mouseInput;
private void Initialize()
{
_mainCamera = Camera.main;
}
private void Update()
{
if (!Application.isPlaying) return;
//movement
Vector2 mousePositionScreen = Input.mousePosition;
_mainCamera.x = Input.mousePosition.x;
_mainCamera.y = Input.mousePosition.y;
_mainCamera.z = Input.mousePosition.z;
Vector3 mouseWorldCoordinates = _mainCamera.ScreenToWorldPoint(_mouseInput);
transform.position = Vector3.MoveTowards(transform.position, mouseWorldCoordinates, Time.deltaTime * speed);
//rotation
if (mouseWorldCoordinates != transform.position)
{
Vector3 targetDirection = mouseWorldCoordinates - transform.position;
transform.up = targetDirection;
}
}
}
One is part of the console namespace and the other part of the Debug class provided by Unity
Yes, you would use then in different places. But that is what an API is
I was looking up my problems on the unity forums and I saw praetor blue answering it
Few months ago
Camera doesn't have an x π€·ββοΈ
You were thinking of the camera's position. Which is not accessed like that
mainCamera.x < this makes no sense. There's nothing called x on Camera
oh i meant to write_mouseInput
Why do:
_mouseInput.x = Input.mousePosition.x;
_mouseInput.y = Input.mousePosition.y;
_mouseInput.z = Input.mousePosition.z;```
When you can just do
```cs
_mouseInput = Input.mousePosition;```??
π
using Unity.Netcode;
using UnityEngine;
using UnityEngine.UIElements;
public class PlayerController : NetworkBehaviour
{
[SerializeField] private float speed = 3f;
private Camera _mainCamera;
private Vector3 _mouseInput;
private void Initialize()
{
_mainCamera = Camera.main;
}
public override void OnNetworkSpawn()
{
base.OnNetworkSpawn();
Initialize();
}
private void Update()
{
if (!Application.isPlaying) return;
//movement
Vector2 mousePositionScreen = Input.mousePosition;
_mouseInput = Input.mousePosition;
Vector3 mouseWorldCoordinates = _mainCamera.ScreenToWorldPoint(_mouseInput);
transform.position = Vector3.MoveTowards(transform.position, mouseWorldCoordinates, Time.deltaTime * speed);
//rotation
if (mouseWorldCoordinates != transform.position)
{
Vector3 targetDirection = mouseWorldCoordinates - transform.position;
transform.up = targetDirection;
}
}
}
NullReferenceException: Object reference not set to an instance of an object
PlayerController.Update () (at Assets/_Scripts/PlayerController.cs:21)
If you're doing networking, you should be able to fix a little null reference error.
Or rather, maybe you shouldn't be doing networking on your current level.
Read the error. It tells you what line exactly is the problem. Check all the reference type variables on that line to find which one is being null and make sure that it's assigned.
!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.
what should i be doing in my current level?
Single player games. Most importantly, follow the beginner pathways on unity !learn and go over some C# courses or the manual.
:teacher: Unity Learn β
Over 750 hours of free live and on-demand learning content for all levels of experience!
oh wow thats actually a good course much better than those I was struggling with on youtube lol
first time Im actually clicking that link
I'm trying to understand how yield and async operations work.
//Check the download size
AsyncOperationHandle<long> getDownloadSize1 = Addressables.GetDownloadSizeAsync("Base");
yield return getDownloadSize1;
if (getDownloadSize1.Result > 0) bundles.Add("Base");```
my assumption is that the code execution waits at yield until `GetDownloadSizeAsync` has finished. is that correct?
that's not what it's doing for me, how is this meant to work? my downloads don't wait until they're finished and it continues on and fails before the assets are downloaded
If that's not in a coroutine that's not a valid code.
In fact, it's probably not valid anyway.
Check the AsyncOperationHandle documentation
Ah, okay, if it is in a coroutine it is valid.
Is it?
Not too sure about GetDownloadSizeAsync, but usually anything that says Async and requires yielding will stop yielding when the operation is complete
or good way to test it is to not yield and see if your program locks up haha
what is yielding exactly?
is it a synonym for "wait"?
what I'm seeing right now is it spits out 0% downloaded then tries to instantiate the asset I told it to acquire dependencies for
It has a meaning in normal C# but in Coroutine terms it means "Wait until the given condition is true before resuming". The default action is "next frame" which would be yield return null. Once the wait condition is up, it resumes right where it left off with the next line. So a yield return new WaitForSeconds(3) would pick up on the next line 3 seconds later.
is the "wait" context inside the coroutine function, or in the thing calling it?
in this case it basically is doing a little work, exiting the code, then picking off where it was last frame. Well, there's some internal operations going on here too done by unity too, but it is checking every frame if it is done.
I only have one coroutine so I guess that's why it's all failing
otherwise your program would become unresponsive
I think I need to redesign my loader completely :/
Maybe share the whole function that this code belongs to...
I think I know how to visualise this now though, thank you
it's not a function, it's multiple classes and scenes
like I said, redesign
In C# any code like that needs to be in a function/method. It can't be outside.
that's not what I meant....
Then share the method
no
the code we're talking about is in different places and it's not worth sharing
as we're finished here you don't need to interrogate it
Surely the code that you shared earlier is in one specific place. Can you not share more of it..?
Aight, you do you then...
thanks for the help @timber tide
how can i make my game start ? my player run using update so i want to it start running only if i click "play" btn. I only know setting time step to 0
do u guys know better methods ?
have a main menu scene, and a scene where the game actually plays. then load the scene when they press play
what if i use only 1 scene?
i just hide the menu canvas
Why limit yourself to this, it is easily solved with 2 scenes
hmm. thanks, u are right
Is it a good idea to create a class that specifically handles the death of enemies? Since enemies dying usually turns off their update loops and logic, or is it better just use use a state machine?
if only enemies are dying it might make sense to just create an abstract base enemy class that handles the updates stopping and death and whatnot
and then all the real enemy classes do whatever they do on top of the code that handles death and health and whatever
i see thanks
Yes, have an EnemyManager that queues and dequeues enemies from the pool
at the moment im just using an interface called IEnemy and when they spawn and die they get removed and added to list
public class EnemyManager
{
public void AddStatMod(StatModSO mod) { }
public void RemoveStatMod(StatModSO mod) { }
private void RequestEnemy(EnemySO enemySO) { }
public void ReturnEnemyToPool(Enemy enemy) { }
}```
some ideas what your manager would do
And on your enemy something like:
public class Enemy
{
public void ReturnEnemyToPool()
{
GameManager.Instance.EnemyManager.ReturnEnemyToPool(this);
//Remove StatMods and such (could do this in the manager too)
}
}```
How many enemies do you think you'll have at a time? the game targetted for pc?
You might be able to just get away with destroying an enemy and instantiating new ones if you dont plan on having absurd amounts. Pooling is nice if you have performance concerns but then you also need to worry about things like resetting all logic associated to that instance of an enemy. It can be quite tedious
https://hastebin.com/share/irapomejim.csharp @rich adder
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
This is the script that mentions the error
line 31 doesn't match
But there is nothing there...
did you change the script since error?
clear errors and run again, just to get fresh error line
No
I did it, I get the same...
line 31 and 32 don't match anything here
select error, screenshot the full stack in console window
Although I'm pretty sleepy right now, it's 2am where I live, do you mind if I add you to talk to you after this?
You may post this question tomorrow, there will be many people around to help
(btw check that you have items in array of questions or no copies with empty)
Hi. Is there any chance that I can draw IMGUI outside of MonoBehaviour?
Hi all,
Would someone be willing to take a quick look at this and see where my mistake is please? I think it's something to do with where I'm setting isFiring = false, but I'm a little lost. At the moment, the missile Swarm only fires once (correct number of missiles spawn etc). There should be a delay before the player can fire the next swarm (3 seconds currently), but it's behaving as though the isFiring bool is never set to false π
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
I just debugged the bool and it seems to be working fine (gets set back to false when it should), so I'm at a bit of a loss tbh as to what's actually happening when I press Space the second time.
Ah, ok sorry reading the logic wrong here. Thinking you invoke the coroutine in the forloop
so, you set shooting to true, shoot a missile and pause some amount of times, then you pause another time after the forloop and set shooting to false.
Shooting = true, fire x amount of missiles, delay for 3 seconds, set shooting = false is what supposed to be happening. (Can only fire again once shooting = false, and enemy count = grid cellcount.
if you haven't, start using the vs debugger and run through your code step by step
Did you figure it out already?
My guess is that the problem is you start a coroutine in a coroutine.
I'm getting there, think I've found the problem, just tweaking to test/make sure. π
I was going to suggest just yield StartCoroutine from the first
but I don't think it makes a difference as it seems fine as is to me
Well I'm unsure what happens without yielding the other coroutine.
The first coroutine ends, so what happens with the other one? Does it end prematurely?
I think the yielding is better, or just put the code at the end of the first coroutine. Not sure why it's nested at all.
Yeah I figured it out, turns out it was nothing to do with the code I posted. lol. It was how I was handling the enemyList. All fixed now and works as intended π
Thank you though π
using System.Collections.Generic;
using UnityEngine;
public class SpawnManager : MonoBehaviour
{
public GameObject[] animalPrefabs;
private float spawnRangeX = 20;
private float spawnPosZ = 20;
private float startDelay = 2;
private float spawnInterval = 1.5f;
// Start is called before the first frame update
void Start()
{
InvokeRepeating("SpawnRandomAnimal", startDelay, spawnInterval);
}
// Update is called once per frame
void Update()
{
void SpawnRandomAnimal()
{
int animalIndex = Random.Range(0, animalPrefabs.Length);
Vector3 spawnPos = new Vector3(Random.Range(-spawnRangeX, spawnRangeX), 0, spawnPosZ);
Instantiate(animalPrefabs[animalIndex], spawnPos, animalPrefabs[animalIndex].transform.rotation);
}
}
}```
Every time I try to invoke the SpawnRandomAnimal it just repeats this in the console and idk what I am doing.
You don't need to get the transform component.
And you're only setting x and y positions to a Vector3, you're missing the z
i am missing the z, because it is unity 2d*
DonΒ΄t forget to remove the dot between GetComponent and < as well
a Vector3 needs 3 floats, x, y, z
That might be the issue.
thank you, it is now fixed
Partybear.
One more thing.
Instead of using Vector3, try using Vector2.
Vector2 uses only X and Y
i dont know, im just doing what the tutorial says so yeah
don't think that will work - position only takes in a Vector3 iirc. Might be better off doing ``new Vector3(coordenada_x_camera, transform.position.y, 0f);`
Dang.
also i need help here 
it did work, its to make the sky follow the camera
I think the camera does need a Vector3.z component even if it's a 2D game?
Because the camera still exists in 3D space.
yup
Could be wrong tought tbh, I don't do 2D. lol.
Yeah, so just add ((camera)).position.z to your Vector3 and I think that'll be fine.
Looks like you may have weird 'edge' pixels on your sprite?
it isnt suppossed to be like that
Photoshop has a habit on some images of kind've adding transparency on the very edge pixels.

i didnt make these assets, the tutorial guy told us to do it like this
and it looks good in the tutorial guy
Okay, well it looks like you're 'stretching' your sprites, so their edges are going to be 'mushed' up.
Don't use tutorials from anybody except Dani, Brackeys and Code Monkey. Cause you finish that tutorial and you get a ton of errors and then there is no tutorial to fix it.
That is my advice.
uhhh im using a tutorial made by a teacher from my college so thats why i used that , and it is in my language so i can understand that better.
dang.
Keep the dimensions of the sprites the same as the tutorial. While you're learning don't change anything at all, do the tutorial 1-1, best advice I can give.
can sumone help pls
everyone gone now :(
fixed it
ok the issue was because i painted two tile sprites in the same spot, thats why
i accidently put the code in update
Ah fair enough.
Literally just about to reply. lol.
srry-
Nah sokay, cool that you figured it out for yourself π
I finally created my fist game
it was not that hard except for the fact that I kept forgetting to build it 4 times so I had to start overπ
Configure your !ide before asking for help in general
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
hey there, i got a code problem and i dont know why is having this error
it says that is in that line
either your AudioSource variable is null or it has no clip assigned to it
oh and you also need to pay attention to the warnings in your IDE because that Play call is irrelevant to the if statement
either you reassign it in the code or you have more than one component where one of them does not have it assigned
why is the semicolon there?
what do you mean with that?
how come you have semicolon in this line?
if (collision.gameObject);
what is it doing in there?
semicolon means " ; "
i wanna if an object colission, the audio reproduces
Guys pls help me this is how its supposed to work vs how it works in build
is no need in that case?
yes, but why is semicolon in there?
please learn how c# works. there are beginner courses pinned in this channel to help you get started
check the player !logs for error messages. and also don't expect us to know what is going on without relevant code
i dont know
if (collision.gameObject)
{
Dano.Play();
}
And please don't get me wrong, but I am strongly against language specific symbols. I guess none would like to work with a code if methods would be called in let's say arabic or chinese.
sorry
How savage would that be?
void ει£δ»ΆδΊ()
{
}
?
i think he meant to ping someone else
nah, don't be sorry. It's just kind of friendly suggestion to not use language specific symbols
wait nvm oops
Nah it's addressed to Sasaki person π
but why is that semicolon there?
how much coding knowledge do you have?
i know, im just used to use the symbols and i forgot to no use them
they don't know why. Because common knowledge is that every line of code should end with semicolon I think or jsut a typo π
if it was a typo its easily spottable
none, we are just doing a school proyect and they dont teach us
i mean, we are studyng animation and 3D, and they want we to program a game with 0 knowledge of coding
oh... okay... anyways, the semicolon, the first one, should not be there
π i would really recommend at least a couple hours of watching tutorials and practice because thats a very big mistake
other than that I am not sure if the collision.gameObject part is correct
that is the worst schooling lesson ive ever heard, you should consider unenrolling
we have 4-5 proyects per week, we have very short time for fisishing them
post the problem and people will decide if they can
dont ask just to ask, post your question in detail
they say that in our grade is not necesary but then they ask for a game coded by us
then do so
so removing semicolon fixes the errors?
what class is this for? and this is for university i assume?
they only teached us about the lenguage (sush a what is void, if loop...)
nothing more
there's no if loop
very poor introduction from what i'm understanding
theres for each and for loop
i think she means basic topics + typo
no :c
what is your code now?
its a profesional cycle
look at that, you finally showed your code and proved i was right all along! you are reassigning your Dano variable in Start
there is built in Unity function: OnTriggerEnter()
i know, but all my game is working with colliders
yours won't work like you intend it if you don't use the built in unity method
i mean colision
yes, so you should use the built in collision detection method
that is what OnTriggerEnter is for
a trigger is a type of collision
oh
wtf are you on about? OnCollisionEnter is a built in "collision detection method". and they've shown that it is working considering the runtime exception is being thrown from within there
void OnTriggerEnter(Collider other)
{
}
``` this is the method... and it will work for 3d object.
the only things wrong with their code are the reassignment of Dano in Start since they assigned it in the inspector. and the if statement inside of OnCollisionEnter is pointless since it's just nullchecking the colliding object which can never be null
well... you might be right. And I might be wrong. But where exactly am I wrong by suggesting to use OnTriggerEnter? π
that was next thing I was going to point out
well considering that won't work with their current setup since OnCollisionEnter is working just fine, the entire suggestion is wrong
yeah, entire. Starting with suggesting to remove the semicolon π
im lost right know 
its ok dont take it personally π
remove the if statement in OnCollisionEnter and the line in Start and everything should work just fine
ignore almost everything that TylerWin suggested
I am getting used to people in this server slowly π
one more pro than another. Love to correct others rather than involve themselves and help people π
except i was the one helping with their issue
said 0 words about semicolon ) A+ help
just because i didn't specifically say the word semicolon (which by the way was entirely unrelated to their issue and did not change the logic in any way) does not mean i didn't point out that mistake. i pointed it out before you
#π»βcode-beginner message
if you are going to help people, at least focus on the actual issue before derailing the entire conversation for another mistake and then suggesting that they should be using OnTriggerEnter instead of OnCollisionEnter when their OnCollisionEnter method is already working just fine
honestly sounds like an xy problem, why would anyone want an audio to play ANYTIME a gamobj collides with something π€·ββοΈ
prob dont know tag useages
that's not what an XY Problem is
you mean like this?
yes. your previous if statement was just checking that collision.gameObject was not null, but it's not possible for it to be null there
though you do probably want some other logic there such as checking a tag or for a component if you don't want the sound to play every time it collides
Hey, I'm trying to make a cutscene scene consisting of 5 frames that change every 4 seconds. Currently my plan is to import the frames with an array, iterate through, and modify the z position of the first frame, then the second frame and so on to have them transition until the timer reaches zero and the scene is loaded. What would be the best way to achieve this intended behavior, since it seems like I can't modify the z-position of the image?
you know what i intended, close enough
you have to create a vector var first, then modify that
it have to play the sound each time it colides, the player have 3 lifes in total, so every time he lost one life he will play the hurt sound
cool then that should work just fine
unless of course this is on the player and it can collide with things like the ground or environment without getting hurt
@slender nymph you are totally right. This is exactly what was causing that exception error.
Still... don't you think it was useful to ask them (what I did) why is the semicolon in there and also suggest for them to use proper unity method for collision detection?
I mean you are right to pick up on me, no questions asked, but I mean...
again, i did point out the issue with the semicolon. #π»βcode-beginner message
it still having the error π
did you remove the line from the Start method?
yes, make sure you have saved and unity recompiled. and make sure that the AudioSource is still assigned in the inspector
if it is and you still receive the error then you have a copy of the component in the scene without it assigned
yaay π
sorry for inconvenience, im really lost at this
no worries, we're always here to help π
yeah... true. And I was slowly getting to the point where I was about to ask what if(collision.gameObject) is trying to achieve in there... actually right when you pinged me I was busy typing something like "not sure what if (collision.gameObject) is trying to do there" π
Thx
I have a prefab with some serialized stuff in it. Do I have to everytime assign the things whenever I drag and drop the prefab into my scene?
if they are scene objects, then yes. If they are prefab references, then no
if you want to assign scene objects to those fields, then yeah you'll need to drag the relevant objects in. if you want assets to be assigned then then you can drag the references into the prefab and they will stay assigned when you drag the object into the scene
All right thanks.
Hi guys how to set position to localPosition when setting parent, like i have an object and i want to stick it to an other object
how to set position to localPosition when setting parent
could you elaborate on what exactly you mean by this
i want to set my object position in the same position when he hit the player like if you get hit by an arrow it stick at the position, because when i setParent my object position is set to 0
when you call SetParent pass true for the worldPositionStays
its not working the object is too low in y axis
if it's position is changing at all when doing that then something else is affecting the position and you would need to show code and how the objects are set up
i'm using navMesh agent btw
unrelated to the issue, but you should be using the CompareTag method rather than string equality to check an object's tag
and please show how these objects are set up and if you could, a video (or at least some screenshots) of the issue
wdym by set up ?
like the inspectors for these objects. you know, how they are set up in the scene
the scale can be a problem ? because my parent is scale to 0.5
if you just do what's asked, you'll get your problem solved quicker
the last line of code at 46, cs private void OnCollisionEnter2D(Collision2D collision) {}, doesnt turn cs OnCollisionEnter2D() as blue but as yellow
!code paste this properly please
π 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 tried
it's the same color as your other unity messages. if vs code is configured then it's fine
ah sorry i just realized youre talking about color, nvm then
Do you guys name variables specific to your game, or try to abstract the names away as much as possible?
For example, in my game, I have a variable fuelPower, which essentially is just mana. Should I name it mana instead in case the name changes in the future?
making variables specific to you is just good practice (its what I do so its easier to remember what it is)
if you encounter name changes, change it in your script at the same time as in your scene
(so you dont lose track)
why would you use mana, if mana isn't a thing in your game? You use names that make sense to what you're developing
your variables should have meaningful names that immediately convey what their purpose is. if you have a Jetpack class with a mana variable, that doesn't immediately convey that it is the fuel available to the Jetpack unless you use mana as fuel in other places as well and the name makes sense in context
wizard high tech space invaders, duh π
But then mana would be a thing in the game π
you shouldn't expect to change your variable names. use meaningful or descriptive names based on their intent . . .
It's a card game in a sci-fi setting. So players DO have literal mana to spend on cards each turn :D It's just that it is represented as "fuel power" for the setting
And maybe that name will change, not because of the variable itself, but because of the lore, setting, etc.
if it's a generic class/lib that you plan to reuse, then try and keep the names generic too.
IE: I have a Health script I've reused many times, but in the game, 'health' might be time, energy, mana etc, etc.
other than that I find that keeping it consistent is the best way to keep your 'mental map' of the code up to date.
so in your case if you call it mana in the script, then have a FuelPowerUIComponent, and a PowerTracker component etc, etc, then you end up with 4-5 different names for the same concept, and that can become confusing quick.
then call it fuel power. i encountered a similar issue in the past and never changed my var names so it made it difficult for future recollection
Okay gotcha guys, thanks
the tutorial im watching says that OnCollisionEnter2D should NOT be yellow, also my vs code is configured
is the tutorial using visual studio rather than vs code? because visual studio will highligh unity messages as blue. i don't think vs code does, but if it is configured then it is already working correctly
It depends on your settings, and which IDE you use, by default it's yellow in VSC
I'm gonna go ahead and say that the person making that tutorial doesn't know what they're talking about
im probably stupid but idk what are the differences
im gonna send a screenshot and tell me if is VS studio or not, sorry for that
all that really matters here is that vs code is configured
OK so putting being held within an if statement did help, there's just a weird thing where if you pick up a slime while looking down it is sideways
(being held works by becoming a temporary child of the player, going into a grab slot. and looking at the player main camera)
yes, this is visual studio not vs code. in visual studio unity messages like Awake, Update, and OnCollisionEnter are highlighted in blue when configured correctly
ok thank you
as long as when you type "oncol" intellisens pops up with suggested completes.. don't worry about the colour
it does so im fine
reset the child rotation to the quaternion identity then try it
the goal is to try to get the child to rotate only on the y
but it looks like when childing and doing lookrotation it's introducing some roll into the equation
yeah I wish there was a way to make its roll set but the only thing I came across was freezing rigidbody rotation and that wont work
I dealt with a similar situation quite a while ago and kinda just played with a bunch of ideas until I got it
angleaxis can help too, as you can manually set the rotation per axis, but it's a bit of work
try resetting the child rotation before childing too for the heck of it
really odd it is introducing roll
lookrotation by default will rotate using y axis using world up
yeah that's there to get the slime to look at ya
Could be something else somewhere in the code maybe? I didnt know what all would be relevant and I feel weird uploading lots of code lol but there's this
here's a better idea. When you pick up the object, reset the position and rotation to zero/identity, now offset the postion of the child by an amount of units on the local z
this should now offset the object directly in front of you with similar rotations, now by using lookrotation, or angleaxis on the y, rotate it towards the character
from there, play around with your offsets, you can probably offset it a bit more to the x+ axis local to keep it on the side a bit like you're doing too, and then using lookrotation then
Ah, sorry image didn't load for some reason, but yeah you're doing similar to what I said, but try introducing some units on the z+ axis if you arent
https://gdl.space/giwunetere.cs Why does the gravity scale set to 0?
im no good at math but this shouldnt be 0
i think its because you are using int values
integer division
5 / 10 is 0 with a remainder of 5
so 10 should be 10f?
yep
Also if you want the random number to be a float the inputs need to be floats too
right now you'll only get 4 5 or 6 precisely
hey so i want to store the current scene and then load it later how would i do this i tried just saving it as a Scene variable it doesnt seem to work though
wdym by "store the current scene"?
i want random floats but with exactly 0.1 in between
Scene currentScene = SceneManager.GetActiveScene();
but what do you mean by this
just the name of it?
Or the actual state of the scene?
do you mean save data?
with all the objects as they are
is this possible?
You have to pick exactly which data you want to save and save it
you can't just take a snapshot
i meant more just the scene name and stuff
so i can go back to that scene
SceneManager.LoadScene(saveObject.currentScene.name);
so this?
you would need to do something like
int tenths = Random.Range(40, 71);
float gravityScale = tenths * 0.1f;```
I mean just save the name
saveObject.sceneName
don't save the Scene object it's not particularly useful to you
I think this is what you said, right? But no matter what values (1f, -1f, -2f, 2f ,3f) it seems to still be on its side or upside down π
so save a string variable instead of a Scene variable
yes
No, I mean the position. Try adding another unit in the z+
ah crap, sorry read that wrong
Im feeling like it's just too close to the pivot and getting a zero direction
I would try to get it working without offset the pos on the x or y first
got it, gotta brb rq then will update
If you want it closer to the camera, you may want to make an empty gameobject behind the camera to look at
Could anyone help me with my code, the floats and all show up, it just wont work, and i dont know which parts not working
i have just fixed it π§
How do I send a long strain of code?
!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.
now explain the issue
The character wont jump, I am not getting an error from unity, and i dont know the language well enough to be able to spot whats wrong, it might be line 15
never mind sorry, as i posted it i saw that i hadnt put the true value in
This is pointless btw
if (grounded) {}
else if (!grounded) {}
You can just do
if (grounded) {}
else {}
Because if grounded is false, then it won't pass the first condition, so it's else will.. as a bool can only be true or false
Thank you, I'll change that now
you have a func to set readyToJump to true but not one to set it to false? π
if(!grounded) { return; }
you should consider just calling a func that changes the bools value to its opposite by using readyToJump != readyToJump
this will let you be much more organized
yes, this, if you don't need anything further after the if statement
Thank you
@timber tide OK yeah it is further from the player now
what happens if i start a coroutine on a gameobject then start the same coroutien again?
It runs two of them
The same as calling the same method multiple times
is it not possible to like stop the preexisting one and start a new one?
It's possible if you have a reference
thanks will looks into this
try getting it to rotate nicely without the x/y offset
could always comment out lookrotation and apply the child and offset, go back to scene, and spin it on the y to see if it's correct
Hi i wanted to find a tutorial for a game mechanic like the one described in the screenshot for my cooking game but i am just not able to find one. Maybe someone here can find one or at least knows the name of that type of mechanic.
Could you send the Stack Overflow link?
so this is similar to the timing arcade game?
cant remember what its called but a line follows a circle and you have to click a button before the moving line goes past your goal
yes exactly!
i really cant remember what the game is called and i cant find it π€·ββοΈ
I am not able to install unity editor I am getting error how to solve it
Editor application
Install failed: Validation Failed
not a coding question but !install
- Make sure you have enough space including on
C:drive. - Check that it's not being blocked by antivirus/security programs.
- Look through the logs for a real reason why the setup fails they are pinned [here](#π»βunity-talk message).
If you still have issues, perform a clean install in another location:
- Install the Hub and Unity in a non-system drive or a clean new folder in the root of
C:drive. - Failing that use the recovery Refresh option or reinstall OS entirely then repeat the previous step.
Went through 6.5 pages on the asset store to find it, because I couldn't remember the name
getting this error i have around 200gb space in my drive
not a code question. but go through the checklist below π !install
- Make sure you have enough space including on
C:drive. - Check that it's not being blocked by antivirus/security programs.
- Look through the logs for a real reason why the setup fails they are pinned [here](#π»βunity-talk message).
If you still have issues, perform a clean install in another location:
- Install the Hub and Unity in a non-system drive or a clean new folder in the root of
C:drive. - Failing that use the recovery Refresh option or reinstall OS entirely then repeat the previous step.
It feels like part of the issue is if I offset the rotation, it will, but depending on how much it decided to be rotated already
Like I grab the slime from the side and it's rotated a little. I grab it looking down and it's upside down instead of sideways. Anyway building and testing commenting out lookrotation with a manual rotation offset
i love deja vu
yeah it is still rotating when I pick it up... ahhhhhhhhhh
Thank you so much i could fine a tutorial with that info <3
you don't change it. you can AddListener via code to subscribe the one you want subscribed and you can RemoveListener to remove subscribed methods (this cannot remove persistent listeners)
lol they deleted it as i answered
i just realised i can toggle it with a bool anyway
lmao sorry man
thanks tho
can anyone help me with an error i have?
perhaps if you share it (:
ok can anyone help whit this error im very new to this so this is my error: Library\PackageCache\com.unity.ai.navigation@1.1.5\Editor\NavMeshAssetManager.cs(172,65): error CS1061: 'NavMeshSurface' does not contain a definition for 'IsPartOfPrefab' and no accessible extension method 'IsPartOfPrefab' accepting a first argument of type 'NavMeshSurface' could be found (are you missing a using directive or an assembly reference?)
make sure your packages are up to date, and if the issue persists after updating then close the project, delete the Library folder from within your project (only that folder and its contents) then open unity again and it will regenerate the cache
ok thanks
Just ran into this funny error I asumme just do what it says on the tin but im curious why its happening in the first place
Because you're trying to destroy a file
Probably a prefab
Ah yes I am, Is that bad practice?
Well, presumably you don't want to delete the file off your computer forever, so yes
it's probably not what you meant to do, no
figured it out!!! it was beacuse I started this using LookAt I believe. I just deleted everything and then set it locally manually. @timber tide in case you wanted to know
Oh I think im stupid that means im trying to destroy the prefab not the instantiated object?
An instantiated object is not a prefab. A prefab is a file on disk that you can copy to put into the scene. The copy is no longer a prefab
If you want to destroy the copy, you would need to call destroy on that, not the prefab it was copied from
Yeah this is what i've done, how stupid of me. Thank god unity has some built in protection for that, Im glad I checked here first cause I was just gonna do DestroyImmediate
Quaternion cameraTargetRotation = Quaternion.Euler(0f, 180f, 0f);
cameraContainer.transform.rotation = cameraTargetRotation;
Quaternion cameraTargetRotation = Quaternion.Euler(0f, 0f, 0f);
cameraContainer.transform.rotation = cameraTargetRotation;
why does 180f translate to y = -180 and 0f translate to y = 180f?
eulerAngles for a quaternion are interpreted at the time they are accessed. there are any number of values that can express the same rotation, do not rely on specific values to be displayed/returned
how can i get specific values to be returned?
you don't
The editor does store euler angles strictly for the purpose of letting you type something like 3600 into the rotation field, but those aren't actually used by the Transform component
When you construct a quaternion out of euler angles, that quaternion has no memory of the euler angles you used
I wouldn't expect the second example to give you [0, 180, 0] unless this thing is parented to another object, though
If you're relying on specific euler angles, then keep track of the euler angles yourself. The conversion of euler to quaternion to euler will always eventually give you different values that lead to the same rotation
(you're setting world-space rotations, and the inspector shows local-space rotations, so having a parent matters here)
it is parented to another object yes
im trying to get a camera to always face one way when the character faces another way
this code makes the camera face the -Z direction, then the +Z direction
a transform with Quaternion.identity for its world-space rotation (which is what Quaternion.Euler(0,0,0) gives you) will face world +Z
Hello everyone! I'm new here. So I am starting my first First Person Movement and Camera, is there anyone who could help with that?
I have the camera and Capsule set up already.
what help are you looking for? if you are looking for someone to guide you through creating those, then find a tutorial. if you need help with your implementation then show your code and describe the issue you are experiencing with it
!learn
:teacher: Unity Learn β
Over 750 hours of free live and on-demand learning content for all levels of experience!
Thank you!
Aye nice that works too. If you want to stop your slimes from clipping into the ground now when picked up, youll need to force it to render on top.
Usually you can just use render objects and disable writing to depth
yeah there are a few issues around rendering... their outline disappears when looking at the water as well
Then switch layers when picking them up
is there a way to keep reference to an object afters its been destroyed like a character for example?
public class MatchTrackerData
{
public Character player1;
public Character player2;
public Character player3;
public Character player4;
public Character winner;
}
If it's been destroyed what are you trying to reference
i just want to keep data from it, like KOs and deaths and stuff
from each character
Then that data will need to be on something that isn't destroyed
then keep just that data, why do you need a reference to the destroyed object?
idk cus it feels tedious to have player1Kills and player1Deaths and player2Kills and so on
i thought it would be easier to just keep a copy of the character class
but i forgot when it gets destroyed t he reference is useless
well yes, that is a terrible way to do that
you can create a class or struct that contains the data for a single player and pass that around when necessary for each player
that works
i'll try that
im trying to invoke this unityevent but when i add the scriptable object i get nullreferenceerror. i thought i could call scriptable object public methods like this. what am i doing wrong?
you can, the error is likely inside that Raise method
or perhaps somewhere else entirely, you'd have to show the error message
Just keep in mind, any time you feel like numbering your variables (player1Kills), something is going wrong.
the raise method is empty though its just for the listeners to do something off it
when i only have the fence wall setactive false i get no errors
so you have nothing at all inside of VoidEventSO.Raise? not even an event invocation in there?
sorry youre right here is the code
yeah so then something subscribed to that event is what is throwing the NRE
ohhh because the object which has the listener is disabled?
a disabled object would not throw an exception just because it is disabled. whatever code is running as a result of that event being invoked is throwing the exception
tyvm ill look into it
show the full stack trace of the error
your error is on line 34 of QuestAnimationManager
ty its clear now
if I have the inventorySlot script referenced, can I change the color of the image component? Or do I also need to get the image or gameobject directly?
im a bit confused and lsot , how can i get rid of this warning π
nvm saw
the problem
mb
you can probably just make inventorySlot.gameobject.getComponent<Image>() or something like that
put reference to Image in Inventory slot script, with a SerializeField
You should always try to use serialized references instead of a bunch of GetComponent calls
It's fine to create components whose only real job is to be a bag of references
(you'll often wind up adding functionality to them later)
There has to be a more effective way of doing code on inventory slots corresponding to numpad keys, but I cannot think of it
I want the player to be able to tap the button to build the blueprint, and hold it down to self destruct the building
new input system would probably be less of a pain, aside from initial learning curve
My game object won't disable on collision, I've tried multiple methods like disabling the game object with a certain tag on collision.
need to show code
also make sure run through these steps
https://unity.huh.how/physics-messages
thanks but they told me that already
Top is game object disable, bottom is script disable (At least that's what I hope for it to do) both aren't working.
I'm pretty new to unity
go through the steps I've linked you, you have to Debug the trigger/collision event, outside the tags
why == tag in one method and CompareTag in the other?
Is the function even running? Put a log outside the if
also not sure what goal of that collision one is...if powerup collides with powerup then destroy the other?
oh
bro how du u freeze x rotation via code? rb component
the docs arent really helping
constraint
hey yall im trying to change a text but the console said i did not refer to it in the editor (even tho i did) i usually solve this issue by refering to a tag in the code editor which works with object but i dnt know ho to apply it to tect any ideas ?
Write the 2D one lol
there is no rotation on x for RB2D
well u said rotation
Why'd you say rotation then
Literally tells you exactly what to write
RigidbodyConstraints2D
oh my bad
ah i was trying Rigidbody2DConstraints
lol
The error message also said the right thing
does your IDE not do this when you type=
Be sure to read the errors carefully
That took forever to upload!
What is the best way to design a point and click locomotion?
Nav Mesh?
And if the character needs to walk around objects, should they be a Rigid Body or Character Controller?
Brilliant, thank you so much!
Hello, I'm trying to make a sprite flip using it's rotation with the animation controller, but I'm having some struggle
Hi im trying to add a particle to the players weapon game object. The code works, but the issue i have is the particle follows the game object, which is correct becuase its a child of weapon. But how can i stop that i just want the particle of the weapon container to be the starting point ```public void MeleeParticleEffect(GameObject effectPrefab)
{
GameObject activeWeapon = FindActiveWeapon(weaponHolder);
if (effectPrefab != null && activeWeapon != null)
{
GameObject effectInstance = Instantiate(effectPrefab, weaponHolder.transform.position, weaponHolder.transform.rotation, weaponHolder.transform);
effectInstance.transform.localPosition = Vector3.zero;
Destroy(effectInstance, effectInstance.GetComponent<ParticleSystem>().main.duration);
}
}```
whats the problem? what are we looking at? whats supposed to happen?
So basically after it finishes the "flip" animation it returns to the normal animation, but it flips back to the right, is there any way to keep the rotation to the left?
i would start by not using triggers
keep a bool that tracks your facing direction
like IsFacingRight
or something
simulate the particle system in world space
I tried using a float that stores the horizontal input, but then it just keeps flipping continously
well if you did something like
if(xInput > 0) animator.SetBool("IsFacingRight", true)
else if(xInput < 0) animator.SetBool("IsFacingRight", false)
or something
it would not constantly flip
triggers would
Would a two dimensional array be the preferred way to create a graph in Unity or is there an explicit type for it?
I found https://docs.unity3d.com/Packages/com.unity.graphtools.foundation@0.8/manual/graphview-overview.html
but it seems that is for UI only
thanks it still has some rotation on it.
then your transitions are setup all wrong
I would suggest studying up the animator further
the first part in the video i how i want the particle to work, but when i attack you see that it follows the rotation of the hand. I dont want that
just don't make it a child of the player
Probably yes, but there aren't much tutorials on animators, and it's just so confusing
ok if i do that i have to change the y axis of the particle but if i wanted to also use it again on another player that maybe bigger or smaller feels like im hard coding it. i was trying to make it flexiable
what do you mean, there are so many tutorials on animator lol
its confusing cause its new, look at multiple sources and eventually it looks less scary
Thanks anyway
sry but idk what you're looking for, if explain it further will just confuse you and i dont feel like going back n forth to give a crash course on animator
this is for making editor windows, yes
A two-dimensional list gives you an adjacency list, where each vertex in the graph has a list of vertices that it connects to
a 2D array is closer to an adjacency matrix, which would be a bool[][] that tells you if two vertices have an edge between them
I tend to do adjacency lists. They're particularly good for sparse graphs
if each galaxy only connects to a few other galaxies, then it's very efficiecnt to have each galaxy store its neighbors
Im creating a mobile shooter and on my right stick i want to rotate and shoot. Everything works so far, but when i shoot, i have to tap the button. How can i repeat my code as long as im holding the button down? Im triggering the Input Action with the Unity "On-Screen Button" script
void Update() {
if (buttonIsHeldDown) {
// do stuff
}
}```
the input system is for handling input not driving game logic.
!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.
Okay, thank you! π
So when i try to load up my project it just gives me a this error that i cant fix here's the part of the code to it
else if (surface.IsPartOfPrefab())
{
var prefabStage = PrefabStageUtility.GetPrefabStage(surface.gameObject);
#if UNITY_2020_1_OR_NEWER
var assetPath = prefabStage.assetPath;
#else
var assetPath = prefabStage.prefabAssetPath;
#endif
if (!string.IsNullOrEmpty(assetPath))
{
var prefabDirectoryName = Path.GetDirectoryName(assetPath);
if (!string.IsNullOrEmpty(prefabDirectoryName))
targetPath = prefabDirectoryName;
}
}
Duh, what error? Or are we meant to guess?
oh sorry let me send rq
unity.ai.navigation@1.1.5\Editor\NavMeshAssetManager.cs(47,30): error CS1061: 'NavMeshSurface' does not contain a definition for 'IsPartOfPrefab' and no accessible extension method 'IsPartOfPrefab' accepting a first argument of type 'NavMeshSurface' could be found (are you missing a using directive or an assembly reference?)
there
So where does this code come from?
you shouldn't be attempting to modify unity packages code. make sure all of your packages are up to date and if the issue persists after updating packages then close the editor, delete the library folder from within your project then open the project again so that unity regenerates the package cache
i didnt
it comes from the NavMeshAssetManager script
right but you're posting the code here and asking for help with it as if you intend to attempt to fix it yourself. follow the steps i just gave you to fix it
ok
I can see that but the docs do not mention a IsPartOfPrefab method