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,366
questions
0
votes
0
answers
20
views
Why doesn't Coroutine work the way I want with if blocks?
I'm making a game and when the enemy dies I keep it in memory. I want the person playing to find the game just as they left it when they enter. I'm doing most of these, but there's one small problem ...
0
votes
3
answers
43
views
How to make camera follow player on Y+ axis only
My player is jumping on sticks, endlessly going upwards, and if they fall, it's game over.
I want the camera to follow the player only when they move up (ie. only on Y axis), not down. If they move ...
0
votes
0
answers
39
views
About Json format and Player Prefs [duplicate]
I'm making an Offline RPG game in Unity. I want to save some things in my game. I have heard of two recording systems for this, one is PlayerPrefs and the other is to save in json format. PlayerPrefs ...
0
votes
0
answers
28
views
Compensate bullets direction towards direction player is moving in
My new prototype is a top down shooting game, the player aims with the mouse and fires projectiles towards the mouse position, this works fine, when the player is standing still.
When the player moves,...
0
votes
0
answers
56
views
1
vote
0
answers
20
views
How do I get a Unity Job to update external data?
I'm relatively new to Unity, and I wanted to use the Job system for a complex pathfinding algorithm, since it will likely be used alongside multiple instances of NPCs attempting to find a valid route. ...
0
votes
0
answers
44
views
Multithreading Chunkbuilding - Thread.Start() acts as it is on the main thread
I'm building a game from scratch using OpenTK, in C#. It is in its base form a mesh-based voxel engine. I have a decent startup on the chunk building algorithm, multiple blocks, block data, etc, but ...
0
votes
0
answers
31
views
Draw Primitives using SharpDX.Direct3D9 with C# .NET Framework
I have a question, How to draw primitives? draw lines, rectangles, circles, text, etc...
For now I can draw text and Lines:
SharpDX.Direct3D9.Font
SharpDX.Direct3D9.Line
However, those lines look ugly,...
0
votes
0
answers
27
views
How could I generate a large 3D mesh from a 2D texture at runtime?
I have a simple black and white texture, where white is a biome, and black is outside of the biome. I want to create a mesh at runtime that is the same shape as the white region and has a ...
0
votes
1
answer
24
views
scale and rotate a cube automatic the cube is never scaling and rotating to the end. how to fix?
the scaling and rotating both are working.
if the automatic flag bool is false and i press the G key each time i can see that the cube is scaling and rotating to the end for example if it's rotating ...
0
votes
1
answer
29
views
How do I move both the child & parent game objects at the same time?
My current code is:
...
0
votes
2
answers
58
views
Type or namespace name 'Collider' could not be found
I asked Mail.RU how to make a script so that when an object is touched, the game will restart. They sent me this:
...
1
vote
2
answers
44
views
Different Spacing of all Children Grid Layout Group
I am creating a top down 2D game, and I am creating randomized triangles on the ground.
Such as this:
This is to enhance the "knowledge" that you are moving.
But it certainly doesn't look ...
0
votes
2
answers
111
views
How can I securely store Gmail SMTP credentials in a Unity project to comply with security guidelines?
I am currently working on a Unity Asset that involves sending emails using Gmail's SMTP server. As part of the setup, developers using the asset are required to input their email address and the ...
8
votes
2
answers
4k
views
Avoiding string literals to reduce memory allocations
In Unity, should we avoid string literals in frequently executed methods (like Update()) to avoid unnecessary memory allocations and instead store string values ...
0
votes
1
answer
63
views
Why are my angle calculations not working properly?
I am using this code:
...
0
votes
2
answers
88
views
Kinematic "dive bomb" motion toward a moving target
Context: infinite runner, stationary player, obstacles move toward player. I have an asteroid that currently Vector3.MoveTowards a moving target e.g. a "rubble&...
5
votes
1
answer
764
views
How to make an authoritative server assign turn order numbers to players once they join?
I'm having trouble developing and understanding Server code. Currently, I'm trying to have each person that joins the Server be given a single digit ID that can then be used for determining turn order ...
2
votes
2
answers
116
views
Turn a 2D array into a 3D map
I have a C# script that creates a random 2D array that is a map for a cave system.
Sample Map:
...
1
vote
3
answers
96
views
Unity Game Architecture
I'm working on a relatively simple game, but even simple games have a lot of moving parts, and I'm running into some architecture issues. Just to be clear, everything works fine, but it feels dirty, ...
0
votes
1
answer
34
views
Understanding transform.forward vs. Converting World Space Forward to Local Space for Ray Drawing
I'm working in Unity and trying to visualize the forward direction of a GameObject. I came across two approaches:
Using transform.forward:
...
0
votes
2
answers
107
views
Why are Quaternions better than Euler-Angles for Godot (when to use which)?
Sorry about the click-bait, I know there are many many reasons why Quaternions and Bases are better than using Euler-Angles. Anyone on a 5 second google search could easily know why!
But I am trying ...
0
votes
0
answers
48
views
Creating Prefabs during AssetPostProcessor from the imported asset
I'm trying to create an automation for our asset pipeline where an imported mesh will automatically be processed into prefabs for each instanced submesh. For example, when I import this FBX ...
0
votes
1
answer
72
views
Turret following the player in the opposite side
i have tried using lookout method then flipping it by 180 degress but it gives me the same result as the problem i had before.
my turret turns left when i move right and vica verse.
To fix this i used ...
1
vote
2
answers
134
views
How to implement C# methods that automatically get called in the game loop, like Unity's Update() etc.?
I've been working on my own game engine for some time, I ideally need a way to create global function implementations to make it easy to do things within the game loop.
Heres an example:
...
0
votes
0
answers
42
views
Frustum culling works correctly but results in flickering meshes
I've written a C# code and Compute Shader that makes frustum culling and it works correctly but it makes the grass flicker. I can't figure out what is behind this issue so I'm asking here. Does ...
0
votes
0
answers
61
views
Frustum culling using compute shader, how?
I'm working on a little project for a while - creating an area where you can spawn a bunch of grass. I've overcame a major headache when figuring out the GPU instancing for the mesh and the code looks ...
1
vote
0
answers
43
views
When making an object that interacts with things, is it better to have one big script or several different small scripts [duplicate]
Im working on a game inspired by Buckshot Roulette but medieval themed, in Buckshot Roulette the weapon can be picked up by the player, who can then point it at themselves or the "dealer", ...
0
votes
0
answers
37
views
GLWpfControl and OpenTK force graphics adapter
I am using GLWpfControl and OpenTK for a Game that I'm developing. The game has a lobby which runs on WPF and C# and I used GLWpfControl for the OpenGL stuff. The problem lies on my laptop that has ...
1
vote
2
answers
96
views
How do i get key input using c#
To change key configuration i need to get the key input but after looking around i havent found any way of doing that using c#.The other way is using the Gd programming language.but i cant do that as ...
0
votes
1
answer
63
views
Camera movement automatically tracking a tool over a surface
I need to create camera movement tracking the clipper hair like this:
I already have a script for the movement of the tool.
I'm using Snapping Player to the Surface of an Object of this pos How ...
0
votes
1
answer
40
views
How to get difference in rotation between 2 objects, but only on one axis
Say I have 2 cubes that start with the same rotation. I wish to track the rotation difference between the 2 about the z (forward) axis. Such that if cube A remains stationary and cube B rotates 30 ...
0
votes
2
answers
101
views
Is it wrong to leave references objects in the game world like 99999 units away
It's hard for me to explain my question with an example. But essentially, I have a game with many craftable items. Each item is a prefab. Each item has many unique scripts and functions on it.
...
2
votes
1
answer
70
views
What does Unity do with a Prefab's Start function when it is assigned to something in the editor?
Unity C#. This is a hard question to phrase, an example explains it the best:
Setup
Create a GameObject called Thing.
Create a script ThingScript and attach it to Thing.
...
0
votes
1
answer
51
views
How to get value of transitionDuration in C# for Unity UI Toolkit
My existing code for this task is:
...
0
votes
0
answers
25
views
Detected the Mesh's Specific material under the click in unity
I have a mesh in unity which is made of several materails. Now if i click on it on a specific location of the mesh, i want to pick its selected materail. Actually the mesh itself have several ...
1
vote
1
answer
83
views
How do I get a client side health bar to update? Netcode for gameobjects
I am working on a multiplayer prototype and am trying to get health bars working. It's working on server side and health is working and subtracting from client side with a network variable, however I ...
1
vote
0
answers
36
views
Stop Jitter On Rigidbody2D From Rotation
I'm currently working on a geometry dash like game, except it is a triangle instead of a square (rubrub calls it a cube). I want it so that it rotates back to 0, 0, 0, when it is touching the ground. ...
0
votes
1
answer
86
views
How to serialize data from C# in a non-human-readable way?
How can I serialize a C# object (class, struct, etc) to a file without that file being easy to read?
Binary Formatter
First I used the Binary Formatter, which worked really well, but there were a lot ...
0
votes
1
answer
76
views
How can I store a list of instances of different classes?
I am making a customizable save system for Unity. In my previous save systems, since they aren't designed to be modifiable, I already know what each save is going to contain.
However, when making this ...
1
vote
0
answers
61
views
How to implement soft-body blobs that don't pass through one another
I am learning about soft-body implementations in Unity recently, and I stumbled upon the game Blob Merge 3D.
It is quite an interesting implementation because the blobs do not overlap one another and ...
0
votes
1
answer
35
views
Error converting singles and floats
I have a custom data type I made called a point.
It has implicit operators to easily convert between a Vector3 and a float[], the reason being Vector3 and Vector2 types are not ...
0
votes
1
answer
47
views
Want get rotation based on the details of four corners of a square
I got four corner points of the object which are
topLeft, topRight, BottomRight, BottomLeft
and are as clockwise.
I want a rotation values in X, Y and Z for unity object to rotate based on the ...
0
votes
1
answer
44
views
Using an InputField to enter a distance and then move an object to a location based on the input: object returns to old position
I have attached a script (1) to the InputField for ease and it displays HA changing when I alter it during run time in the ...
0
votes
1
answer
92
views
My CharacterBody3D Is getting blocked by ramps that act as walls
To summarize, my ramp is acting like a wall even if it is created to have a collision and mesh that fits its shape.
I have tried:
Putting the max angle to 90
using different ramps (CSG & mesh)
...
0
votes
1
answer
17
views
Unity UI Builder InvalidCastException
I am making a custom UI with the UI Builder for my scriptable object that holds some data for the AI Player. It all worked fine until I added a third slider for a new value I needed; now the object ...
0
votes
0
answers
45
views
How would you render 'water' underneath a plane having CPU deformations of 'waves' done to it?
https://i.imgur.com/GkEYhGa.gif
I have a plane mesh that I am trying to make 'water' from by deforming the vertices on CPU in a 'waves' motion. (I know this is not ideal for performance). But ...
0
votes
1
answer
65
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
48
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
76
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,...