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
1
vote
1answer
45 views

How do I get a range of vertices/edges using a half-edge data structure?

I have a half-edge data structure in 2D which loops through edges in a triangle in a clockwise order. I'm trying to get a range of vertices within a target vertex. Let's say I want all vertices within ...
0
votes
1answer
34 views

How to sync the speed of a rigidbody and the speed of a running animation

I have a character with a run animation. The animation was downloaded from mixamo.com. In the animation controller, the physical update mode is selected. How do I change the speed of an animation ...
5
votes
5answers
2k views

Should we have multiple scripts doing only one thing, or one large script?

I'm currently working to make a game, and it's a first for both of us. We are at the point where we are starting to have a lot of scripts pile up, and are wondering about the resource management & ...
0
votes
0answers
42 views

ComputeBuffer Values messed up when calling the dispatch many times in a row

I'm having a RWStructuredBuffer called AffectedVertices give me random data instead of 1 simple value to resultAffectedVertices, ...
0
votes
1answer
76 views

How to run a DOTween tween on float and apply it to a component on each update?

I am trying to use DOTween by tweening a float and then applying that float to the parameters of a gameObject's components on each update. In LeanTween, this was done like this: ...
1
vote
1answer
77 views

Unity - How to store a Dictionary in a serializedObject property

I'm writing a custom editor for my GridModel object. The object has 2 fields; Vector2Int dimensions and a ...
0
votes
1answer
25 views

Compass objective indicator points towards wrong direction

I have a compass that is pointing towards player forward direction. ...
0
votes
0answers
30 views

How can I change the moving objects speed at runtime?

The manager script ...
0
votes
1answer
31 views

Flappy Bird Pipes not colliding with with Square

So, I'm quite new to game development and am trying to make a clone of flappy bird. The way my game operates is that I am spawning the pipes to the right of the camera, and then making it move all the ...
0
votes
2answers
73 views

Why do objects spin in circles instead of stopping when reaching their target?

This script is attached to each drone. ...
1
vote
1answer
19 views

Why the target variable can't find the object name "Base"?

"Base" is in another scene but I thought Find will find it even if it's in another scene. ...
0
votes
2answers
33 views

How can I spin object randomly change direction every x seconds on the y axis only?

Even if I set the value 1 on the y only on the spinAxis variable and leave both x and z 0 it will spin also on the x and z. How can I make the objectToSpin to spin only on the y axis ? ...
-3
votes
1answer
61 views

Can anyone explain this code? C# Unity [closed]

Can someone explain this code to me? ...
-1
votes
1answer
62 views

How can I check how long the player has been playing for?

How can I check how long the player has been playing for in Unity?
1
vote
0answers
48 views

How to create a shortcut to a folder in Unity, using c#?

My game saves screenshots in the persistent data path Path.Combine(Application.persistentDataPath, "Screenshots");. I would like to create a shortcut in ...
0
votes
1answer
47 views

Determine when a character is stationary, and which direction they are facing

I'm currently trying to figure out two things for my character's movement and animation. A better/faster way to track when movement stops than the IsSleeping method. A way to track which direction my ...
2
votes
1answer
129 views

Grid: Spreading temperature

I'm trying to spread temperature values evenly across the grid (Room) but somehow it has a bias to the right side of the map. My basic math skills are non existent so i could use some help with the ...
0
votes
1answer
41 views

How do I add a jump to my character controller?

I have watched a tutorial on how to add third-person view that uses character controller and I am looking for a way to add a jump mechanic. My code: ...
1
vote
1answer
32 views

How can I stop this timer from another script?

Here is the script: ...
0
votes
1answer
20 views

How to make a sprite face the mouse while remaining upright, without negative scale?

In the game I'm creating I have a sprite that needs to constantly be facing the mouse, but the sprite also always needs to be facing "up". Because of the Polygon Collider 2D and Shadow ...
2
votes
1answer
80 views

What kind of math is used by this camera panning script?

I'm not fluent in English so I apologize in advance. I have found a source code in order to pan camera by touch - here it is: ...
-1
votes
1answer
83 views

Fire only the currently equipped weapon, not all weapons

I have two guns and two different functions for it. I pick up the weapon by making weapon a child of the parent player. When the player presses the "Fire1" button, I want only the current ...
1
vote
0answers
28 views

How to achieve something like anti-aliasing on 8x8 pixel font using TextMeshPro

I use TextMeshPro for my UI text. My text is currently very crispy and looks like this I'd prefer if it looked more like text in 90s arcade games, with more "...
1
vote
0answers
24 views

How to correctly rotate object using clamping and euler angles?

I've a player (a space-ship ;) that can rotate from -x to +x value (so clamped). So, before apply rtoation i check it: ...
0
votes
1answer
34 views

Overshooting when traversing between two points with a set velocity

I'm creating a prototype for something I may make into a game and I've run into difficulty in creating a method to move a ship along a line between two points. While it reaches the end point, it ...
1
vote
1answer
133 views

Unity C# XML How to load a saved position and a saved stage

I have a problem. I already figured out how to save the player stats (including the player position). But every time I load it back, the player ends up in the saved position but still within the open ...
1
vote
0answers
71 views

How to validate an Exception occurred as expected in a Unity Test?

I am trying to write unit tests in Unity that assert that logs, errors, and exceptions are raised as expected in my code, but I'm getting inconsistent results. I'm using ...
1
vote
0answers
77 views

