Questions tagged [c#]
C# is a multi-paradigm, managed, strongly typed, garbage-collected, programming language created by Microsoft in conjunction with the .NET platform.
8,483 questions
0
votes
1
answer
152
views
How to change layer depth according to player location?
I would like to change the layer depth of objects, so that the player can go behind them. Right now it looks like this when the player is behind the object:
The problem is that the layer depth doesn'...
0
votes
1
answer
147
views
Detecting Mesh Geometry Irregularities in Unity
I am trying to create a function to detect mesh geometry irregularities — for instance, the mesh possibly contains a missing face or possible normal flip problem.
To detect the missing face, I ...
0
votes
1
answer
117
views
Why does this movement script prevent you from jumping if you're running forward (but running in other directions does allows jumping)?
This is a rigidbody-based movement script. I notice that it doesn't let you jump while you're running. This problem persists whether you are using new Input System or not (I tested both ways).
Notably,...
0
votes
2
answers
93
views
Unity Camera snaps back to camera mouse look after lerping to a point and rotating normally. Once mouse look is re-enabled it overrides and snaps back
I am trying to get the camera to rotate towards a location and position. Which works at the moment, but once it is done and re enables the mouse look script or bool in the script the mouse look ...
0
votes
1
answer
122
views
How to add gameTime to movement with acceleration and diagonal normalization?
I recently started rewriting my engine from scratch, because the old one was my first attempt and the structure was very messy. Everything has been going great, but now I'm being held back by some ...
0
votes
1
answer
103
views
I'm trying to find a way to iterate through a list of game objects to find furthest object in the list. Then re iterate if path is blocked
I've got the first part of the code working. It iterates and does a check through the gameobjects to find the furthest nav point to hit. Then it calculates path to see if its valid or not. Now I'm ...
1
vote
1
answer
419
views
Curved Grid Layout Group
I can't find a quick answer anywhere, besides adding a 100 line script that I'm pretty sure is outdated. As the title suggests, I am trying to curve a grid layout group. I also want the children of ...
1
vote
1
answer
375
views
How to pause or slow down/speed up Time.deltaTime when it is inside the Update() method?
My player is able to dive for a limited amount of seconds (let's say 10 seconds) while swimming. When he's not diving his breath gauge fills up again to a max of 10 seconds:
...
1
vote
3
answers
432
views
Add wobblyness to moving object
I've been working on a custom enemy "AI", the way it works is it generates a point inside a colliders bounds, then moves the enemy towards the point. Once the enemy reaches it. The point is ...
0
votes
1
answer
68
views
Make attack particles at collision point?
I'm working on a 2D game, it has some basic combat but I want to spice it up a bit with some effects.
First I added a flash when you get hit but I also wanted to add some particles.
I thought it would ...
0
votes
0
answers
283
views
Graphics.RenderMesh in update with massive loop
I have millions of objects that I want to render. I found that instantiate is not suitable, so I'm using Graphics.RenderMesh which is amazingly fast and light. But here comes the problem: it takes CPU ...
0
votes
1
answer
89
views
KeyCode field in custom inspector
I'm making a custom inspector for my script, and I have an option to pick a KeyCode as you can see below
However, now that I'm using a custom inspector, I don't know how to add a Keycode Field.
I ...
0
votes
0
answers
50
views
Physics Material 2D Not Working When Object Rotating Around Player
I am trying to make a clone of florr.io (I'm not getting sued I know what I'm doing), assuming you don't know what that is, it is a game with petals rotating around you. I'm using a parent object ...
1
vote
0
answers
180
views
How to enable undo functionality in a custom Unity inspector?
I'm working on a custom inspector/editor for my player controller, the issue is every time I change something and click undo, the undo just undoes clicking on the object not modifying the value. After ...
0
votes
2
answers
192
views
Why am I getting a "NullReferenceException: Object reference not set to an instance of an object" Error when calling List.Contains()?
I'm trying to make a randomized generation engine for a top down dungeon crawler, in the Binding of Isaac style, however, the code is throwing out a multitude of errors when I try it compare a value ...
2
votes
2
answers
369
views
How to make the player pass through only certain objects, but not others?
Experimenting with my 1st Unity project. It's about a top down swimmer. By toggling the swimmer's collider, he can swim under boats:
...
1
vote
1
answer
168
views
Rhythm game, Sync music start with the start of the level in fixedUpdate
I'm working on a rhythm based android game similar to Guitar Hero.
I have a kinematic rigidbody moving downwards with tapobjects (colliders) inside which need to be pressed when moved above the button....
0
votes
1
answer
67
views
Camera not following the player after spawn
After my character spawns, the camera just stays in the same place. How can I solve that?
Here's my code:
...
0
votes
1
answer
106
views
How to check for collisions between objects with the same script?
I am creating a game where there would be two objects instantiated. Each one has a script (to check for collisions), a Rigidbody2D component and a ...
-1
votes
1
answer
46
views
2D rotating on z axis according to Time.deltaTime not working properly
This is in 2D by the way.
...
1
vote
0
answers
53
views
how to resolve this compile error referencing code in a 3rd party asset?
I am having a problem importing code from a 3rd party asset into my project--this is an asset I purchased off the Unity asset store. I did contact the vendor but haven't heard back.
The error I am ...
-2
votes
1
answer
113
views
How to make a coroutine private in Unity?
I am trying to make a coroutine private in Unity. I have tried declaring it as a private method, but it still seems to be accessible from other classes.
Here is an example of the code I am using:
<...
0
votes
2
answers
212
views
How to spawn a road at the end of a current road and delete the previous (Endless Road Spawner)
I'm creating a game in unity for my school project similar to a mobile game called Traffic Racer which is essentially an endless runner. Due to my current scripts, I need to spawn the road at the end ...
0
votes
1
answer
1k
views
Cannot convert bool to System.Func<bool>
When I run this script in Unity: (ignore the clones variable)
...
0
votes
0
answers
183
views
Attach Generic Type UnityAction from delegate to Generic Type UnityEvent
My question is more C# than Unity, but it relies on a Unity specific delegate, also, sorry if the title is not that clear to what I'm trying to do.
I have implemented a simple event manager which uses ...
0
votes
1
answer
68
views
12
votes
3
answers
6k
views
How can I structure my game like a "classical" program?
How can I setup a Godot 4 project in the way of a "classical" software project? With a Main function. Openable in any IDE. Compiling to an executable file ...
0
votes
0
answers
142
views
Destroyed object's transform is null by LateUpdate but not other components in Unity?
one of my players always, consistently get a NullReferenceException in a "will be destroyed" behaviour. No other report were sent (they are automatic). Only from that device and I couldn't ...
0
votes
1
answer
55
views
Sawblade's spin stops or jitters when swiping to steer it
I have a 3D object, a blade, that I want to rotate continuously
on the x axis, like it's cutting through something.
I also want the player to control its z-axis rotation by swiping.
It's mainly ...
0
votes
0
answers
345
views
Client Player not moving - NetCode for Game objects - NetworkTransform
when the host try to move it works perfectly fine, but on the client, the client player does not move
...
1
vote
1
answer
183
views
How to call every method with a certain name from a set of classes in C#
I have the following case:
I have a class called App.cs and here I have a function called Render, that runs once every frame:
...
0
votes
1
answer
346
views
Implement Singleton that loads before Awake
I would have liked to comment on this answer, but I don't have enough reputation so I had to open this new one. The issue with it (and with the rest of the answers) is that it doesn't work well if ...
2
votes
1
answer
91
views
How to Refactor a Unity PoolManager Class for Generic Object Pooling?
I'd like to refactor my pooling class to work for more object types in my top down Unity game. Right now it's working fine for player projectiles, but I want it to also work for enemy projectiles, ...
0
votes
0
answers
102
views
commend a player in Counter-Strike 2 programmatically
I'm trying to Automate a Task which involves commending a player in a specific server (unofficial custom server), I looked into several open source project but all of them are deprecated and archived ...
0
votes
1
answer
170
views
Scrolling the screen left, right, up and down based on cameras rotation in Unity with C#
I'm making a building game in Unity and C#
I want to be able to scroll the screen in all 4 directions when in building mode.
At the moment, I can rotate the camera and scroll the screen left and right,...
0
votes
2
answers
157
views
Why is my enemy not moving?
I'm trying to make a 2D Unity platform game for a school project, but I can't seem to get the enemy to move.
...
1
vote
1
answer
548
views
How to clean up list entries when objects are destroyed in Unity?
We are developing an economic sandbox somewhat similar to a mixture of The Guild and Kenshi.
In this game, both the player and the NPCs will often create and destroy (consume) various objects.
The ...
1
vote
2
answers
106
views
Best way to implement a carrying tray in VR using Unity
I need a way to carry objects on top of other objects in VR without jitterness causing the objects to fall through a tray for example.
I've tested with rigidbodies having very high friction, this does ...
0
votes
3
answers
573
views
Simulate Velocity For A Projectile Moving Along A Spline
I'm using Unity's latest Splines package(v2.5) to move a projectile across a spline with speed. It works perfectly and the projectile moves across the spline to it's target with linear speed.
But I'd ...
0
votes
1
answer
150
views
NullReferenceException when object is not null
So in the following code:
...
0
votes
0
answers
278
views
Why can't I limit FPS inside Unity editor?
I have an Unity app that requires a stable fps in editor. The fps itself is really high anywhere from 200 to 280 the problem is that is not consistent. I tried to limit it with the code belove but it ...
2
votes
1
answer
280
views
Detect if a key other than "this" key has been pressed
I'm wondering if there is a way to detect if the key being pressed is NOT matching a specific KeyCode.
I tried using: ...
0
votes
1
answer
156
views
Converting number in name of gameobject into alpha keycode
So I have no idea if there is a way to do this, but I'm trying to find a way to turn an alpha number in a game object name string into an Alpha key code, which I'm going to use in an Input.GetKey.
...
17
votes
3
answers
6k
views
Game loop isn't performing well enough, so my frame rate is too low (Windows Form + GDI+)
I decided to learn about building games, so I picked up C# to use it along with Windows Form - I already have C# experience, so that was the main reason I did so. That said, I tasked myself to build a ...
1
vote
0
answers
106
views
Trying to implement undo system
I've got a problem with my undo system that ive made, the idea is I want to make a sort puzzle game like this => https://www.youtube.com/watch?v=VdXi9UQhOng
WHAT I UNDERSTAND
There is some ...
1
vote
1
answer
131
views
Flying AI shakes when chasing and avoiding obstacles simultaneously
I've got a problem with my flying AI in Unity. When it just chases a target it's ok, but my system contains avoiding obstacles so when it starts to do it, it shakes weirdly.
As I understood using <...
1
vote
1
answer
137
views
What would be the best way to gradually increase the speed of a 2D arcade game with gravity physics in Unity?
I'm somewhat new to Unity, so I'd like to hear some more experienced thoughts on this. I'm using C# if that helps.
I'm currently working on an arcade game somewhat similar to "Doodle Jump" ...
0
votes
1
answer
1k
views
How can I instantiate a prefab in a canvas and have it positioned relative to its parent?
I am trying to load, at run time, a UI prefab and have that display on a canvas. I was following the directions found on this forum. I am able to get it to load and display, but it is not showing up ...
0
votes
2
answers
242
views
Euler Angle X is wrong after using Quaternion.LookRotation
I have an direction that I want the local player hub & camera to rotate at.
The game handles this by using euler angles which Y represents the hub rotation on the horizontal axis & X ...
2
votes
2
answers
268
views
Fast way to calculate angular intervals and occlusion of circular objects in a 2D vision cone
Say I have an agent in 2D in a world filled with circular obstacles of different kind and across many scales (some may be very large, practically filling an agent's view, some may be very small).
The ...