Skip to main content

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
0 answers
68 views

Reversing the velocity doesn't work after being built

...
Leo's user avatar
  • 1
0 votes
1 answer
25 views

KeyCode field in custom inspector

I'm making a custom inspector for my script, and I have an option to pick a KeyCode as you can see below However, now that I'm using a custom inspector, I don't know how to add a Keycode Field. I ...
Pow's user avatar
  • 404
0 votes
0 answers
32 views

Physics Material 2D Not Working When Object Rotating Around Player

I am trying to make a clone of florr.io (I'm not getting sued I know what I'm doing), assuming you don't know what that is, it is a game with petals rotating around you. I'm using a parent object ...
sammyiscuul's user avatar
1 vote
0 answers
89 views

How to enable undo functionality in a custom Unity inspector?

I'm working on a custom inspector/editor for my player controller, the issue is every time I change something and click undo, the undo just undoes clicking on the object not modifying the value. After ...
Pow's user avatar
  • 404
0 votes
2 answers
86 views

Why am I getting a "NullReferenceException: Object reference not set to an instance of an object" Error when calling List.Contains()?

I'm trying to make a randomized generation engine for a top down dungeon crawler, in the Binding of Isaac style, however, the code is throwing out a multitude of errors when I try it compare a value ...
Thirstierpoet17's user avatar
2 votes
2 answers
154 views

How to make the player pass through only certain objects, but not others?

Experimenting with my 1st Unity project. It's about a top down swimmer. By toggling the swimmer's collider, he can swim under boats: ...
Tomo's user avatar
  • 133
1 vote
1 answer
113 views

Rhythm game, Sync music start with the start of the level in fixedUpdate

I'm working on a rhythm based android game similar to Guitar Hero. I have a kinematic rigidbody moving downwards with tapobjects (colliders) inside which need to be pressed when moved above the button....
delato468's user avatar
  • 111
0 votes
1 answer
29 views

Camera not following the player after spawn

After my character spawns, the camera just stays in the same place. How can I solve that? Here's my code: ...
TheEpikDuck's user avatar
0 votes
1 answer
45 views

How to check for collisions between objects with the same script?

I am creating a game where there would be two objects instantiated. Each one has a script (to check for collisions), a Rigidbody2D component and a ...
Saharsh's user avatar
-1 votes
1 answer
34 views

2D rotating on z axis according to Time.deltaTime not working properly

This is in 2D by the way. ...
sammyiscuul's user avatar
1 vote
0 answers
33 views

how to resolve this compile error referencing code in a 3rd party asset?

I am having a problem importing code from a 3rd party asset into my project--this is an asset I purchased off the Unity asset store. I did contact the vendor but haven't heard back. The error I am ...
tatmanblue's user avatar
-2 votes
1 answer
72 views

How to make a coroutine private in Unity?

I am trying to make a coroutine private in Unity. I have tried declaring it as a private method, but it still seems to be accessible from other classes. Here is an example of the code I am using: <...
Alex Junior's user avatar
0 votes
2 answers
108 views

How to spawn a road at the end of a current road and delete the previous (Endless Road Spawner)

I'm creating a game in unity for my school project similar to a mobile game called Traffic Racer which is essentially an endless runner. Due to my current scripts, I need to spawn the road at the end ...
menaktee's user avatar
0 votes
0 answers
66 views

How to "float" a capsule with a rigidbody component in unity?

I've been stuck in a rut trying to figure this out for a while now. What I want is to have a capsule hover above the ground at a set height to eliminate ground friction and make irregular surfaces ...
Sundayz's user avatar
0 votes
1 answer
287 views

Cannot convert bool to System.Func<bool>

When I run this script in Unity: (ignore the clones variable) ...
sammyiscuul's user avatar
0 votes
0 answers
74 views

Attach Generic Type UnityAction from delegate to Generic Type UnityEvent

My question is more C# than Unity, but it relies on a Unity specific delegate, also, sorry if the title is not that clear to what I'm trying to do. I have implemented a simple event manager which uses ...
Daniel Guiomarino's user avatar
0 votes
1 answer
30 views

Fade-in sprite in TextMeshPro

...
Nader Amir's user avatar
0 votes
0 answers
46 views

Why doesn't my save system work on IOS?

I am building an IOS game in Unity. I have constructed a save system and it seems to function as expected in editor, but does not when I release a build to my device. Additionally, if there is some ...
Devin's user avatar
  • 1
11 votes
3 answers
6k views