Rendering between two DrawMeshInstanced() calls in Unity

I am working on a 2D shmup that requires rendering thousands of animated bullets and animated medals on screen at the same time. I use a standard pooling method to activate and deactivate these ...
0
votes
0answers
26 views

How can I spawn a gameobject based on its rarity rate? [duplicate]

I want to spawn my obstacles based on their rarity rate (between 1-5). I am confused at how to handle the condition where random value equals to multiple obstacles with the same rarity rate. I thought ...
0
votes
2answers
70 views

How can I access a ScriptableObject from C# class?

I adjust my level settings in a Scriptable Object and I want to access that Scriptable Object from a non-Monobehaviour C# class. When I use ScriptableObject.CreateInstance<> method, I get ...
0
votes
1answer
78 views

How do I make an object bounce off the wall?

I am spawning objects at a random place at the top of the screen, tilted at a random angle like this: ...
0
votes
0answers
21 views

List<Vector3> of line segments (start, end position) from jointed CapsuleCollider chain

What I'm trying to do I'm trying to create a list of positions which I can use to define a centripetal catmull–rom spline; however I can't think of a solution for creating the list of positions which ...
1
vote
1answer
44 views

Sprite won't flip properly

I have a waypoint script I use to control enemy patrol movement in a given area. I use a reference to the Sprite Renderer to change the sprite facing direction. It starts with flipX set to false, by ...
1
vote
1answer
47 views

How to fix animation script so that humanoid character holds their weapon

I am trying to follow this tutorial video about setting up an third-person shooter character in Unity. But my character will not hold their weapon. I'm also getting the following warnings in my ...
1
vote
1answer
64 views

Help on calculating distance between player position and other object collider end

So, imagine the drawing in 3d and obstacle is in front of the player, and I do a raycast for checking in front of the player and if the raycast hits the obstacle the player needs to check both left ...
1
vote
1answer
41 views

Unity LoadScene did not seem to work properly

My logic is simple: after conditions are met, display an image (an Image class instance) and restart the stopwatch. After a certain time, reload the scene. In a <...
1
vote
0answers
26 views

Handling Multiple Collisions for 2d Platformer

I am looking for ideas on how to handle multiple collisions. For example: currently if my player character lands on an enemy tagged object, a raycast handles collision detection for a seamless kill. I ...
0
votes
1answer
53 views

How can I make an object follow behind the player with respect to its rotation such that the player never faces it and always remains behind them?

Below is a sample of my current code. It doesn't even move the object at all. I thought I could first get the current forward y rotation of the player and then flip it to get the backward rotation and ...
0
votes
1answer
80 views

Unity IAP - Collection was modified; enumeration operation may not execute

In Unity, after importing UnityIAP Version: 2.3.0, I have a button to which I attached an IAP Button component like in the image below: My SkinsPanel class looks like this: ...
0
votes
2answers
308 views

How to set a variable from the selected text of a dropdown menu in Unity?

I am trying to set a variable from the value of a DropDown menu in Unity. I wrote a script as follows, attached it to the dropdown and set it to run it in Unity under: On Value Changed (Int32). I have ...
2
votes
1answer
83 views

How to make mouse pointer be the vertex of a drawn parabola when estimating the trajectory of a projectile?

I'm trying to remake an old flash game using Unity. The main mechanic of the game is to make the basketball pass over the mouse. Here's a video of the game: https://www.youtube.com/watch?v=6sArMC1l_Sc ...
0
votes
1answer
81 views

Making vehicle using WheelColliders faster

I have a driving game and use wheel colliders to control cars, but whatever I change with the WheelCollider components it doesn't get faster and is way too slow. The code of the controller: ...
1
vote
2answers
136 views

Regarding performance, when is it okay and and when is it not okay to use LINQ with Unity?

As the title mentions I am interested in LINQ performance in Unity. When is it okay and when is it not okay to use it? As I understand it is bad to use it in something like ...
0
votes
0answers
40 views

How can I make the look at to be smoother slowly when using IK?

The script is very long so I will zoom in the specific script places of the problem and in the end I will add the full script too. The problem is at lines 209 - 235 when the player is smoothly looking ...
0
votes
1answer
50 views

Point System Using a GameManager?

I am trying to use a GameManager script to store and hold my players points, across multiple levels. The problem is that I have no idea how I should implement this. Should I declare the points ...
2
votes
2answers
96 views

Finding nearby tile objects with a certain tag more easily

I have generated a grid with hex tiles. I am using two different types of tiles and would like to at some points ask the tiles, how many tiles of each type they have as neighbours (or really, it would ...
0
votes
1answer
29 views

Unity UI Image not rendered?

In Unity I created a Panel with 3 children (An UI Image (LogoAch), and 2 TextMeshPro components (Name, Progress)). It looks something like down below: I saved this as a prefab and I try to instantiate ...
1
vote
1answer
70 views

Why the distance is never less than 1?

The distance is 1.07 and changing sometimes at this point the distance is 1.06 or 1.07 more or less this range. ...
0
votes
2answers
69 views

Help with multiple powerup types

I am trying to have a single class that handles multiple powerups types and using enum for the types of power-ups and switching the powers based on enum however when there are multiple power-ups in ...
0
votes
1answer
32 views

Change Sprite's Position

I have a sprite attached to the player like an accessory and it flips along with the player when moving in the opposite direction. However, due to the player being a dog, when flipped, the accessory ...