#💻┃code-beginner
1 messages · Page 520 of 1
Look it up on asset store, obviously tons of assets exists for character controllers
That makes sense
Im trying to ground my player again when they jump using character controller, the issue is I can't seem to modify their velocity which is from my understanding the typical way, and I also want to apply gravity as well so its not like an abrupt landing. It's more "smooth"
https://hatebin.com/uueedmmlit here is my current code
Typical way of doing what?
I want to make my player smoothly jump and then go back to the ground, currently it looks more like they are teleporting
If the harsh landing is the only problem you are trying to solve, I would just make the camera follow the target position more smoothly with lerp smoothing or something like that
Teleporting sounds weird. Can you show us what is actually looks like with a video recording or something?
Yea one second
On the left, you can see when I press space, and even on the right it doesn't really look like they are jumping, its more like they are just "teleporting" to that position or "cutting" (using video terms)
clearly there's no gravity in play
Im not really sure how gravity works without using a rigid body
Im sure I have to do it myself though physics is not something im good at either 
watch a tutorial. You keep z velocity which you decrement each frame to make downwards acceleration and increase the up velocity when you jump
I don't particularly like tutorials tbh, but I will try and find one
Or any other resource on gravity. It's quite simple formula in the end
How do you even access the velocity of a character controller
I know you can get it, but you can't modify it
unity bug
.velocity?
it doesn't take much to look at 'UnityEditor.Graphs.Edge' and see it's a editor bug to do with a window using a graph
so yes
Why would you? You call .Move when you have a new velocity to apply