How can I structure my game like a "classical" program?

How can I setup a Godot 4 project in the way of a "classical" software project? With a Main function. Openable in any IDE. Compiling to an executable file ...
Zsar's user avatar
  • 235
0 votes
0 answers
67 views

Destroyed object's transform is null by LateUpdate but not other components in Unity?

one of my players always, consistently get a NullReferenceException in a "will be destroyed" behaviour. No other report were sent (they are automatic). Only from that device and I couldn't ...
Tudvari's user avatar
  • 761
0 votes
0 answers
17 views

Client error I can't spawn canvas and asign it to my client player -Netcode for Gameobjects

in my netcode unity c# code I have a host and a client, and each time i try to instantiate a client I get this error even though canvasInstance is not null since it's passing the debug ...
Jamelaumn's user avatar
0 votes
1 answer
34 views

Sawblade's spin stops or jitters when swiping to steer it

I have a 3D object, a blade, that I want to rotate continuously on the x axis, like it's cutting through something. I also want the player to control its z-axis rotation by swiping. It's mainly ...
Nader Amir's user avatar
0 votes
0 answers
119 views

Client Player not moving - NetCode for Game objects - NetworkTransform

when the host try to move it works perfectly fine, but on the client, the client player does not move ...
Jamelaumn's user avatar
1 vote
1 answer
68 views

How to call every method with a certain name from a set of classes in C#

I have the following case: I have a class called App.cs and here I have a function called Render, that runs once every frame: ...
Bogdan's user avatar
  • 111
0 votes
1 answer
96 views

Implement Singleton that loads before Awake

I would have liked to comment on this answer, but I don't have enough reputation so I had to open this new one. The issue with it (and with the rest of the answers) is that it doesn't work well if ...
vandermies's user avatar
2 votes
1 answer
62 views

How to Refactor a Unity PoolManager Class for Generic Object Pooling?

I'd like to refactor my pooling class to work for more object types in my top down Unity game. Right now it's working fine for player projectiles, but I want it to also work for enemy projectiles, ...
Aloof's user avatar
  • 21
0 votes
0 answers
73 views

commend a player in Counter-Strike 2 programmatically

I'm trying to Automate a Task which involves commending a player in a specific server (unofficial custom server), I looked into several open source project but all of them are deprecated and archived ...
AliSalehi's user avatar
  • 101
0 votes
1 answer
78 views

Scrolling the screen left, right, up and down based on cameras rotation in Unity with C#

I'm making a building game in Unity and C# I want to be able to scroll the screen in all 4 directions when in building mode. At the moment, I can rotate the camera and scroll the screen left and right,...
Guybrush Threepwood's user avatar
0 votes
2 answers
99 views

Why is my enemy not moving?

I'm trying to make a 2D Unity platform game for a school project, but I can't seem to get the enemy to move. ...
TheEpikDuck's user avatar
1 vote
1 answer
222 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 ...
stack_ndx's user avatar
1 vote
2 answers
48 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 ...
Richard Muthwill's user avatar
0 votes
3 answers
242 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 ...
PayasoPrince's user avatar
0 votes
1 answer
104 views

NullReferenceException when object is not null

So in the following code: ...
sammyiscuul's user avatar
0 votes
0 answers
121 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 ...
Ivan's user avatar
  • 339
2 votes
1 answer
133 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: ...
sammyiscuul's user avatar
0 votes
0 answers
32 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 ...
Daniel Lip's user avatar
  • 1,757
0 votes
1 answer
108 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. ...
sammyiscuul's user avatar
17 votes
3 answers
6k 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 ...
curiousguy_08's user avatar
1 vote
0 answers
94 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 ...
YouCanCallMe Syarif's user avatar
1 vote
1 answer
78 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 <...
kotan4ik's user avatar
1 vote
1 answer
74 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" ...
soxyo's user avatar
  • 13
0 votes
1 answer
293 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 ...
tatmanblue's user avatar
0 votes
2 answers
130 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 ...
Xprt's user avatar
  • 3
2 votes
2 answers
119 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 ...
kram1032's user avatar
  • 121
0 votes
0 answers
36 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 ...
Lekr01d's user avatar
1 vote
0 answers
32 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 ...
Jessica Jones's user avatar
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: <...
John Hughes's user avatar
0 votes
0 answers
52 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 ...
NovaMaxi's user avatar
0 votes
0 answers
56 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 ...
zaboombafoo's user avatar
1 vote
1 answer
126 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 ...
Michael's user avatar
  • 41