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
3 answers
58 views

Respawn Player to Respawn point when colliding with a Hazard

I have grid movement set up for the player within a set space. The player moves one unit at a time and can move several units when holding down a direction key. I would like the player to respawn back ...
nataliadalomba's user avatar
0 votes
0 answers
39 views

How to scale a room along the z axis so one wall stays in place and only the far wall moves?

I'm a Psychology undergrad working in a spatial navigation lab where we design Unity environments and have people navigate them in VR. There's a lot of stuff we do here that doesn't involve coding, ...
Logan Gomez's user avatar
1 vote
0 answers
24 views

I have a wind simulation in Unity, and i need to rotate an arrow to show the wind direction [duplicate]

I have this code that creates random vectors, which are used in the AddForce to push rigid bodies around. ...
Foneet's user avatar
  • 31
0 votes
3 answers
168 views

How to prevent the player from completely blocking the enemy paths in a tower defence game like Fieldrunners?

I am new to Unity and want to create a tower defence game like Fieldrunners. I need help to create the grid placement area for the towers so that there is always a path for enemies to travel. I mean ...
Robin's user avatar
  • 3
0 votes
1 answer
139 views

How can I make objects spawn at random positions on the terrain?

I want to spawn some objects like trees etc. on my terrain randomly. I use the script below: ...
Makaron's user avatar
  • 35
0 votes
0 answers
44 views

How to add/remove gap between created objects?

I'm creating escalator stairs. In this script i manage the units of each stairs and generating new staris. what i want to do is using the Range attribute to remove/add units/gaps units = stairs and ...
Abraham Krim's user avatar
0 votes
0 answers
71 views

How to launch a 2D character toward the mouse position?

I want to launch a 2D character using the mouse, but for the life of me I can't figure out how to get the character to move left or right during the launch. Its as if the code is ignoring the X axis ...
fabian freund's user avatar
0 votes
1 answer
301 views

How do i check if the script is executing in editor mode or runtime mode?

...
Benzi Avrumi's user avatar
1 vote
1 answer
36 views

Unity type safe CompareTag without using strings

When comparing tags sometimes I can do a typo. For example I might miss type Enmy instead of Enemy and loose some time when ...
mustafa candan's user avatar
0 votes
0 answers
23 views

NullReferenceException: Object reference not set to an instance of an object PlatformController.FixedUpdate () [duplicate]

How do I fix it, I don't know how I fix it? Can anyone help me? ...
anii me's user avatar
0 votes
0 answers
35 views

Continuously reading sensor data from a file

I'm working on a game/app used for relaxing, which is measuring pulse and using it to adjust the world (grow or decrease some trees etc.) I have already found an app for connecting a Fit Band to a PC ...
DatMefju's user avatar
0 votes
1 answer
124 views

How to make the jumping/ground pounding smooth in Godot?

