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,286
questions
0
votes
0
answers
299
views
Design Pattern for Server and Client Objects in Unity Netcode
I'm struggling with how to solve the general problem of having a server-side GameObject which does most of the work and a client side object that's coupled with it for UI purposes only.
As an example, ...
0
votes
0
answers
158
views
Change textures dynamically on 3D animating object in runtime
I have the following situation, where in I need to animate textures on 3D animating plane in runtime.
There are 5 panels in the unity scene and two buttons, each button, when clicked triggers one ...
0
votes
0
answers
28
views
Unity Thought There Was No MonoDevelop In Scripts in My Code
Weird Unity thinks that the code that I've checked already has a MonoDevelop inside of it, but unity doesn't think so, can you help find what I wrote wrong in these two scripts?
...
0
votes
0
answers
39
views
IsTouchingLayers() does not detect collision
I'm making a tile-based player controller for a top-down game that first throws out a "move point" transform to see if its path is clear, then moves to it if the move point does not collide ...
1
vote
2
answers
303
views
Unity ObjectPool<T> CountActive is not decreasing after a destroy is called
I have made a loop to spawn and despawn a basic sphere gameobject. The issue is that when spawning goes over the max size, it does not decrease the ActiveCount when ...
0
votes
0
answers
56
views
How to hide part of character under slope
As shown in the image below I'm trying to find the points in which a line in the world space intersect a sprite. The idea was to get the corresponding values inside a shader to play around with pixel ...
0
votes
1
answer
82
views
Mouse-Click Movement Using Unity NavMeshAgent Causes Stuttering Upon Reaching Destination
Alrighty, so I've seen a lot of stuttering-related questions about NavMeshAgents but my problem is a little specific to my use case since it has nothing to do with <...
0
votes
0
answers
65
views
How to map south button on gamepad to behave like the left mouse button?
How would I tell Unity that the left mouse button is being pressed when I actually press the south button on a gamepad?
0
votes
0
answers
45
views
Rotating Body Sprites of Snake depending on Direction Moving
Saw a thread with the same issue, but didn't seem like the question was answered: Snake Game body rotation
As shown in the above thread, I have a Snake game that I'm developing for a project. I have ...
0
votes
1
answer
72
views
How do I select more Raycast Mask layers for XR Ray Interactor at run time?
I want to select more layers for Raycast Mask at runtime when I click a button.
I tried GetComponent<XRRayInteractor>().raycastMask. but couldn't find an ...
0
votes
1
answer
116
views
Noise in compute shader related to threadsPerGroup
I have been working on a metaball compute shader for roughly 3 months now, and the only issue I have to resolve is noise in the output Dest[id.xy]. I also asked GPT 4 about the crux of the issue and ...
0
votes
0
answers
35
views
Both players turn around at the same time
i got the main camera following the players but once a player rotate to left or right the other player would do it too at the same time. I noticed that the event happens on void Turning() (on the ...
0
votes
1
answer
68
views
How to add visual movement to a car's wheels?
I'm fairly new to Unity and game development in general, I'm trying to build a basic car and give visual movement to the wheels. The car controls are pretty basic: accelerate "w" key, turn ...
0
votes
1
answer
84
views
Errors in Play Mode test setting Animator parameters
I've just started adding tests to my game project in Unity. I know the difference between EditMode and PlayMode tests. I've written a PlayMode test that triggers a change to the Animator internally, ...
0
votes
0
answers
217
views
Setting Timeline Speed To 0 Immediately
I'm currently using a Signal Emitter to call a method that "stops" my Timeline by setting the speed to 0.
Then I wait for player input to go through some dialogue and then continue the ...
0
votes
0
answers
19
views
Textures don't load on specific scene on web build
I have two scenes: a game room and a test room. Both use all the same code, the difference is that the test room have less stuff so its easier to place isolate objects and see how they work.
Both ...
1
vote
1
answer
40
views
Recursive function for LineRenderer with reflections causes Stack Overflow Error
I'm developing a 2D top down shooter game. I'm building the grenade functionality. The idea is that while you're holding the grenade button, it remains in your hand, and then when you release the ...
0
votes
0
answers
41
views
Discarding pixels of a 2D game object based on its properties in camera render texture
I have a C# script and a shader script that is supposed to create two game objects and discard pixels of the second game object based on whether or not the b value of the pixel as shown in a camera's ...
-1
votes
1
answer
175
views
Parameter "isMoving" does not exist
I was following tutorial video but somehow end up error like this
This is the code
Any clue where is the problem, I tried changing things but still no different...
1
vote
0
answers
83
views
Prefab not instantiating in the next scene Unity
I have a problem with bullet prefab in next scene. In first scene the bullet is instantiated and shoots, but in other scenes the same bullet prefab is not instantiated for some reason. A picture of ...
0
votes
0
answers
44
views
Why does holding the jump button cause the player to go higher each time they hit the ground?
Why is it that when I hold the jump button, my player character keeps going higher and higher each time it hits the ground?
Here is my code:
...
0
votes
0
answers
200
views
CryptographicException: Bad PKCS7 padding
I'm using Unity 2019.4.3f1. I noticed that sometimes the game doesn't launch properly, and figured out, there is an error message like this:
...
1
vote
1
answer
229
views
Destroy and instantiate player prefab
I am new to game development.
I am trying to change the player prefab every X seconds.
For that, I am destroying the previously spawned prefab and instantiating a new prefab.
But I don't know how to ...
0
votes
0
answers
174
views
calculate projectile velocity from moving shooter
I have a task which i have a moving ship that can shoot in any direction i want. i have to shoot to standing or moving nearby objects.
the problem is, I can't correctly calculate true shoot direction....
0
votes
2
answers
45
views
Unable to access an instanced health system
I am having an issue with a health system I am making for my game. I have been at it for 3 days now and have not made much progress. For reference, I am following this tutorial by code monkey: Code ...
0
votes
1
answer
69
views
A*Pathfinding generating wrong path
I'm building a maze game where there's an enemy ready to pursuit the player if the player gets in his range, I'm using A*Pathfinding algorithm to do so, and I build the maze in a procedural way, where ...
7
votes
1
answer
5k
views
Enemy is losing 2 health instead of 1
I am trying to componentize all of my scripts and I would like the enemy to lose 1 health (enemy max health is 3) every time the player collides with the enemy. Right now the enemy is losing 2 health ...
2
votes
2
answers
178
views
How can the player jump on top of the enemy, damage the enemy and the player does not get damaged?
Currently, when the player jumps on top of an enemy, the player and the enemy take damage.
I'm trying to figure out a way that only the enemy gets damaged when the player jumps on top of the enemy and ...
1
vote
1
answer
593
views
Map arrays of game objects to values of an enum in Unity inspector
I want to have a serialized field with an array of game objects for each item in a global enum, like this:
public enum MyEnum
{
Item1,
Item2,
Item3
}
...
1
vote
2
answers
92
views
How do I ensure that an enemy has a maximum of 3 attackers on him?
I'm coding the combat system for my RTS game, and every time a unit spawns I iterate over all enemies and then attack the closest one. This is achieved using the below block of code:
...
0
votes
1
answer
114
views
How to move camera by "grabbing" ground and moving mouse
I want to grab my terrain and move the camera with my mouse, this was fairly simple to do using speed:
Code (CSharp):
...
0
votes
2
answers
806
views
How to get the name of a function added as a listener to a Button's onClick event?
If my button uses AddListener to subscribe a function to listen for clicks:
mybutton.onClick.AddListener(getNameFunction);
Is there a way to get the name of that ...
0
votes
1
answer
366
views
How do I know currently active TMP_InputField in unity
I have a list of TMP_InputFields on my canvas like OTP boxes. I made it in such a way that the cursor automatically moves to the next box once the user types something in the current box. I am ...
0
votes
0
answers
111
views
how do i get my coroutine to update every frame in my BepInEx plugin?
in the code linked below, i am using bepinex and harmony to make a plugin for the game Sons of The Forest
the goal of the code attached is to log the value of an in-game variable every second, but the ...
1
vote
2
answers
91
views
Player transform has not been assigned when player enters trigger collider?
I wrote some code so when the player falls off a platform and collides with a trigger collider called Respawn Trigger, the player's transform position is set to an empty gameObject called Respawn ...
0
votes
1
answer
59
views
Trying to have damage flashing for a short time every time player takes damage
The code below has the player flashing when touching a hazard but continues flashing indefinitely. If I stand on the spike for a few seconds, the flashing speeds up faster than I want.
...
0
votes
2
answers
118
views
Add delay between taking repeated damage from a hazard
I have a 2D platformer and when the player collides with a tile that is on the Hazard layer, the player takes 1 damage. However, I would like for there to be a 2 second delay until the next time the ...
0
votes
0
answers
27
views
How to prevent an object from moving beyond colliders? [duplicate]
I have an enemy object, and it needs to move around an arena. I also have four Wall gameObjects surrounding this arena, and both the enemy and walls have colliders (not set to isTrigger). This is how ...
1
vote
1
answer
58
views
How to flip the scale of just a parent GameObject and not its children
I'm creating a 2D platformer game and I have a Player gameObject in the hierarchy that has its sprite. When the player is facing one way and they press the opposite arrow, I'd like to flip the sprite ...
2
votes
1
answer
3k
views
What's the difference between FindObjectsByType and FindObjectsOfType?
FindObjectsOfType and FindObjectsByType look very similar, both in name and in usage. The only difference I noticed is that FindObjectsByType takes a ...
0
votes
1
answer
899
views
UI Toolkit not firing button clicked event
I'm using the new UI Toolkit and new Input System together, and I've setup everything correctly the Input Actions has separate input for UI, the Input System UI Input Module is setup correctly, the ...
0
votes
1
answer
1k
views
Is it necessary to unsubscribe from C# events when the event owner has already been destroyed?
The following code throws a null reference exception when I stop the project because touchInterfaceController has already been destroyed.
...
0
votes
0
answers
69
views
How to use Look delta values for 2d rotation?
I have InputActions that are pretty much the defaults. Specifically, a Look action that uses the pointer delta (action type Value, control type Vector 2).
How can I translate this information into a ...
0
votes
1
answer
175
views
Creating Asset Bundle in Unity 2021
I am using this code snippet in unity 2021.3.16 to create Asset bundles:
...
0
votes
0
answers
73
views
Initializing prefabs with different scripts
I am creating a tower defense game.
Currently I have 2 different tower types 'Shooting tower', amd 'Unit tower'.
I have a Scriptable object to initialize the tower. It contains some tower properties ...
1
vote
2
answers
453
views
Place effect when colliding player weapon with enemy
I've only been using Unity for a very short time and got stuck at one point. I explain.
It is a 2D platform game. I want that when hitting an enemy with a sword, right at the point where the collision ...
0
votes
0
answers
81
views
Enemy sprite with a raycast ground check is flipping even when it shouldn't
I have a 2D Sprite that patrols around a platform and is supposed to flip when it reaches the edge.
The way the flipping is implemented is through Raycasts. There are two Transforms, on the Left and ...
2
votes
0
answers
154
views
Application of modified MVVM paradigm
Let's assume a game development company uses a modified version of the MVVM paradigm that includes the notion of a Manager which handles manipulation of the Model.
So, the idea is
View - all frontend ...
0
votes
0
answers
297
views
How to set a position relative to my player's direction?
Currently I am setting my Player's position with:
transform.position = new Vector3(target.x, target.y, target.z);
However, the X and Z of this do not work the same ...
0
votes
1
answer
51
views
Platformer enemy with raycast to detect obstacles keeps changing direction rapidly
I am making a 2D platform and implementing a character similar to a Mario Goomba. This character will move left or right, depending on whether or not a raycast determines that there is an object in ...