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
1
answer
43
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 ...
0
votes
2
answers
396
views
Converting from global coordinates to local coordinates
I am trying to create a Radar/Minimap for the F1 2021 game in C#/WPF. Here is a image of what I am trying to replicate
In the image, the white car (my car) will always face the direction it is going. ...
0
votes
0
answers
31
views
Can layermask be made for colliders in Unity?
I use collider to import a few objects in Unity. And these are triggers. Actually, what I want is, for example, there is a wall in front of me and a key behind it, and I cannot get it from in front of ...
0
votes
2
answers
58
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
2
answers
21
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 ...
-1
votes
0
answers
39
views
How to add smoothing to character controller camera [closed]
I want my FPS character's camera to rotate smoothly. I've been working on this for weeks but I haven't found any solution.
1
vote
1
answer
51
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
78
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.
...
0
votes
0
answers
67
views
NullReferenceException when object is not null
So in the following code:
...
17
votes
3
answers
5k
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 ...
5
votes
3
answers
9k
views
Getting a pixel of Sprite at the cursor position in Unity
Summary: I've been trying to figure out a way to use simple box colliders as a nice and efficient "first pass" collider. For the "second pass", I want to check that the area clicked has an alpha value ...
0
votes
0
answers
44
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 ...
1
vote
1
answer
45
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
0
answers
20
views
Why when switching between scenes the loading transitions is loading empty scene before loading the scene in index 1?
I have two scenes: Opening Scene and Game Scene.
The logic is to play the Opening Scene and then fade out then when the Game Scene has loaded to fade in when the Game Scene is already loaded.
the ...
2
votes
1
answer
886
views
SpriteBatch, trying to reduce draw calls
This my main draw call:
...
0
votes
1
answer
618
views
Calculate Mesh top, bottom, left and right position relative to mouse click position on the mesh
I have a mesh (suppose it can be circle, or rectangular,square or an arc). The geometry of the mesh can be anything. I can click on mesh at any position. From relative to the clicked position, I want ...
3
votes
2
answers
883
views
Efficient 2D grid overlay on tiles without each cell being its own GameObject
So for my game I need the ability to add a grid overlay over my tilemap. Now I don't think that making the grid with each cell being its own GameObject with some SpriteRenderer would be hard to do but ...
1
vote
0
answers
83
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
61
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 <...
0
votes
0
answers
70
views
Include camera movement and calculation in the 3D game
I was sent here by softwareengineering.stackexchange.com.
I am writing a WinForms .NET application using C#. I use SkiaSharp for drawing for performance reasons.
I can already create a cuboid, rotate ...
1
vote
1
answer
4k
views
Issues using NetworkServer.Spawn with Unity and Mirror-Networking
I am using Mirror to handle the networking aspect
When I spawn an object on the network, I Instantiate it on the server and then use NetworkServer.Spawn to notify all clients to spawn the object.
...
0
votes
2
answers
70
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 ...
0
votes
1
answer
26
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
1
answer
228
views
How to set GameObject on tilemap through script
In the built in Tile Palette tilemap editor, you can choose a GameObject brush to set custom tile GameObjects. How would I be able to set a gameObject onto a tile through a script?. There is no ...
0
votes
1
answer
2k
views
Why use Animator.StringToHash?
Using Animator.StringToHash, doing something like:
public static readonly int MyBool = Animator.StringToHash("MyBool");
Could anyone explain why one ...
2
votes
2
answers
87
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 ...
1
vote
2
answers
396
views
Rotating sprite 180 deg
I should say first, that I have the rotation down. Its just that I want my square to rotate exactly 180 degrees. Currently, it will rotate but it will rotate but by less each jump. So after several ...
0
votes
1
answer
383
views
Draw a texture2D at specific coordinates on another Texture2D
I have a ShipTexture and a Sail Texture. I need to draw the sail texture at a specific location on the shipTexture (call it the sailMountPoint) regardless of the location vector associated with the ...
0
votes
0
answers
29
views
Limiting shooting angle only works when facing right
I have a problem with the shooting being limited when the player is turned to the left side. When I set a range from -145 to 145, on the contrary, it does not shoot into this range, but shoots from ...
8
votes
3
answers
2k
views
Change in direction should slow down object and accelerate in new heading (2D grid-based)
I'm trying to implement some sort of faux space physics in my 2D game. I have a top down view of my space ship. You can change direction and set a speed up to a maximum which then accelerates the ship ...
1
vote
0
answers
27
views
Issues with bitmap character spacing
I've been working on a bitmap character renderer for my game engine in C#, however, I've been running into some spacing-related problems.
This script parses the font and gets all the relevant data ...
0
votes
2
answers
68
views
My collisions won't work
I have been banging my head against this one for a while. I am trying to implement a pickup mechanic, using OnTriggerEnter2D, however I cannot get it to work, my player just runs past the coin.
Code:
<...
0
votes
1
answer
2k
views
How to manipulate PostProcessing effects settings during execution with c#?
I need to change the intensity value of my current Vignette effect depending in specific conditions.
So far I haven't been able to achieve this. Please help!
Image of what I want to achieve:
My ...
0
votes
0
answers
37
views
Unity clamping local rotation on LookAt issues
I'm new to game development, and I've been trying to code a "smooth camera" rotation that's limited within the camera's local rotation, using a smoothed cube and ...
1
vote
2
answers
292
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
1
answer
1k
views
Building TMX in the MonoGame Pipeline using MonoGame Extended
I updated MonoGame to the latest development build and noticed the Tiled Map Importer and Processor wasn't in the content pipeline anymore (even after adding both MonoGame Extended Content DLL and ...
0
votes
0
answers
23
views
Second player gets stuck while joining
I get this error message on the console whenever I try to make the second player join.
Failed to find a PhotonView with ID=2 ...
1
vote
1
answer
102
views
Audio won't pause in coroutine
I am making a system where I have one long audio clip made up of voice lines which I want to be able to play one after the other with a variable pause in between.
I press the space key to start the ...
2
votes
0
answers
75
views
How to paint terrain details (e.g. grass billboards) programmatically?
In Unity, is it possible to paint terrain details such as billboarded grass textures programmatically? (The kind that appear vertical and wave according to wind settings.)
What I know so far (or think ...
0
votes
0
answers
45
views
First person jump only works at certain angles
I'm making a basic 3D First Person project using the movement code below, but I can only jump at a certain angle.
How can I fix this so that my character can jump anywhere?
...
0
votes
1
answer
59
views
Weapon flips upside down when aiming to the left
When the player turns to the left, the texture of the weapon turns upside down. How can I solve this?
Shooting Script
...
4
votes
1
answer
7k
views
Orbiting a specific point - Orbiting Camera
How would I create a camera that with the mouse, it allows you to orbit around a specifc position, with the camera always facing that point? I would also like it to be able to always be at a constant ...
0
votes
0
answers
123
views
How do I copy GPU buffers in Godot like in Unity?
How would I convert even a section of the following code, which was taken from this GitHub Source to Godot C# or GDScript?
I'm trying to make a Godot version of this project, but I don't know how to ...
0
votes
0
answers
22
views
Live notifications using PlayFab
I want to integrate live notification, send/receive, in my Unity game using the PlayFab server. Is there an API call for this?
0
votes
1
answer
102
views
Clicking UI button calls event twice
I've designed a game where, when a button is clicked, the moving point stops. If the button is clicked again, the moving point starts moving again.
I only click on the button once, but the ...
0
votes
1
answer
522
views
Unity Build is showing GooglePlayGamesManifest.androidlib' is Missing.?
I was trying to build my unity project but it is showing this GooglePlayGamesManifest.androidlib' is missing AndroidManifest.xml file. UnityEngine.GUIUtility:ProcessEvent (int,intptr)
some more ...
0
votes
1
answer
34
views
Game object ownership not transferring and getting destroyed with the master client
I'm using photon pun. I have a spawner script which instantiates the eatables in the gameplay and right after the instantiation, im transferring its ownership to null. The instantiated game objects's ...
1
vote
1
answer
760
views
issues about combo attack system animation
i have some issues about my attack animations
right now, i'm doing my light attack which has 3 separate attacks and animations. the scripting and trigger works(without animation), but my animation ...
-1
votes
1
answer
64
views
unity onTriggerEnter does not work
so in here there is a box to which i have attaches this script and ATTACH1 is a socket interactor here i want is when the box which i have attaches attaches to that socket interactor the text which is ...
0
votes
1
answer
457
views
How to get reference to board tile object another game object is sitting on?
I am trying to get reference of the object underneath my Player.
I don't know if I am approaching this correctly. Right now, I have a player simply put in the scene, like this:
Then I am trying to ...