I'm new to Godot (and C# in general, but I use that because that's the language I'm learning in school, and I don't want to confuse myself with GDscript), and I tried to code a 2D player character (...
Mudafucsa's user avatar
0 votes
1 answer
95 views

Why are quads not rendering with OpenTK 4.7.5 when similar code works with OpenTk 3.3.3?

The following code will not render the quads with .Net 6 and OpenTK 4.7.5, but (nearly) identical code works with .Net 4.8 and OpenTK 3.3.3. (Triangles will render fine, but I would rather use quads, ...
AntiHeadshot's user avatar
0 votes
0 answers
15 views

How to change GUILayout depending on selected asset?

I'm making an editing window for some in-game stats. I have a few different stats in there with the same fields, like stats and stats of equipment. Because these fields are so similar, I want to make ...
Dead Lord's user avatar
0 votes
1 answer
58 views

Bullets shooting all over the place

I have created a simple player controller, which contains the player logic for a movement, aim and shooting bullets from a gun. Everything almost works, except the bullets shoot in random directions, ...
Laurens van Oorschot's user avatar
0 votes
0 answers
51 views

How to get information about hovered inline sprite in a TextMeshPro?

I am new to Unity And C#. Usually I can get answers online when I encountered problems, but this one I couldn't find any clue. I know there's a way to detect text by using ...
Hippo's user avatar
  • 1
1 vote
1 answer
61 views

Reduce coupling between various singletons

I'm working on a game that makes use of several singletons such as a game manager, audio manager, and a level loader. The game manager I created has references to the audio manager, level loader, and ...
Mav's user avatar
  • 99
0 votes
2 answers
67 views

Find coordinates in one space from another

I'm trying to determine what coordinates are in one space when given a point in another space. For example, I've got a Matrix4x4 that I can use to convert a point in unity's world space to a skewed ...
Hex Crown's user avatar
0 votes
1 answer
81 views

How to change GameObject position using new Input System?

I was asking myself if you could change the position of a game object with the input of the player, with the new input system. That is, with something like this: ...
Hammynator's user avatar
0 votes
1 answer
167 views

Snake Game body rotation

I am currently trying to make a snake game with Unity. I'm a beginner at C# so I decided to make a game that seemed easy. With the help of this tutorial How to make Snake in Unity (Complete Tutorial) �...
killy dima's user avatar
0 votes
1 answer
166 views

Problems with rotating Child Objects

I'm writing a Transform script for a Monogame project and I'm trying for a few days now to fix the Rotate method of this script, but without success. Currently, the Parent transform only rotates ...
NOrlYNcE's user avatar
0 votes
1 answer
148 views

Delay confirmation pop-up for in-app purchase

I'm trying to implement IAP in my game where the user can buy 100 coins. I have used this video tutorial to implement the IAP and this works fine. I want to implement a functionaltiy where once the ...
single arrow games's user avatar
0 votes
1 answer
82 views

Fire Projectile In Ballistic Motion

I am using the following to calculate velocity: https://gamedev.stackexchange.com/a/114547/39518 ...
PayasoPrince's user avatar
0 votes
1 answer
36 views

Modify ballistic code to not rotate projectile

I am currently using this formula to fire a projectile in my game. Credit to Stephan-B for this wonderful formula: https://forum.unity.com/threads/throw-an-object-along-a-parabola.158855/ ...
PayasoPrince's user avatar
0 votes
1 answer
297 views

Y in transform.position has different value in inspector than in code

I've got very simple code: ...
Shagohad's user avatar
  • 101
-1 votes
1 answer
181 views

Cooldown in the new input system of unity

A few days ago I first used the new input system of unity for my game and I ran into a problem. So basically I cant seem to figure out how to implement cooldown in the new system. Either it just ...
Hammynator's user avatar
2 votes
1 answer
304 views

In C#, is there any performance reason to implement ECS?

The formal ECS specification was developed to address gaming in a JavaScript environment. In any C# translation, this implies all of the classes' members must be public. My concern is that too many ...
user avatar
0 votes
1 answer
86 views

Which is better to use C# and Shader to move textures?

We could use C# code Material.SetTextureOffset to move a texture, and ShaderGraph can do the same by Time and ...
Yun CHEN's user avatar
  • 101
0 votes
1 answer
121 views

How do I send data from client to server using LiteNetLib

I started with the example client and server from here and modified the client to send a response back to the server... which never arrives. What am I doing wrong? How do I do this? Server: ...
gyozo kudor's user avatar
0 votes
1 answer
161 views

Replace Input.GetKey(KeyCode.Mouse0) with New Input System

I was implementing the new Input system for my game, when I saw that I still had a script in my player that wouldnt allow me to start the scene, because the script still operated with the old input ...
Hammynator's user avatar
0 votes
1 answer
24 views

How to implement "Auto Generate Animation" and "Visualize" buttons in custom Button inspector?

I extended the Button class with my own variables. I also had to create an Editor script since Unity manually draws the Button's fields into the Inspector. I just need to know what the functions that ...
CraftedGaming's user avatar
0 votes
1 answer
152 views

Changing GameObject Position with the new InputSystem Unity 2D

I am making a little top-down 2D RPG right now and I'm struggling with the range of my attacks. The problem is that my range is stuck on the right side of my player. This is of course really annoying, ...
Hammynator's user avatar
-1 votes
1 answer
22 views

Cube moving in a laggy way

The movement on its own works perfectly fine, the problem is just that when I move diagonal, then the cube (the Player) is kinda lagging around and you can see its pixels moving to the edges of it. ...
Hammynator's user avatar
0 votes
1 answer
148 views

How to make laser made by line renderer get a effect of continuous damage?

I tried to implement a way of laser attacking. the character will shoot a laser implemented by the line renderer. the laser can detect an enemy using raycast hit, but it seems can only damage once. ...
YOUNG ETHAN's user avatar
0 votes
0 answers
182 views

How to play animation clips (.anim files) through a script (without Animator, Animation Controller)

I'm making a custom sprite-based animation system. basically an "animation component" (legacy) with more features. I want to create my animations within the Unity animation window, which ...
Sad Noodle's user avatar
0 votes
2 answers
463 views

How to deal damage every 2 seconds while enemy is touching the player, rather than every frame?

I have made an up and down movement RPG prototype and I wanted to have a fighting system. I made it so that the enemy follows the player and that I get damage every time he collides with me. The ...
Hammynator's user avatar
0 votes
1 answer
24 views

I can only access the latest instantiated clone. The script only works with the latest instance

I tried to implement a way of attacking. Fire the spear, then retract it. Just like Thor's hammer. But when I fire multiple spears, I can only retract the latest fired one. I don't know what the ...
YOUNG ETHAN's user avatar
0 votes
1 answer
143 views

Detect collision occurring on a parent CharacterController from a child object

I'm creating an audio script for my character and it changes the sounds based on the textures it is walking on. Said character uses a Character Controller component from Unity and I thought of using ...
Astolfo's user avatar
0 votes
2 answers
55 views

How to change from gameplay camera to menu camera when colliding with a game object?

I want to know how to change which camera is outputting to the screen when colliding with another game object in Unity. I'm making platformer, and at the end of the level I want to switch from the ...
TheElectricWolf _'s user avatar
0 votes
0 answers
34 views

Convert 3 2D-curves to a 3D-curve and How to calculate weight value of the animation curve in Unity?

I have 3 Hermite curves, including a position at the x, y, and z axes controlled by tangent and weight values. I knew that it is a 2D curve. now I can calculate the tangent from 1st derivative, but ...
Hadestrb's user avatar
0 votes
1 answer
290 views

How do you upload an AudioClip to a server in Unity?

My current approach is to take an AudioClip, turn it into a byte array, then put it into an UploadHandler, attached to a UnityWebRequest, to send a POST request to a server. Right now, when I pass ...
cadburia's user avatar
0 votes
0 answers
28 views

A* on a pong game model [duplicate]

I am doing this project a pong game(in c#) where one paddle is a ball reactive AI and other should be A* AI with max 0.05s think time. I have made a ball tracking reactive AI but I dont know how to go ...
Nomi's user avatar
  • 23
0 votes
0 answers
47 views

Bool not working when I rapidly press assigned button

I'm trying to create flappy bird like game. and this is the scripts. ...
Pekovania's user avatar
1 vote
1 answer
74 views

Shaking UI World Space element when keeping it centered between 2 objects

So I have a ship in the game, and I can click on a Sail to make a World Space UI panel appear. The panel will follow the selected sail and also always Billboard towards the camera. The problem I have ...
questioneeeeer's user avatar
0 votes
0 answers
161 views

Kinematic Rigidbody parented to a moving Rigidbody gets displaced

I have a kinematic Rigidbody parented to another non-kinematic moving Rigidbody. Render-wise, the child Rigidbody does not jitter, nor does it inherit any displacement changes from the parent ...
LifGwaethrakindo's user avatar
0 votes
1 answer
39 views

Move From 0 to "Max Amount" Over Time

I need to create Coroutine that moves from 0 to "maxAmount" over "duration". Can someone please assist me with the proper way to create this loop? Here is my attempt at it: ...
PayasoPrince's user avatar
3 votes
1 answer
692 views

Why does a script named "GameManager" have a ⚙️ icon instead of a #️⃣ icon in the project assets?

I am learning to use Unity for game development and one of the scripts in the Unity project window has a weird icon vs the other scripts. I'm not sure if it's something I should be concerned about or ...
KS9000's user avatar
  • 33
0 votes
2 answers
160 views

Whats the best way to handle large amounts of animations in unity for unique units?

So atm im working on a game where we need many different units each with their own animation set. Is there a way to automate this process? or do we have to create blend trees manually with each ...
Angelo's user avatar
  • 28
0 votes
2 answers
88 views

Should dealing damage and healing be the same function called change hp or should they be sepparated into the functions of their own?

I'm making a simple game with sliders, where there is a damage over time function, the main focus of the player is to upkeep the player health as long as possible by clicking corresponding buttons. My ...
koogel's user avatar
  • 65
0 votes
2 answers
95 views

Perlin algorithm generates weird artifacts

I'm writing a Perlin noise generator in C++ for terrain generation but the generator produces weird JPEG-like artifacts instead of proper noise. I've tried doing it using C# in Unity and confirmed the ...
truepaddii's user avatar