So if I wanted to gradually ground the player, i'd just call .Move on the y every frame?
Guess so
ok
can someone show me how to make a move script
no
can u give me one atleast
no
no, !learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
no, we can help with yours but we won't make you one
alright do i send it??
you seem to think that there is just 'A move script', that is not the case, every 'move' script is different
using UnityEngine;
public class MoveObjects : MonoBehaviour
{
public GameObject object1;
public GameObject object2;
public GameObject object3;
public float moveSpeed = 5f;
void Update()
{
MoveObject(object1);
MoveObject(object2);
MoveObject(object3);
}
void MoveObject(GameObject obj)
{
if (obj != null)
{
float horizontal = Input.GetAxis("Horizontal"); // A/D or Left/Right Arrow
float vertical = Input.GetAxis("Vertical"); // W/S or Up/Down Arrow
Vector3 movement = new Vector3(horizontal, 0f, vertical) * moveSpeed * Time.deltaTime;
obj.transform.Translate(movement);
}
}
}
whats wrong here
you tell me? does it not do anything? do you get errors? something else?
tells me this Can't add script behaviour 'PlayerController'. The script needs to derive from MonoBehaviour!
can u like help me make it work
and is that script PlayerController
can I assume you can read?
Nothing wrong with the code from what I see but you showing us MoveObjects and error screaming about PlayerController sounds like something doesn't add up
except he's using deltaTime, but we'll overlook that atm
How are we supposed to know?
Apparently there is something wrong, and you would know
Time to share the error or issue
no like i mean why does it say that my script needs mono behaviour
am rlly new to unity and coding to be exact
He did, apparently for a completely different script than the one he posted
Can you screenshot your editor?
Like, full editor
wdym
Screenshot your Visual Studio screen
There you go. Configure your editor !ide
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
• :question: Other/None
Come back when you have done that
Also, I suggest you use Visual Studio or Rider for Unity development
Its better to just use visual studio community
wut am i using??
Visual Studio Code
your using vs code
so its not good?
It's harder to work with and VS has better support
So please try using that instead or Rider
k lemme download rider
Check the bot's message for setting up Unity for the IDE you use
am mentally unstable
we see
Can you not?
bro idc ab you puttinf parrot emoji's on my messages u just typed it faster
Hi, please share a screenshot of the exception
using UnityEngine;
public class InfoBehaviour : MonoBehaviour {
const float SPEED = 6f;
[SerializeField]
Transform SectionInfo;
Vector3 desiredScale = Vector3.zero;
// Update is called once per frame
void Update() {
SectionInfo.localScale = Vector3.Lerp(SectionInfo.localScale, desiredScale, Time.deltaTime * SPEED);
}
public void OpenInfo() {
desiredScale = Vector3.one;
}
public void CloseInfo()
{
desiredScale = Vector3.zero;
}
}
not unless you tell what they are
Show the console errors.
Can you screenshot your Visual Studio/Visual Studio Code/Rider editor please?
wut do i choose
I was watching this video and trying this project in 3D Core project : https://www.youtube.com/watch?v=OE66gtiF8QQ&list=PLA-J1cIDvBRzSUTQikQOOxq5YJf_9AhRR&index=1&t=1s
In this Augmented Reality Tutorial Matthew Hallberg is going to show us how to do gaze interactions in Unity with ARFoundation with ARkit and ARcore.
Stay in Touch with Third Aurora
Website: https://thirdaurora.com/
Facebook: https://www.facebook.com/Third-Aurora/
Instagram: https://www.i...
It's a theme, choose yourself
oh kk
Please screenshot your editor
It's probably not configured
You haven't provided the necessary information #💻┃code-beginner message
I was correct, please configure your !ide first
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
• :question: Other/None
what is IDE?
After that, your editor will correctly point out the error
IDE = your editor
In this case Visual Studio
Can we connect on call and I will share the screen. I got some errors
The issue is your misconfigured editor. Do that first
The errors become clear after that, because the editor will help you with it
how to do that
Read the bot message
Follow the steps for configuring for Visual Studio
Depending on if you downloaded VS through Unity on manually you pick the correct link
This one
Run the Visual Studio installer again and you'll be able to modify your current installation. You'll need to follow the steps again and make sure everything is accounted for. Common mistakes would be not adding the Unity Workload to Visual Studio - this had to be done manually. Other than that, the section about external tools might be the issue.
when i open the script it opens visual studio instead of jetbrains rider how do i fix this????
Check your external tools section
am dum idk wut dat is
in unity hub??
I assume you mean Visual Studio Code since the whole thing was to change from that one?
In the Unity Editor.
mhm
am so lost rn
i want to use rider instead of visual studio code
Did you try changing your external script editor?
EXPLAIN TO ME WUT DAT IS'
where do i choose my preffered scripting editor
Pick Rider instead of Visual Studio (Code)
Click the link
I'm going to assume you simply do not know how to ask where to find the preference window:
In the Unity Editor, select the Edit > Preferences menu.
ok
You are using Visual Studio. You just need to configure it
If you follow the bot steps, then you just have to change a few settings
Did you install VS manually or using the Unity Hub?
Did you verify all of the steps again?
I checked the steps, its confusing to me
Start with this, which one?
Its mentioning to select unity development after fresh installation of visual studio
Yes, as a workload
I installed VR Manually and Unity Hub separataley
So what's the issue? Seems clear to me
Open visual studio installer, modify your VS that is listed, make sure Unity workload is installed
Note VS is not the same as VS installer.
Run the installer and select modify. Make sure the workload is installed @serene sage
What's with the parroting today
Surely something only has to be explained by a single person?
VR = VS = Visual Studio? I'm confused
Has anyone here tried the behaviour package of unity?
Should I need to try this way?
My Visual studio is in purple and on youtube it shows blue?
Which color VS is best for Unity codes?
No? You don't need extensions at all
You need the workload, and then you need to set up Unity to open VS as the external script editor
What's wrong with the steps in the bot message? You have been pointed to it multiple times now, and it's very clear on what to do
I didn't find workload in unity or VS
You're using Visual Studio. They're using Visual Studio Code. Two completely different software. Visual Studio is the preferred software. Follow the installation guides to have VS properly configured. I've got to go, good luck.
Follow the steps
ok, I will try again
Finally got the option for workloads from installer
You will not find the Workload tab in the Unity Hub or Unity Editor. Run the installer for Visual Studio (or download it again then run it), select modify and verify that the Unity Workload is selected. If that isn't the issue, try checking the external tools (which would be mentioned at a later step in the installation guide linked). Other than that, try rebooting the Unity Editor, Hub or your computer.
what to do in this case?
They already have the workload working as specified in the previous message
This closes Visual Studio. Save your work, then close and continue
It requires VS to be closed to finish
okie
First time in unity, I can't seem to fix the problem when it is about to collide with the floor and at the same time I press space it gets stuck to a certain animation.
which options should be tick marked for XR Development projects?
Can you post the !code?
Sounds to me that you don't reset the falling bool correctly.
📃 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.
Is this working now? Or should I need to install something else? I still didn't get it, what's wrong with my code. I tried to check but couldn't find the compilation errors
Looks good to me
Look at the help you're getting
Time to solve them
actually your very first screenshot shows the error. you have 2 scripts called InfoBehaviour
now it looks like this
you also have a duplicate script FaceCamera
I removed faceCamera, but then I don't know how to fix compile errors
I was programming a 2-player game in Unity 2D and what happens is that the two players cannot move in opposite directions at the same time. sorry if the code is in spanish
!code, use a paste site
📃 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.
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
is there an easier way to serialize dictionaries than using structs? i have a working method its just so encumbering
Use someone else's prebuilt version? https://github.com/azixMcAze/Unity-SerializableDictionary
Note that it's the same thing, just a serialized list of structs.
But uh... basically like anything in software - solve the problem once and reuse it
How to fix the compilation error for previous unity version codes to new unity version codes?
Update anything that uses old functions and parameters to the new versions
!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 is this?
sorry
Here it is 😄
which one is giving error
the last line is the error when using that script in unity project
which line is the error pointing to
line no. 30
I added according to this format says
you're showing the symptoms not the problem
and why is using UnityEngine; commented out
I marked in red. When I am trying to add that script, it says compile error
yeah
This isn't the full code.
I don't know how you do onGround, I don't know when you call PlayerJump.
So still can't say anything about it.
your errors are collapsed
either the video sucks or you copied wrong
In this Augmented Reality Tutorial Matthew Hallberg is going to show us how to do gaze interactions in Unity with ARFoundation with ARkit and ARcore.
Stay in Touch with Third Aurora
Website: https://thirdaurora.com/
Facebook: https://www.facebook.com/Third-Aurora/
Instagram: https://www.i...
this is the video link
I'm not watching 17 minutes of this. Show the relevant part
Show me where in the video they commented out using UnityEngine
for Gaze interaction
also...Unhide/Uncollapse the errors, never have them collapsed
that screen uses only unityengine
since you have no idea what you're doing or know wtf I'm talking about , you need to start with !learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
otherwise this is just a waste of time
you're jumping straight into code without knowing the basics of unity, that isn't going to get you far
okay so most likely 2 cloned scripts
I m begineer in code..
no shit
you do know what the word duplicate means, nothing to do with code
again, time to do the Learn courses
start here then do the Junior path
otherwise you're just wasting your own time not understanding why something is broken
I can't see duplicate scripts
well they are there so search harder
Then look harder
You even have their names
Oh wait, sorry.
https://hatebin.com/upcfyfzosg Here it is tho 😄
also, why the scripts are dark grey. I cannot even uncheck or untick?
Can we have a call here? so that I can share my screen, I m trying since morning, couldn't find errors
it was pointed out the what the issue is, you have to delete duplicates 🤷♂️
you seem to think you can dive into development work without having one single iota of basic computer knowledge, that is never going to work
you can search for duplicate Variables/classes in the IDE and duplicate scripts in the search bar in the project window search bar in unity
I m sorry, I have gone through Unity essentials and VR Development. But things are not quite clear to me through that course. The scripting parts is hard for me and finding errors is more harder,
thats why they have essentials that then goes into junior path.. and if you dont understand it , you do it until it makes sense
this is something that sometimes takes years to learn, you can't shortcut your way to learning
anyways, thank you for helping me out trying to find errors. I will check some more youtube tutorials.
youtube wont teach you anything good, how is a youtube gonna teach you not to have a duplicate file?
Its super need for me. I want to get started with my start-up
if you want to do it for real then start by taking your learning seriously
forget it
your picture you sent shows us errors of duplicate variables/classes which means either a duplicate script or some script you have contains the same name variables/classes
literally if your search your error
they all say the same shit
You found your errors. You have duplicate scripts
Delete the extras
That's it
@serene sage if you will not learn how to solve your errors even when you have been told what they are and how to solve them how do you expect to progress? You cannot seriously expect someone to hold your hand and spoon feed you on every step of your journey
public class Game : Singleton<Game>
{
[field: SerializeField] private Player Player { get; set; }
private void Start()
{
Player = new();
}
}
[Serializable]
internal class Player
{
internal Resources Resources { get; private set; }
public Player()
{
Resources = new(); // This is executed immediately on game start.
}
}
Is there any reason why Player constructor is executed without Start() method when I start the game?
Is there some hidden new() when using [Serializable] or a property?
Hmm, quite difficult.
You can hear that you are jumping.
But you do some strange things with gravity by removing it whilst your grounded.
But the fact that the jump sound triggers, means you set all those booleans again.
But you never actually moved of the ground because of the gravity change. So all those booleans are messed up.
there is indeed. Serialization does the class construction
yes you are correct
because of the inspector
Thanks, I assume it only does that if a constructor has no parameters?
I found and removed it. My unity restarted again and now in console no errors. I am checking for some missing scripts
I wanted to see Player data for testing, but I might need to do extra checks to make sure it doesnt run code that can't run this early.
yes, in fact it does not use a constructor at all it creates the class without calling a constructor
Thank you so much 🙂
But in debug that constructor is being called
same reason you dont have to do new() on a list/array when using the inspector with public/serializefield
because you are newing it, which basically means the class is being constructed twice
Is there a way to delay it but still make it serializable for debugging purposes so I can see Player data at runtime?
It runs before I get a chance to new() it
Unity will indeed call the paramterless constructor
when it creates the object
delay what exactly ?
https://i.gyazo.com/eba620cc9f14566545b995c28c1acc25.png
This is first line that runs on game start
So Player is already created because of serialize field
But it doesnt say that in the call stack
I wanted to delay Player being created by Unity due to [serializefield]
we tested this the other day, it uses Activator.CreateInstance which does not call a constructor
Ideally pervent it
So I can =new() it myself, but I guess thats either too advanced or not possible?
i mean thats just how the inspector works, unless you do [NotSerialized]
Honestly its just for testing purposes so I don't really need it.
unity has to create the object before it can show it
Idk how I did it for other games, but I guess that it serialized it twice, I wonder how many bugs were caused because of that lol
The docs for CreateInstance:
Creates an instance of the type designated by the specified generic type parameter, using the parameterless constructor.
https://learn.microsoft.com/en-us/dotnet/api/system.activator.createinstance?view=net-8.0#system-activator-createinstance-1
I guess if there isn't one actually defined, it will call a do-nothing imaginary constructor
Alright, I will have to live without it then, thanks!
my bad it's FormatterServices.GetUninitializedObject
now that's a new (and interesting) one
and it does what is says on the box which is great for deserialization as the deserializer will fill in the blanks
Is there a requirement to show a variable in the inspector?
[Serializable]
internal class Player
{
internal Resources Resources { get; private set; }
internal int Test = 5;
public Player()
{
Resources = new();
}
}
Test doesnt show
I am always stuck on serializing things lol and I cant ever remember what the issue is, but I feel like I tried it all.
I can't [SerializeField] since its a regular class.
internal wont work
Unity serializer will only serialize public fields in poco's
hmm should I give up internal variable for serialized property? I think not!
Tbh its fine at this stage, but I like having things private/internal 😄
internal just means visible within the same assembly
also interal class wont work, serialization is done by the UnityEditor.dll and it cannot see internal classes from Assembly-CSharp
Makes sense, I actually need to learn about assemblies so I can make my own for my scripts, apparently that speeds up compilation time by a lot when developing a game.
there is an InternalsVisible attribute to override this
it also introducing a lot more work and compartmentalizing everything
What does that mean?
something you typically do in the beginning of the project rather than later on
Yeah this is the very beginning of the project, do you recommend it? I kinda want to learn it.
Is it worth it?
well once you start to separate things by assembly you need to be very careful on your referencing
you can start by using asmdefs but I usually put all my stuff into dll's anyway
I am not sure what that means yet, where/how do you put stuff into dlls?
something like a class Library etc
So assemblies are supposed to reference only within themselves and rarely outside?
Thats what speeds up compilation times
no I just mean if you start making too much like spaghetti it will defeat the point of asmdebf
create a CS dll project external to unity, put your code in that project and when you build it the output goes into the project/Assets/Plugins folder
Spaghetti in a sense that multiple assemblies reference each other a lot?
yes because if you want to access something within one assembly in another assembly you need a reference and so on
What if I just put my whole game into 1 big assembly, wont that speed up the compilation regardless of how spaghetti my code is?
if you're making that much spaghetti you are definitely doing something wrong
i mean thats whats happening now its all in 1 big assembly
Aside from the Unity ones like TMP etc
because afaik Csharp assembly is my project files + unity + other stuff which is why it takes forever to compile after 1 small change(hot reload saves a lot of time tho, but still)
No, then a change in one class would trigger a recompile on the whole assembly. Like I said keeping assemblies separate is what speeds up compilation
very true, thats why you have to be careful or you're just back to where you started
no, just your script files
Is there a guide on that? This makes almost no sense to me tbh 😄 Is it part of creating assemblies that I will learn if I look up the topic?
look up Visual Studio class library for example
thats how you normally make a simple DLL
AssemblyCsharp has like 100 references, could it be why complilation is so slow?
I know that people who use assemblies compile their small projects in like 0.01 seconds 😄
Looking into it
well think about it, everytime you make a change in 1 script now it has to refresh all of those
that is, indeed, one of the reasons
Yeah so if I make my own assembly for my scripts, it should make it faster by itself right? Even if its not ideal and those should be separated into multiple assemblies.
This is mostly for the sake of fast development/prototyping, it may not be perfect long term etc, but if it makes it so 1 change compiles in 1 second instead of 5-20 then thats a huge difference
Since I can make 10 changes per minute as I test things
I will have to give it a go I guess, wont know until I try.
Hot Reload is also something I should be using.
Example dll solution. Contains 3 dll projects and the results in unity
Yep that looks good, only 5 references(idk what analyzers are) compared to 100+
I would guess it compiles almost immediately?
indeed, I can compile this plus the rest of the code that makes up the asset and create versions for 5 different versions in Unity in < 1 minute
Nice, I will focus on assemblies tomorrow then or later today.
Since I am early in development it wont hurt, I want to at least see the difference 😄
can i get hep, i have instaed unity fr first time and i cant pen any prjects, everytime i try t pen prject i see this
Hey there :) Not sure if this is the right channel for this, because technically its not about coding, but its related. So I'm using git to collaborate with some peers, and when merging branches, we often get merge conflicts with .meta files and guid. And i've done a bit of research and it seems to me the guid is the reference which tells the attached GameObject which other Asset/GameObject/Script is attached to it. So now i am confused as to why the guid changes so often and in merging conflicts, which guid should i use? Because I'm worried that all the links may break.
one other benefit is you can use nuget packages which you cannot do in Unity even using asmdefs
#💻┃unity-talk
this is a code channel
if guids are changing it means someone is deleting and recreating assets. tell them to stop doing it
That or you are not committing your meta files
I do commit them, else i wouldnt get merge conflits, right?
Right but that also means someone is also commiting them on the other end and that should not happen
I never used nuget packages I think, is it another way to get packages instead of package manager?
Maybe I did use it once for WebGL save that required some weird thing
yes, like Newtonsoft for example
#if UNITY_WEBGL && !UNITY_EDITOR
[DllImport("__Internal")]
private static extern void SyncDB();
#endif
I had to dig for this line of code on some old forum post + I needed some file I think, cant remember how it was done, but it was required to make save/load work on webgl
Oh newtonsoft yeah I used that, but I was able to get it without any assemblies
That is probably an Enscripten import from a .jslib file in your project
Unless I remember it wrong
I dont even know where to find it haha, but it worked somehow
I think that I had to download something using url from package manager, but I might be confusing it with newtonsoft
Regardless its crazy how save/load for webgl requires those hacks that don't seem to be in any documentation?
that is basically a way for Unity to talk to the JS script in the browser at runtime
because a webgl program, like a web form has no direct access to the OS file system, it requires a hack
On that note...Is Unity documentation always so painful to use? I just avoid it at this time as searching for anything is difficult and when u google and open old version documentation there is no way to open same page inn new version etc.
Right, but how do you figure out the hack if its not documented? I found it on some forum post and up till now I have no clue how it works
yes there is, top left of the page you can select the version
oh you have to manually switch version
Actually here is the thing:
This was my issue and its still there
Is there a way around it?
There is no dropdown, maybe old version of documentation doesnt have it
indeed but if you switch to the 2019 version it does have the dropdown
yes so 2019+ has a dropdown, I might have missed that or a lot of my google searches would open older docs like 2018
But thats good to know!
Is there a way to display the line numbers or do I just have to count them every time I chase a bug? lol
mine all seem to open Unity 6 and I have to change to get the older versions
Yeah this dropdown is kindna broken lol
wdym
There should be an option in your IDE
Like the other day when the error to my code was on line 32, I had to count 32 lines down.
Which IDE do you use?
is your IDE not showing line numbers?
no
then you turned the option off because it's on by default
Just to finish this with: It seems like each version of unity documentation has its own separate dropdown for some reasons, which is why I always get those issues.
It probably is fine if u search for things directly with their search bar tho
unity search bar is crap, I always use google
Same, but that opens old version of documentation and I am stuck in a loop 😄
I use Microsoft Visual Studio and it hasn't showed the line numbers since Ive had it
microsoft visual studio 2022 show line numbers
Google it
I assume you are using 2022 version tho, idk which version is up to date nowadays but it works fine for me.
Tools->Options
Hi Can you tell me what are these errors now?
Those are warnings just to be clear
Thanks guys. That worked just fine
They are not errors, they are warnings, read them to see if they are important to you
save/recompile and even restart Unity might get rid of some of them, usually ignored unless they appear again from my experience(never had your specific warnings tho)
So i making a puzzle where you have a set of words that you have to place in a certain spot to complete the puzzle. So for the first few levels there was only 2 word puzzles then i moved up to 3 word puzzles, but how i have it set up is not good it worked for the first 2 but then you add another word and not the puzzles with only 2 words are looking for 3 if that makes sense...
I have it set up by collecting words and then you have to drag and drop the words on the correct "DropPosition" if not the word returns to OG spot and if it does it stays. i know theres a WAY BETTER way to do this but i cant wrap my head around on how to go about it. Heres a screen shot of the code for checking if the puzzle is complete by checking the "DropPosition"
But for the first few levels i only need to check if dropPosition02 and DropPosition02 is correct and not DropPosition3
yeah, Can I just separate AR Camera and then replace the old ARSession origin with XROrigin? or will their be more problems after that?
https://i.gyazo.com/b29774919985b60ca575abc4efa63531.png
Is there a better way of doing this?
I want my UI elements to subscribe to this event and update/subscribe to other events deeper into the class(like Player class) when the game is loaded to avoid null reference exceptions.
I tend to do something like:
void Start()
{
if(Game.Instance.InitComplete) SetupUI();
else Game.Instance.OnGameInitComplete.AddListener(SetupUI);
}
private void SetupUI()
{
Player player = Game.Instance.Player;
player.OnLevelUp.AddListener(UpdateExperienceBar);
}
Then combine it with OnEnable/Disable if needed depending on my UI
then your dropPositions should probably be in an array or List rather than being discrete variables
This is just a random example, but thats how I do it usually, but I would like to see if there are better ways
Im not really to familiar with lists... So if i made it a list then say for level 1 i only drag in DropPosition01 and DropPosisition02 and then for level 5 i would drag in DropPosition01 and DropPosisition02 and DropPosition03 ?
exactly
It can get a bit more complicated if I do Player.Inventory.Item[0].OnCountChange for UI.Player.Inventory.ItemCell(UI object/script to update specific Cell in inventory)
I wonder if its too much work/bad practice?
Isn't there an identifier that is something along the lines of gameObject.other or something like that?
in what context
What is other?
Other what
I've identified an object as part of a collision and I want to add force. I was just going to use it to identify which object I'm adding force to
The collision function gives you the other object as a parameter
the Collider parameter is often named other so other.gameObject
ok, thanks
how would i write the code to go through the list and check if the word is in the correct position?
Can Someone explain to me what i get worng with it?
private void processWallslide()
{
if (isGrounded == false && wallCheck() && horizontalMovement != 0)
{
isWallsliding = true;
rb.linearVelocity = new Vector2(rb.linearVelocity.x, Mathf.Max(rb.linearVelocity.y -wallslideSpeed)); //Caps Full rate
Debug.Log("WALL");
}
I should decrease the WallslideSpeed, but instead i'm falling faster
wallslideSpeed = 2
I think is something in the Mathf, but didn't it work?
theres no comma in there
That was it, Thanks!
post your !code correctly and I will show you
📃 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.
So I cant understand why joints break.
if (_dropPosition01.inCorrectPosition == true && _dropPosition02.inCorrectPosition == true && _dropPosition03.inCorrectPosition == true)
{
puzzleKey.gameObject.SetActive(true);
TVButton.gameObject.SetActive(false);
puzzleCompleteText.SetActive(true);
//UICanvas.gameObject.SetActive(true);
//Player.gameObject.SetActive(true);
hasSpawned = true;
}
else
{
puzzleKey.gameObject.SetActive(false);
}
and what is the Type of _dropPosition01 02 and 03 ?
Im trying to turn the DropPosiitons into a list and check if they are in correct position
[SerializeField]
private DropPosition _dropPosition01;
ok, wait one
instead of
if (_dropPosition01.inCorrectPosition == true && _dropPosition02.inCorrectPosition == true && _dropPosition03.inCorrectPosition == true)
you have a List
public List<DropPosition> dropPositions;
which you fill in the inspector
then
int found = 0;
for (int i=0;i<dropPositions.Count;i++) if (dropPositions[i].inCorrectPosition) found++;
if (found == dropPositions.Count)
int found = 0;
for (int i = 0; i < dropPositions.Count; i++)
{
if (dropPositions[i].inCorrectPosition)
{
found++;
}
}
if (found == dropPositions.Count)
{
puzzleKey.gameObject.SetActive(true);
TVButton.gameObject.SetActive(false);
puzzleCompleteText.SetActive(true);
//UICanvas.gameObject.SetActive(true);
//Player.gameObject.SetActive(true);
hasSpawned = true;
}
else
{
puzzleKey.gameObject.SetActive(false);
}
so like this?
exactly, it's not the best way to do it but the most easy to understand
Okay ima test it out! Thankyou!
If i may ask what would be the best efficient way to do it?
you really need to take the time to learn about array, lists and for loops, your life will be so much easier in the future
sure
bool found = true;
for (int i=0;i<dropPositions.Count;i++) if (!dropPositions[i].inCorrectPosition) { found=false; break }
if (found)
so the loop breaks as soon as it finds one not in the correct position. not really important when you only have 2 or 3 entries
I updated visual studio and now its broken, how do i fix it
reinstall the unity workload via the VS Installer
can someone take a look please?
Yes im am realizing that now lol Im watching videos about them ATM
It worked!
Thanks so much Really appreciate it!
thank you
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
!cs
Join the C# Discord server, a programming server aimed at coders discussing everything related to C# (CSharp) and .NET. https://discord.com/invite/csharp
what could be the reason that the other animation doesnt start playing for me
as the loop is off,the has exit time is unchecked
can you send an ss of connection between them?
this is a code channel. #🏃┃animation
!vscode
will you please stop spamming the channel with bot commands
I want to use bot commands, what's wrong?
I just joined and i need to get needed stuffs
if you are looking for basic information please use the pinned messages here and in #💻┃unity-talk
Okay, thanks
Sorry, i though i need to use those bots commands here because i found #854851968446365696 under scripting categories
there is no conditions right?
no its just I have a object which needs to come from bottom to up and then just flip once that what i have done so far
but in different animations
i also need to flip once again after the the reveal animation
should i do all at one animations
Hi
hey
hemlo
I've got a problem that my player teleports to the right and don't move. Can you help me?
you would want to place a - sign at the first XRange (I believe)
ok
and also a minus sign in the XRange in the vector3 below it
it isnt working
never seen çã used in names for classes. Neat. You need to be more specific about what exactly isn't working, and what behaviour you're getting instead of what behaviour you want.
when i try to run the game it says i need to fix the errors first
but it doesnt show any sintax errors
does your IDE not tell you what errors you're getting?
nope
what does your console say then?
the console says nothing
the console should print whatever errors you're getting. How do you even know if you have an error?
are you certain you don't just have errors hidden in the console
nullref incoming.
null ref is runtime not compile time
wait i wrote something wrong. i fixed it but its showing a lot of errors in the console ill try to fix them (i swear it wasnt showing in the console before i restarted unity)
you should configure your IDE first
all errors are underlined there
how can i configure it propely?
!ide
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
• :question: Other/None
i alredy did everything
so screenshot your IDE window
that dont look configured to me
this would disagree with you
you also need C# and .Net install tools
then go into external tools in unity and assign VScode as your external IDE
then regenerate project files
the MonoBehaviour isn't highlighted
it is
what is your unity version
6000.0.23f1
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
it is
I did not see that
there ya go
so you did not have .net
download/install .NET SDK , then restart pc
hey yall i wonna use visual studio n not the community one how tdo so
!vscode
wdym "visual studio n not the community one"? do you mean you want to purchase a pro or enterprise license? or do you perhaps think that vs code is the same as visual studio?
no its the other version that comes with large size .. i kinda wonna jus use the other one since it uses less space
what do you mean "the other version that comes with large size"?
there is only visual studio with different licensing (community, pro, enterprise)
or there's vs code which is a completely different coding environment
vs code the normal one..
vs code is a different program from visual studio. they are two separate things. vs code is not "the normal one" when referring to visual studio
im not sure... but the one that doesnt require u to download anything jus an ide like the text editor
extensions
vs code is the one that is just a fancy text editor. you are still required to download and install specific extensions for it to have it work with unity correctly.
visual studio is the fully featured IDE
im following that u sent me
?do i have to install the debugger
unity plugin / c# devkit already comes with everything
hey can i jus yk.. go to the file n then do the cmd n type code . n still be able to code fine?
configure vs code using the guide that was linked to you.
ok
would anyone know why i cant move my character in my procedurally generated world? currently following a tutorial but i implemented my own player movement and it doesnt let me move around at all. Thanks https://imgur.com/a/Zh6yfPO
You'll have to show the code
Could someone help with why this pause menu script wont work? The unpause function works, so i dont think it's the input, but i cant figure what else it could be. Let me know if you need a video of the game. https://paste.ofcode.org/f5L8pmuUB3chzDw2X4U93d
can someone help me? the assets of the unity tutorial are purple
#💻┃unity-talk
also use 

Does UnityEvent auto unsubscribe if the object/class subscribed to it is destroyed?
Incompatible render pipeline. Either the assets are URP while you're using Built-in or vice-versa
looks like the assets are BIRP as they are using standard Shader
Hello
I need some help
I wanna create sections of a terrain
Not like split the terrain
But create like 7 random sections on the terrain
Each one overlayed over the original terrain which just represents the hue of that particular area separating it from others
How can I achieve that
Or how to slice a mesh
break the problem into smaller easier to solve / research steps
@snow warren Please learn to type in full sentences. Shift+Enter is a thing
Sorry my bad
sounds more like you just want different vertex colors on different parts of a mesh
vertex colors are usually built-in data and you can assign them via Unity's mesh class
Hey any reason why my movement feels really jittery?
Many possible reasons
9 times out of 10 it's usually the camera. but you need to provide actual information. #854851968446365696
Before it felt really inconsistent so i changed the simulation mode back to fixed update and the physics are now consistent but more gitter
That's what online said too but im using a cinemachine not a script
and if your camera updates before the object does then you'll experience jitter
Jittering is basically when your object movement relative to the camera is not updated at the same rate as rendering.
Hm any way i can fix this with a cinemachine camera?
The best way is to align everything to the regular update.
Do i change the "update method"
Rn its on smart update i feel it should be on fixed
On the cinemachine? Yes, better make it update, rather than fixed update.
And you can align the rb by making sure it uses interpolation.
Theres 4 options though, fixed,late, smart and manual
Late is basically at the same rate as regular update, so you want that.
I think it might be jittering more now
So do i need to move my movement into late update or just regular update
Thanks btw
It depends on how you're moving it.
Addforce if thats whatcha mean
Moving addforce to a different update wouldn't change when the object movement is updated. It is moved by physics, so that always happens in fixed update. You can enable interpolation on the rb, so that the position is interpolated during the regular updates.
any physics related items should remain in fixed update to be on the physics step
Its already set to interpolate
if you put camera movements in lateupdate that usually fixes camera jitter as it is further down the update queue (I forget the name for it)
Done that too
is your camera directly parented to the rigidbody?
Yeah
don't do that
try moving it directly to an empty on the player
unparented
transform.position = Empty.position;
So make n empty object thats on the player or?
Then the interpolation is being broken.
make an empty and put it on the player near the head of it and move your camera to it via script
that works for me
I mean its a cinemachine so thinking about it does it need to be paired at all
No, it's best not to parent it to anything.
yes
your camera should not be a child of the player, no. your vcam also doesn't need to be, but can be
do not parent it to anything
Uhhh okay sorry simple question how do i unparent something on a prefab
Ive done everything n its still gittery
because you are likely breaking the interpolation like dlich pointed out
show all of the relevant code you have regarding the player's movement/rotation so we can see where you might be doing that
Alright
Ill have to take a pic with my phone though so sorry for the jank of that lol
do not photograph your screen. share the !code correctly 👇
📃 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 have discord on my laptop
well conveniently it's a website you can visit. or you can easily just post the code to a bin site (which you probably should be doing anyway) and just type that out manually if you really need to
Ig ill do that
its not that much code should i just copy n paste it
just copy and paste it into a bin site and share the link to that
remember to save it
when does the jitter happen, when you move or when you turn?
move but then the little raycast ball thing also jitters
also you seem to by multiplying the addforce by time.deltatime
which is a no go, since it already does it
cause its in the fixed thing?
well the method does it normally I believe but also yes
what is your movespeed at?
that's 100% because you had your movespeed about 100x too high to compensate for the erroneous deltaTime multiplication
all cool n all now its not quick, still stuttering
rather than assigning the transform.rotation, assign to the rigidbody's rotation instead
still jittering idk why that would have fixed anything
because it wouldn't have broken the interpolation. are you absolutely certain nothing else anywhere is affecting the transform of this object?
yeah litreally nothing is
that code is all there is in terms of script for the player n nothing else fucks with it
Share the updated code.
Also, don't know if that was pointed out already, but you should move your input querying out of fixed updated.
its like the same thing
Try commenting out the rotation bit. Does it still jitter?
hey i'm making this laser for a platformer game im making which uses a line renderer to render the laser and apply a collider which matches the exact size of the rendered laser to reset the scene once the player touches it. for some reason, the collider isn't right and i've tried everything. i visualize the collider with a gizmo to show where it is. https://paste.ofcode.org/3DamS2ugpsbyb748eWUnFn
yes
they are just querying the current state of the keys so it wouldn't actually be a problem. it's really only the GetKeyDown/Up that would be a problem in FixedUpdate
I'd still move it out, but fair point.
why would the raycast do anything lol
It might be confusing you. Whatever you're using for debugging might be jittering and not your character movement.
Since the interpolation doesn't apply to it.
Ok, then take a video of what it looks like now(with all the suggestions applied).
I see stuff rotating, meaning you don't have the rotation commented out as I suggested.
i re-enabled it
just imagine no rotation at all in that vidoe and its the same thing
All of the things that were suggested to this point could be contributing to the issue. Just testing out one at a time would not help.
This is the basics of debugging an issue. Please comply...
can someone help please?
Hmmm... That looks very weird compared to normal jittering.🤔
Something weird about the movement itself too.
For example, why would it stop immediately when you don't hold any input? Normally it should keep on moving.
drag
Okay. And if you set the drag to 0, press input a little bit and let it go, does it still jitter when it moves freely?
still jitters when moving freely
Can you take a screenshot of that object inspector?
That would imply that length is not having the value that you expect. You should add a few more debugs along the way and maybe visualize your raycast as well.
Why is the interpolation set to none?
ok i'll do that
yeah thats my mistake, was doing it before so i tried it off n yah
ill try the things off n on again
You should have it on always. There's no point testing with it off at all.
As I said, it was probably a combination of issues, so when you were trying things one by one there was always an issue preventing it from working correctly.
thanks bot
the blue line is the raycast, and its hitting where it is supposed to.
What about the additional logs?
And share the updated code as well
Raycast hit: Square (1), Distance: 9.344271
UnityEngine.Debug:Log (object)
ShooterScript:Update () (at Assets/shooterScript.cs:33)
this is all i could really think of
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ShooterScript : MonoBehaviour
{
public Transform shooter;
public LineRenderer laser;
public float maxDistance = 100f;
public LayerMask ignoreLayer;
private BoxCollider2D laserCollider;
void Start()
{
laserCollider = laser.gameObject.AddComponent<BoxCollider2D>();
laserCollider.isTrigger = true;
Debug.Log("Laser Collider added");
}
void Update()
{
Vector2 direction = shooter.up;
RaycastHit2D hit = Physics2D.Raycast(shooter.position, direction, maxDistance, ~ignoreLayer);
Debug.DrawRay(shooter.position, direction * maxDistance, Color.blue); // Visualize raycast in blue
laser.SetPosition(0, shooter.position);
if (hit.collider != null && hit.distance > 0)
{
laser.SetPosition(1, shooter.position + (Vector3)direction * hit.distance);
UpdateCollider(shooter.position, direction, hit.distance);
Debug.Log($"Raycast hit: {hit.collider.name}, Distance: {hit.distance}");
}
else
{
laser.SetPosition(1, shooter.position + (Vector3)direction * maxDistance);
UpdateCollider(shooter.position, direction, maxDistance);
Debug.Log("Raycast did not hit anything");
}
}
private void UpdateCollider(Vector2 startPosition, Vector2 direction, float length)
{
laserCollider.size = new Vector2(laser.startWidth * 10, length);
laserCollider.offset = direction * (length / 2);
Debug.Log($"Laser Collider Size: {laserCollider.size}, Laser Collider Offset: {laserCollider.offset}");
}
private void OnDrawGizmos()
{
if (laserCollider != null)
{
Gizmos.color = Color.green;
Gizmos.DrawWireCube(laserCollider.bounds.center, laserCollider.bounds.size);
}
}
}
Your debug ray is not entirely correct. Use the hit distance instead of maxDistance.
like this?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ShooterScript : MonoBehaviour
{
public Transform shooter;
public LineRenderer laser;
public float maxDistance = 100f;
public LayerMask ignoreLayer;
private BoxCollider2D laserCollider;
void Start()
{
laserCollider = laser.gameObject.AddComponent<BoxCollider2D>();
laserCollider.isTrigger = true;
Debug.Log("Laser Collider added");
}
void Update()
{
Vector2 direction = shooter.up;
RaycastHit2D hit = Physics2D.Raycast(shooter.position, direction, maxDistance, ~ignoreLayer);
Debug.DrawRay(shooter.position, direction * hit.distance, Color.blue);
laser.SetPosition(0, shooter.position);
if (hit.collider != null && hit.distance > 0)
{
laser.SetPosition(1, shooter.position + (Vector3)direction * hit.distance);
UpdateCollider(shooter.position, direction, hit.distance);
Debug.Log($"Raycast hit: {hit.collider.name}, Distance: {hit.distance}");
}
else
{
laser.SetPosition(1, shooter.position + (Vector3)direction * maxDistance);
UpdateCollider(shooter.position, direction, maxDistance);
Debug.Log("Raycast did not hit anything");
}
}
private void UpdateCollider(Vector2 startPosition, Vector2 direction, float length)
{
laserCollider.size = new Vector2(laser.startWidth * 10, length);
laserCollider.offset = direction * (length / 2);
Debug.Log($"Laser Collider Size: {laserCollider.size}, Laser Collider Offset: {laserCollider.offset}");
}
private void OnDrawGizmos()
{
if (laserCollider != null)
{
Gizmos.color = Color.green;
Gizmos.DrawWireCube(laserCollider.bounds.center, laserCollider.bounds.size);
}
}
}
didn't mean to delete the message
Yes.🤔
Can you pause the game at runtime and take a screenshot of the collider object inspector?
According to the logs you shared in the first message, the width of that collider is 10.
No. The collider that you add via code.
The object that it's added to
The whole object inspector
Is that the same object? Where did the collider go?
oh oops i accidentally stopped the game
one second
Ok.
- Why is it scaled like that? Try setting the scale to 1 1 1 and adjusting everything else accordingly.
- Why is there both a sprite renderer and a line renderer? I understand that the line renderer is the laser? Then what is the sprite renderer for?
ah
yeah it was because it was scaled like that i think
the sprite renderer made it insanely misleading lmao
also, how do i fix this? the pivot is in the wrong place
What is that? A sprite renderer?
I mean,what's supposed to be where?
the blue green and red circle
That's what I'm asking what is it? What object does it belong to?
Show hierarchy and inspector
First of all, the correct way to think about it is that the gizmo represents the object position. If the sprite is not centered on it, then it's an offset of the sprite itself.
In your scene view top left change center to pivot mode.
oh, didnt know you could do that
ok that helped
@teal viper i found another problem, the light green border doesnt match up with the red laser when rotated, and gets more offset the more rotated https://paste.ofcode.org/wzDLwrmqExgzj4NbgbGWiq
Could be several things. For starters, I'd make sure it's not related to scaling on the current object or it's parent. Set the scaling to 1.
Hello, I'm having a dataflow issue. On a GameManager class I have this event being triggered:
private void NewGameStart()
{
ChangeGameState(GameState.OnPlayerControl);
OnGameStart?.Invoke(0);
}
This leads to this class:
public class DroneManager : MonoBehaviour
{
[SerializeField] DroneHolder droneHolder;
[SerializeField] List<Drone> Drones = new List<Drone>();
[SerializeField] public Transform MainBaseSpawn;
public static DroneManager Instance;
private void Awake()
{
if(Instance != null)
{
Destroy(this);
}
Instance = this;
}
private void Start()
{
GameManager.Instance.OnGameStart += AssignDrone;
}
private void AssignDrone(int droneIndex)
{
Drone drone = Instantiate(Drones[droneIndex]);
droneHolder.AssignDrone(drone);
droneHolder.InitializeDrone();
}
public void TowDrone()
{
Debug.Log("Tow");
}
public void LaunchDrone()
{
GameManager.Instance.ChangeGameState(GameManager.GameState.OnDroneControl);
UIManager.Instance.TogglePanel("Computer");
}
}
Then leading to where It's supposed to set the data, on a DroneHolder class.
public void AssignDrone(Drone drone)
{
if(drone != CurrentDrone)
{
Debug.Log("Assigning new drone instance.");
CurrentDrone = drone;
}
}
public void InitializeDrone()
{
transform.position = DroneManager.Instance.MainBaseSpawn.position;
WeightSystem.SetDroneData();
BatterySystem.SetDroneData();
StartCoroutine(BatterySystem.UpdateBattery());
}
When entering InitializeDrone method, CurrentDrone is null. Why?
nope, its not scaling
Then it must be due to offsetting the collider and/or possibly the object itself relative to it's parent. It's really hard to tell without having the project at hand, but should be something really simple to figure out if you have the project.
CurrentDrone isnt used directly in InitializeDrone, where do you see that its null? also you already have debug statements, you should add more to see why its null. like print the name in AssignDrone
@eternal needle On BatterySystem.SetDroneData() I have this code:
public void SetDroneData()
{
CurrentBattery = CurrentDrone.MaxBattery;
OnBatteryHasCharge?.Invoke();
}
Here I have a NullException
That code is supposed to run after CurrentDrone has been set to the incoming drone value
BatterySystem.SetDroneData() is called on InitializeDrone
How can i load Audio Files at Runtime from a Disk/Location? Doesen't matter what Format, but i want to avoid using the WWW class.
so go backwards through the logic being done, add debugs and see why its null in AssignDrone or at what point it becomes null
have you looked online? theres quite a few posts about this exactly https://discussions.unity.com/t/dynamically-loading-mp3-files-during-runtime/934935
I have, but i cant use the WWW class due to some Limitations.
www is super old/ deprecated. You should use UnityWebRequestMultimedia
I meant WWW Or any other Networking Solution.
they didn't link the www class. Its a UnityWebRequest
And UnityWebRequest is part of the UnityEngine class?
I'm quite sure the last time i tried Networking it wasn't Included for my Build Platform.
WebRequest should work for pretty much all platforms
just unity's version of a http client
alright imma try it
anyone knows how do i create that wobble effect on a card using DOTween like phone ringing
WAIT WHAT no way it actually works
void OnTriggerEnter(Collider other) {
if (other.CompareTag("Player")) {
isInArea = true;
Debug.Log("area enntered");
}
}
void OnTriggerExit(Collider other) {
if(other.CompareTag("Player")) {
isInArea = false;
Debug.Log("area exited");
}
}
ive got this code attatched to an empty gameobject with a box collider 2d with isTrigger enabled. but when the Player walks into this area (player has capsule collider 2d and a rigidbody component) neither of the debug logs go off so its not being detected
how do i make this more wobbly Sequence wobbleSequence = DOTween.Sequence(); wobbleSequence.Append(card.DORotate(new Vector3(0, 0, wobbleZOffset), tiltDuration / 2).SetEase(Ease.OutQuad)) .Append(card.DORotate(new Vector3(0, 0, -wobbleZOffset), tiltDuration / 2).SetEase(Ease.InQuad)) .SetLoops(3, LoopType.Yoyo); // Adjust loops for extra wobble effect
its a card
like a phone ringing
is it fine to store all my cooldowns by storing the last Time.time when that ability was used
and in void Update, checkinng if Time.time - lastUsedTime > cooldownTime
if its working its fine
How do you destroy a c# object(not a GameObject)? If I create an object with a class constructor and add it to a list, will it automatically get destroyed when I remove it from that list or do I manually destroy it?
im also a beginner in coding, but isnt there a function such as Destroy(thisObject) (I may be wrong)
c# objects usually are cleaned up by just unbinding any reference(s) to them
I am working on a 2d game with kinematic rigidbodies. I have looked online, and I cannot find a reason why my game objects do not collide. Could anyone help me?
That’s what I thought but I wasn’t sure if it would be more performant to manually destroy it
you don't. C# is a garbage collected language.
Usually it is, but that's a feature of c# ;p
The only reason Unity objects need Destroy is because they have a native (non-C#) C++ object half
Anybody know which file contains AdditionalLightShadow? Or rather, where shadows are generated. I've modified light scripts but I can't find those ones.
https://github.com/Unity-Technologies/Graphics/blob/master/Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl#L472
No idea about the second question.
public class DialogueHandler : MonoBehaviour
{
[SerializeField] Canvas dialogueCanvas;
[SerializeField] TextMeshProUGUI dialogueText;
protected static string path = "Assets/Dialogue.CSV";
...
...
public static void startDialogue(string key)
{
List<List<string>> dialogueList = getDialogue(key);
if (dialogueList == null)
{
Debug.Log("Dialogue not found");
return;
}
for (int i = 0; i < dialogueList.Count; i++)
{
List<string> dialogue = dialogueList[i];
Debug.Log(dialogue[0] + ": " + dialogue[1]);
dialogueText.text = dialogue[0] + ": " + dialogue[1];
}
}
}
I tried to make a Dialogue handler which you can call from other scripts but now i've realised that you can't really make a serialized field static which means i cant really edit the gui text from this class. Is there a way to overcome this like another way to reference gameobjects as static or is the whole structure of this class totally wrong
You need a singleton. https://gamedevbeginner.com/singletons-in-unity-the-right-way/
Welp I'll try stumbling around with this again
thanks
Ah that works
thanks
Is it a good idea to keep the interaction action in a seperate script from the other action scripts?
Like a seperate script for actions(like attacking/emotes) while one more for interactions(either with Obj or NPC).
Mostly as the Interaction script would be the one thing consistent for each character to boot.
Guys i have a parent object and three child objects and with the child object i have animation made in animator and then their is a script attached to the parent object with some animation that i want to play after the childs animation is finished how can i do that in unity?
This is what I'm doing with my interactions.
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
public class Interactable : MonoBehaviour
{
public UnityEvent OnInteract;
public string str_interactionMessageText;
public Sprite spr_interactionMessageSprite;
bool canInteract;
public void Interaction()
{
OnInteract.Invoke();
}
private void Update()
{
if (canInteract)
{
if (Input.GetKeyDown(GameManager.Instance.controlsManager.interactKey))
{
Interaction();
}
}
}
}
This lives on each object that I need to interact with (dealing with the interaction on a mouseRollover raycast thingy), then each object type has it's own 'This is what happens when you press the interaction key' script that gets called from the event firing. (The UI Stuff on there gets passed to my ui dependant on what has been rolled over.)
What resource should I learn to start making a game with parry and invinsibility frames ? Also what are some good tutorial on how to use Unity animation ?
Show the movement code
Don't cross-post
Is that step code also in update?
That sets the step to whatever the frame rate is at the start. Deltatime changes based on whatever the current framerate is so it has to be recalculated every time in Update
then, maybe, you should have done some research
because you didn't bother to research someting you were relying on
Not condesending, trying to get you to think
Ive been using Random.insideUnitCircle.normalized * radius to get a random point on the edge of a circle, but im not sure how to pick a specific point on the circle (say i wanted to get the point at the 120° angle for instance)
I can't make button to switch between cameras I don't know how to explain it, but it looks like very complicated chore to achieve such simple things
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraSwitchButton : MonoBehaviour
{
public Camera mainCamera; // Renamed to avoid spaces
public Camera camera2;
public void SwitchCamera()
{
Debug.Log("SwitchCamera called");
mainCamera.enabled = !mainCamera.enabled;
camera2.enabled = !camera2.enabled;
}
}
is this code correct?
yes, that looks correct
so where is this script attached to a button?
in here
ok, so show the inspector of the script on the GameObject
that all loks fine, are you not getting the Debug message at all?
yes you are or yes you are not
then it is working
but camera won't change
but camera is changing is one gets disabled and the other enabled
Ive been using Random.insideUnitCircle.normalized * radius to get a random point on the edge of a circle, but im not sure how to pick a specific point on the circle (say i wanted to get the point at the 120° angle for instance)
Take a normalized vector and rotate it 120 degrees.
maybe this will be easier to understand
why camera won't change?
I need some help, I have to make a project which will be a 2D game with levels and cutscenes (probably) and I was going to start the project and I saw this 2D platformer microgame, do you recommend me using it?
you can use it to learn, and you can use it as a base for a prototype, but you'd have to replace pretty much everything to make your own game anyways, so once you've learned how to make it, i'd recommend opening a new project for a fresh start where you have control of everything
But is it possible to change like, background, add attack animations, add enemies, make levels, change the designs using this as a base?
yeah, that would be removing everything and then adding your own stuff back in
so why not skip the removing step
Yea fair enough, maybe I'll just look into this 2D platformer microgame for a bit and start from 0, thanks
Don't crosspost
Yea some random other guy already told me that, and I answered, which I'm sure you saw since you're saying this
Here's how I'm arranging the Interaction/Action for the Player between Character States.
why these don't fall inside?
wdym by that? are they falling at all?
Let me guess, you use convex mesh collider
it's an open box
or single box collider
I don't know
yes it's single box colider
in godot it automatically creates collider for your model
do they have rigidbodies
is there button like this in unity?
yes, balls are fine
Don't know about godot but in unity box collider is a box, 8 corners, no holes. you gotta use mesh collider or multiple primitives (like box colliders) if you want to have more complex collision shape
that's what mesh collider is, it's a collider and you give it a mesh as shape
that would be just a simple cube
For human model that needs to move around and morph their shape, I would use dozen or two capsule colliders like any other game in the world. unity's mesh collider won't update correctly with moving armatures so it wouldn't really work for most characters. Most games (outside unity) don't even try to use dynamic mesh based shaders because it would be very expensive. For stationary and more importantly rigid objects (not ones bending according to a rig) mesh collider is totally fine
so with every model you need to manualy set up colliders?
in godot you just click create trimesh static body and that's it
I only doing unity because I need it for my college
Read more carefully. For stationary rigid objects you may use mesh colliders which accurately uses the mesh for collisions, for moving and especially shape morphing objects compound colliders (using multiple primitive colliders) are the way to go
For non moving objects mesh collider is often a good option. Someone on the internet may scream to you about their performance cost but it's really not that slow on most cases. Mesh colliders biggest limitations are that dynamic (moving/physically active) bodies can only be convex (no dents or holes) and rigid (cannot be bend by armature/skeleton/skinned mesh/bones/whatever you wanna call that)
Obviously if your mesh is just a box, sphere or capsule, you should definitely use the primitive collider types respectively but for more convex meshes Mesh Collider is often fine
Hi! In the project I'm working on, we're importing some 3d models with animations in the same fbx file. At the moment, we're playing these animations using an Animator component and AnimationController, but we have hundreds of clips in the controller and we only ever want to play one clip at a time (we don't need to switch between clips). The animation clips are taking a ton of memory, so I'd like to find a better way to handle this. Does anyone have any suggestions?
There's an Animation component that could have worked, but this is now marked as Legacy.
That doesn't mean you can't use it
ok I have problem, box collider doesn't fall trough the ground (good), but when I apply mesh collider it does fall trough the ground
I've not used unity in a while, so im trying to still decide on what the best way of organizing my project is. Normally i'd create empty game objects as containers for my scripts and organize them based off what they do. Such as having a Player game object that holds all player related scripts that then take in a reference to the player prefab, then I'd have one for Environment that handles all environment stuff, like Audio, Lighting, etc etc. I am wondering if this is the best way, or how you guys would recommend, because I feel like when it comes to team projects this won't be the best method.
I did try adding the Animation component with "Play Automatically" selected, but it doesn't play the animation
Sure it does 🤔. Which animation did you select?
Mesh collider to the bucket shape, not the ball. The ball is… a ball, use sphere collider for that
yes, my bucket falls trough the ground
if I mark convext then it stays on the ground, but balls can't fall in again, so it's like box collider
Hi everyone. I have a question about the best way to handle the Animator and controlling a GameObject’s rotation with the transform.LookAt method.
I’m trying to have my enemy GO look at the player and then chase after them, but the enemy has an animation that affects their rotation when they die.
It turns out trying to manipulate the rotation of a GO in that situation doesn’t work. I have a hacky temporary “solution” that just disables the Animator until the enemy dies, but this doesn’t seem sustainable because i plan on creating a chase animation and can’t have the Animator component off for that.
Can anyone recommend what I should do?
Hey, how with InputSystem read delta control type? action.ReadValue<Delta> not exist struct....
[moved]
please don't crosspost.
Use an aim constraint
One of the animations I'm importing with the fbx file
This is the model with the Animation component enabled and Animator disabled
And when I enable the Animator the animation plays. It's the same clip as in the Animation component.
I still get the issue where if I have the constraint active, I can't use the death animation, but if I turn on the Animator that controls it, I can't get the enemy to move or rotate towards me/the player
Is this a good start for arranging code?
Right, I thought the bucket was a static object. In that case you cannot use non-convex mesh collider as said earlier so you must use compound collider. In your case you don't need too many box colliders (you can add them as child objects) to create that shape. There are some assets available to generate compound colliders automatically but in your case it seems easy enough to place 5 box colliders manually there to match the shape closely enough
alright, thanks
I've been enjoying shorthand if branches a lot, like this one:
movingSpeed = movingDistance > 4 ? 20f : 7.5f;
now Im wondering if there's a way to incorporate another if else condition into this?
sure
movingSpeed = movingDistance > 4 ? 20f : movingDistance <2 ? 7.5f : 8f;
right that makes sense
everything after the : is "do this if false" so then I just repeat the structure there
thanks!
you mean a ternary operator? and yes, you can nest (stack) them, though readability goes out the window . . .
and debugging them is a PITA
does it even catch it? the nested ternary if there is an error?
works for this very simple use case at least, ty
or do you have to figure out where it—the error—is on within the entire nest (stack) . . .
same as any nested construction. Debug by trial and error, lol
I just put a log behind it that writes the distance and speed
Syntactic sugar is all well and good but, tbh, at your level of skill I would stick to plain old if else structures
I appreciate the advice but I really dont see the point of not using this for such a simple case
public async Task typeText(string text,string name)
{
setNameText(name);
for (int i = 0; i < text.Length + 1; i++)
{
setDialogueText(text.Substring(0, i));
await Task.Delay(100);
}
setDialogueText(text);
}
So I have this text typer for dialogue and I want to skip to the end if the user presses the space button
public async Task typeText(string text,string name)
{
setNameText(name);
async Task typer()
{
for (int i = 0; i < text.Length + 1; i++)
{
setDialogueText(text.Substring(0, i));
await Task.Delay(100);
}
}
async Task input()
{
while (!Input.GetKeyDown(KeyCode.Space))
{
await Task.Yield();
}
}
Task[] pray = {typer(),input()};
await Task.WhenAny(pray);
setDialogueText(text);
}
After some searching on google I came up with this mess but apparently you need to use cancellation tokens to cancel the other thread which has not yet ended so I feel like I'm going in the wrong direction with this one, how do i proceed?
Switch expressions are a bit cleaner:
movingSpeed = movingDistance switch
{
> 4 => 20f,
< 2 => 7.5f,
_ => 8f
};
that is horrible. whats wrong with a simple Coroutine?
I can see
Give me a sec
I had a reason to justify it
I just forgot it long ago
that is handy too know, ty
Oh yes I want the function to yield
writing c# used to be my dayjob but it's been a whole lotta time since I last touched it so Im derusting
thats what coroutines do
that's a lot of async going on . . .
i mean not yield
ill just uh
pull up more code
private static async Task waitConfirm(string key)
{
DialogueSingleton.instance.setDialogueUI(true);
List<List<string>> dialogueList = getDialogue(key);
if (dialogueList == null)
{
Debug.Log("Dialogue not found");
return;
}
for (int i = 0; i < dialogueList.Count; i++)
{
List<string> dialogue = dialogueList[i];
Debug.Log(dialogue[0] + ": " + dialogue[1]);
await DialogueSingleton.instance.typeText(dialogue[1],dialogue[0]);
I meant i wanted it to await
mb
ive probably committed several programming warcrimes havent I
look
bool cancelled = false;
void Update() { if (Input.GetKeyDown(KeyCode.Space)) cancelled = true; }
IEnumerator typeText(string text,string name) {
setNameText(name);
for (int i = 0; i < text.Length + 1; i++)
{
setDialogueText(text.Substring(0, i));
yield return null;
if (cancelled) break;
}
setDialogueText(text);
}
sure
wait
Ill just test this
but im not sure if itll work
because the rest of my code is so shit
it's much easier to use the maxVisibleCharacters property for TMP and check input in Update that sets a bool to skip and display the remaining text . . .
Oh my bad for not knowing this property of TMP
oh nevermind
sure it works but
actually nevermind it just works
Dont over complicate stuff, the simplest option is usually the best one
what i wanted was to cancel even if it was between states of typing but
I guess if its fast enough nobody's going to notice
I'm watching a tutorial on making an interaction system for my project, as a separate script from the regular action inputs(plan to make it camera-dependent down the line) connected to the Input System so that I can have the Player swap between the Characters that they're playing without having to codify an interaction system for each of the Player's Characters.
I noticed the problem, but unsure how to fix it without adding the Interaction System into the regular action inputs script as shared below.
The script: https://hastebin.com/share/oqoqegoyeb.csharp
The video I'm following it from: https://www.youtube.com/watch?v=K06lVKiY-sY
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
In this video I go over the creation of a flexible interaction system in Unity3D.
Join my Discord! ► https://discord.gg/jrRJgfBz2y
How to Make Player Movement ► https://youtu.be/TOPj3uHZgQk
Extra Resources ►
https://docs.unity3d.com/ScriptReference/Physics.Raycast.html
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/i...
Unity/C# won't allow me to implicitly cast a bool to an int, is that right? are ternaries or Convert.ToInt really my best options for this?
That's right, just use a ternary yeah
unfortunate
Unfortunately your best option is int x = someBool ? 1 : 0
you could make an extension method . . .
it would've been neat to do stuff like x + y * [bool] in a single line
This is a code channel, and that's not a code question. Delete from here and ask in #🥽┃virtual-reality
you can. just replace [bool] with a method that takes in a bool
Create a static class and add an extension method, which converts a boolean to the integer:
public static int Sign(this bool value) =>
value ? 1 : 0;
Thanks for the tip
hello everyone,
i'm doing a asteroid like game and i don't know how to make the asteroids spawn in an random direction and then move at a random speed in this direction, i can send you the code or a video of how my game run but i really need help please
google -> unity how to spawn object in random position
google -> unity how to spawn object in random rotation
google -> unity how to set random rigidbody velocity
oh ok thanks i didn't know those terms because it's my first time using unity and C# but i'l go look at this
the first 2 require no knowledge of terms, but good luck , have fun 😄
anyone have idea why unity become like that
become like what
open pic man
I can see it. You didn't actually say what you're asking about though
do you find the unity editor normal
Just say what the problem is instead of wasting time
can't u use windows name hidden and the ui feels a little weird
i can't see windows name
nope
Close Unity, delete Library folder, and re-open to let it reimport everything
is this 2019 
alright
fixed it by switching to light mode and then dark again
Bro thats definitely an older version 💀