Questions tagged [c#]

C# is a multi-paradigm, managed, strongly typed, garbage-collected, programming language created by Microsoft in conjunction with the .NET platform.

Filter by
Sorted by
Tagged with
0 votes
1 answer
45 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, ...
Samuel Slade's user avatar
0 votes
0 answers
61 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 ...
PayasoPrince's user avatar
0 votes
0 answers
17 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 ...
Jojo's user avatar
  • 1
1 vote
1 answer
32 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 ...
erikstagg's user avatar
0 votes
0 answers
30 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 ...
rasputin's user avatar
-1 votes
1 answer
75 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...
Timesters 's user avatar
1 vote
0 answers
48 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 ...
a183's user avatar
  • 11
0 votes
0 answers
40 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: ...
weekdays's user avatar
0 votes
0 answers
51 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: ...
modernator's user avatar
  • 1,133
0 votes
0 answers
59 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....
Mamad R's user avatar
  • 113
0 votes
2 answers
43 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 ...
BobBarker's user avatar
0 votes
1 answer
59 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 ...
AND4011002849's user avatar
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 ...
nataliadalomba's user avatar
2 votes
3 answers
117 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 ...
nataliadalomba's user avatar
1 vote
1 answer
206 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 } ...
Felox's user avatar
  • 65
1 vote
2 answers
87 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: ...
StuckInPhDNoMore's user avatar
0 votes
1 answer
61 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): ...
Majs's user avatar
  • 363
0 votes
2 answers
190 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 ...
jasmine zhao's user avatar
0 votes
1 answer
66 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 ...
Craving_gold's user avatar
0 votes
0 answers
51 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 ...
naenae baby's user avatar
1 vote
2 answers
55 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 ...
nataliadalomba's user avatar
0 votes
1 answer
40 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. ...
nataliadalomba's user avatar
0 votes
2 answers
69 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 ...
nataliadalomba's user avatar
0 votes
0 answers
26 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 ...
IronWaffleMan's user avatar
1 vote
1 answer
45 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 ...
nataliadalomba's user avatar
0 votes
1 answer
456 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 ...
mustafa candan's user avatar
0 votes
1 answer
223 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 ...
Džoni's user avatar
  • 1
0 votes
1 answer
253 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. ...
arcadeperfect's user avatar
0 votes
0 answers
30 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 ...
IronWaffleMan's user avatar
0 votes
1 answer
96 views

Creating Asset Bundle in Unity 2021

I am using this code snippet in unity 2021.3.16 to create Asset bundles: ...
Muhammad Faizan Khan's user avatar
0 votes
0 answers
38 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 ...
Taras Fityo's user avatar
1 vote
2 answers
341 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 ...
PlayerWet's user avatar
  • 113
0 votes
0 answers
66 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 ...
Sternutation's user avatar
2 votes
0 answers
86 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 ...
DyingIsFun's user avatar
  • 1,527
0 votes
0 answers
71 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 ...
m0a's user avatar
  • 115
0 votes
1 answer
24 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 ...
TBG's user avatar
  • 25
0 votes
1 answer
46 views

How to get Update to acknowledge variable value from other method

So I'm trying to write a script in Unity where, when right clicking while the mouse is being followed (I changed it so the cursor is replaced instead, but that's off-topic), that the cursor will ...
gtc26's user avatar
  • 3
0 votes
1 answer
112 views

How to get a type other than GameObject using GameObject.Find?

I am Using Unity 2021.3.13f1. I need to find an object in my scene and its type is TMP_Text. I'm trying to use the following code: ...
Mike1979's user avatar
0 votes
1 answer
51 views

Create after image effect following behind character

I'm currently trying to achieve an effect like this, except wirh a 3D character: I've tried a variety of of techniques but have fallen short, I feel like I'm on the right track but just missing ...
Jambo's user avatar
  • 11
1 vote
0 answers
59 views

How can I implement a cursor object that is controlled by either a keyboard or a gaming controller?

I'm looking to implement a cursor object similar to the ones from certain tactics RPGs (think Fire Emblem, FFT, etc.), but I'd like for it to be controlled by either keyboard keys or controller ...
NJJ_002's user avatar
  • 19
0 votes
1 answer
179 views

How do I add a pointer to my XR Interactor line visual?

I am setting up my project with XR Interaction toolkit. As usual, there are two red rays from the controllers after the set up as shown below. However, I want the rays to appear exactly as it is in ...
Craving_gold's user avatar
1 vote
0 answers
55 views

How to make entities fall through illuminated side of collider?

I'm trying to make a prototype, but I'm still new to Unity so not sure what's the best approach to take. Consider this arena: Essentially, I want the shadowed parts of the outer rectangles to behave ...
IronWaffleMan's user avatar
1 vote
2 answers
196 views

Distributing objects on an infinite map with density decreasing with distance from the center

I'm working on a game that has a procedurally generated world akin to Minecraft, but in 2D. I'm generating my terrain by using Perlin noise to determine heights and type of terrain. The advantage of ...
Charles Nough's user avatar
2 votes
1 answer
386 views

How to make a Unity navmesh agent keep distance from the target

I want my enemies to follow the player, stop at a certain distance and when enemy is within that distance he will walk away. ...
Foneet's user avatar
  • 31
0 votes
0 answers
59 views

I'm having trouble getting my player to climb up the edge

I am building a free climbing system for a 3d Game like in Genshin Impact but I can't get my player to climb up the edge, I used double raycast to detect if it's an edge or not, if there is an edge, ...
Dev 's user avatar
  • 1
0 votes
0 answers
61 views

How to move a Rigidbody2D to exactly match the movements of another body?

I'm recording the velocity of a Rigidbody2D using Animation Curves and I need to reproduce the same "movement" on an instantiated prefab (we really need "stuck like glue" movement ...
Igor's user avatar
  • 219
0 votes
1 answer
123 views

Make ready player me Avatar replicate animation from Mixamo by pressing an oculus quest2 controller button

I have a ready playerme avatar that I rigged with Final IK. I downloaded an animation from mixamo to play with this avatar. My goal is to animate the avatar with the downloaded animation once a button ...
Craving_gold's user avatar
0 votes
0 answers
24 views

Building platformer levels in Unity - making grids of many GameObjects vs. creating the world only in code and recycling fewer GameObjects to show it?

I am familiar with the common method of creating a world for a 3D platformer, where game objects are painted on a grid to create a world, as illustrated here. However, in doing so, it seems apparent ...
mike's user avatar
  • 471
0 votes
1 answer
75 views

Can player input be missed while yielding WaitForSeconds?

I just wanted to fact check myself on a scenario where the player may be locked out of input. With this example, there is a chance that the player's input will not be received if they happen to press ...
PayasoPrince's user avatar
1 vote
2 answers
59 views

Faster approach to iterative pixel mapping in Unity

I need to take an initial Texture2D and, depending on four sliders, remap the RGBA channels. What I currently have works, but is not very performant, especially with larger images. ...
Jesse Williams's user avatar