Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

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
1 answer
41 views

Implement the snake movement in unity

I am developing a bullet-hell game and struggling to implement the snake movement logic. I try to record the head's positions and update bodies with these positions. ...
user avatar
  • 11
0 votes
0 answers
23 views

How to use scriptable objects for class selection?

I'm trying to make a class selection system for learning and I've decided to use scriptable objects for the classes since it seems like scriptable objects are good for that(?) however I start to get ...
user avatar
0 votes
0 answers
13 views

Problem Cloning Skinned Mesh Renderers Mesh via script

I was trying to clone a rigged mesh via script and change its orientation as the characters face wasn't facing at forward direction. So I created a Editor Script for that: ...
user avatar
0 votes
0 answers
36 views

How to make an Input Buffer?

I'm trying to make an Input Buffer in Unity C# for later projects, and I've only found this old post from 7 years ago — here is the code: ...
user avatar
  • 1
0 votes
1 answer
45 views

How to get selected value in a dropdown

I made a simple survey from a guide on YouTube. The trouble is that dropdowns are not mentioned in there, and I have totally no idea how to get the selected text value from it. I tried multiple ...
user avatar
0 votes
0 answers
14 views

"Attach socket" with Oculus Interaction SDK

I'm trying to recreate the "attach socket" (XRSocketInteractor) from Unity's XR Interaction Toolkit. Has anyone had any success? I've read through the documentation but can't come up with a ...
user avatar
0 votes
0 answers
19 views

Unity ScriptableObjects String Interpolation [closed]

I am sure its possible, but I haven't figured out how. How would I go about using string interpolation for scriptableObjects? Some basic code I have for it: ...
user avatar
0 votes
1 answer
40 views

Why do my image sprites only change after closing the run, instead of when I start the game?

Why do my image sprites only change after closing the run, instead of when I start the game? What I mean by this is that, upon starting the run, it does nothing. But once I hit the play button to end ...
user avatar
  • 3
1 vote
1 answer
37 views

How do i make my game object goes to that specific direction after it bounces off a collision and not behave erratically?

...
user avatar
0 votes
0 answers
25 views

If I have 2 separate scene teleporters in a scene (can exit and enter anytime), how do I specify a location a separate location when exiting them?

I have the main scene "camp", in camp I have two scene teleporters, "cave" and "tent", each teleport into a different scene. The issue I am having is that when I exit ...
user avatar
0 votes
1 answer
34 views

how to have player stay on a rotating platform?

Im making a top down game in unity. in my game there is a platform where the player can stand on. while this platform is moving the player moves with it. here is an example: This almost works like i ...
user avatar
0 votes
0 answers
16 views

How can I pragmatically move a navmesh rigid body when changing scenes?

I have an object with both rigid body and NavMeshAgent attached Which I want to set to a new location on scene change, but there is something weird going on with it. If I just try to set the position ...
user avatar
  • 101
0 votes
1 answer
38 views

Random value is chosen 2-3 times, then after that it's always 1

...
user avatar
0 votes
0 answers
14 views

Unity - One client can control all player objects in a multiplayer game (Netcode and Input System)

TL;DR Clients can control only their player objects with keyboard, but all players with gamepad (using Netcode for Game Objects, Unity Input System and a PS4 Controller) I am working on a multiplayer ...
user avatar
0 votes
0 answers
14 views

RayCastHit2D returning value only once, then stops

I am trying to do a check to make sure the player is not on a wall, so that he doesn't not continue jumping upwards when hitting it, as it returns him as being grounded. I am using a RayCast2D coming ...
user avatar
  • 25
0 votes
0 answers
31 views

Help with particles and raycasting

I have a 3D side scroller style game in which the player flies along avoiding stuff, you know, side-scrollery things. I'd like to add an effect (particle system) to the player when they get close (say ...
user avatar
0 votes
1 answer
31 views

Passing a string as argument to Unity Job System

I have a Job that needs to take some string from main thread and use it locally. Considering that the Job System cannot directly accept the string as an argument, is there any workaround to circumvent ...
user avatar
0 votes
0 answers
51 views

Issue with Goal Oriented Action Planning (GOAP) and multiple preconditions

So I am working on an AI for my game using GOAP. I've been researching it for the past few days and while implementing it on my own I've ran into a problem. Here is a diagram of what I am doing. The ...
user avatar
0 votes
1 answer
47 views

Why use Animator.StringToHash?

Using Animator.StringToHash, doing something like: public static readonly int MyBool = Animator.StringToHash("MyBool"); Could anyone explain why one ...
user avatar
  • 21
0 votes
0 answers
29 views

How does using C# and C++ together with Unity affect efficiency?

I'm new to game dev and I'm looking to use Unity to create a phone game that will utilize neural networking. Obviously, putting neural networks in a mobile game presents a serious performance concern, ...
user avatar
  • 1
1 vote
1 answer
38 views

Centralized Event System with arbitrary number of parameters of arbitrary types

I've coded an event queue system that supports subscribing/firing events with an arbitrary number of parameters of arbitrary types. So I basically declared a delegate that accepts arbitrary parameters ...
user avatar
  • 13
2 votes
2 answers
64 views

Applying upgrades to pickups that do different things

In my game, the player has pickups that they can activate that each do different things. Some examples include: Restore your health Gives you a one time speed boost Give you a bubble that bounces you ...
user avatar
  • 113
1 vote
1 answer
28 views

How to convert ZXY euler rotation to XYZ?

I want to know the values of x, y, z satisfying the following. ...
user avatar
  • 121
0 votes
0 answers
26 views

How to set LineRenderer to single color when selecting AnimationType: None?

The problem is when i'm trying to use the None mode the method IEnumerator SelectAnimation should get only type of IEnumerator and I'm not sure how to use the None mode? When starting with the None ...
user avatar
0 votes
1 answer
31 views

How to change animation coroutine when a variable changes, not every frame?

I want to be able to change the enum animation mode at runtime. This way will start the coroutine every frame in Update, but I want to start the coroutine only if the value of the enum variable has ...
user avatar
0 votes
0 answers
19 views

Unity - Reparenting and resetting child's transform properties offsets it from parent (using Timeline animations)

I am beginning to use Unity's Timeline for the first time. I am creating a simple intro sequence where the Animator Gameobject does a position displacement animation (the movements and rotations are ...
user avatar
1 vote
0 answers
30 views

Saving Tiles in an irregular grid

I have a grid, which the user can expand as he wishes. Since I don't know how big the grid will end up (and many tiles will stay empty) a two dimensional array (...
user avatar
0 votes
1 answer
37 views

Preventing other animations from resetting when a new animation starts playing

I'm playing some animations through a C# script. In such script, I'm not using any other methods except GetComponent<Animation>() and ...
user avatar
0 votes
0 answers
46 views

Increase opacity of a floor plane along the path travelled by a cube

I have a plane object (a normal Unity 3D Plane, but it can be a complex floor in the future) and a cube is moving on the plane. Currently, the plane is transparent. I want to make the plane opaque as ...
user avatar
0 votes
1 answer
56 views

Reference as local variable in Unity c#

In the script below, "btn" is a local variable in OnEnable() method. It's said that local variable is deallocated (lost) when leaving the countaining method. Why this one (btn) is not ? Nb: ...
user avatar
  • 43
0 votes
0 answers
33 views

Unity Input Buffers

I’m working on the framework for my 2.5D fighting game in Unity (it’s gonna be similar to Street Fighter IV) and I’ve got movement down so I want to start adding attacks. Since there’s going to be ...
user avatar
0 votes
2 answers
57 views

How to connect rockets to a space capsule?

I am trying to create a space capsule that has four rockets to balance the capsule. The rockets and capsule haveRigidbody2D and ...
user avatar
  • 3
0 votes
0 answers
43 views

Class component field keeps returning null when it's already assigned a new value

I turned the non-static field to static to make sure this is the only one being used. I only have one GameObject in the scene hierarchy that uses this Class Component. ...
user avatar
0 votes
0 answers
30 views

AsyncGPUReadback.RequestIntoNativeArray - owner has been invalidated

I have the following C# code in Unity version 2022.2.0a12: ...
user avatar
0 votes
1 answer
35 views

How to call an invoke repeating when a bool is true and canceling when it isn't?

I'm trying to make my player launch an object every 3 seconds when a bool is true but I can't InvokeRepeating in Update, ...
user avatar
0 votes
0 answers
19 views

Unity question about tilemap

So if I planning to make big location like for example Stardew Valley with tile size 32x32, should I make all map and just have it, or should I load tiles as player moves to them. I actually new to ...
user avatar
  • 3
0 votes
0 answers
21 views

Need help Slerping position and rotation for a death cam

Issue I have 2 scripts on my camera, one for following the player ( FollowTarget.cs ), and one which is supposed to, over time, Slerp the camera's transform position and rotation around the player on ...
user avatar
0 votes
1 answer
24 views

How to rotate a sphere on its axis with a tilt?

How can I simulate a planet's rotation on the Z axis but tilted x° ( similar to how the Earth's rotation axis is tilted 23° relative to its orbit). I know with Euler angles I'll meet some gimbal lock ...
user avatar
  • 103
0 votes
0 answers
17 views

Variables set in script/Unity do not work in visual studio

I was just trying to set up an array through Unity when this happened. Basically, I set the array size and values through the Unity Inspector, however, it did not register in VS. I found this out when ...
user avatar
0 votes
0 answers
48 views

Pathfinding sprite disappears when approaching the player in Unity

I'm trying to make AI for enemies in my game. I applied a pathfinding (A*) script to my enemy sprite, after which the sprite began to follow the player. But when the enemy approaches the player, the ...
user avatar
0 votes
0 answers
27 views

Need help looking into IndexOutOfRange Exception for my Audio Manager script

basically, its as the title says. I am trying to build a brick breaker game in Unity2D, and I have found myself unable to play the death sound effect (played whenever a brick breaks). ...
user avatar
0 votes
0 answers
67 views

Plot rigidbody path simulating magnus effect

I am trying to create a method that will plot the path a rigidbody will take when simulating a magnus type effect with no gravity in Unity. I realize this approach is a drastic simplification to the ...
user avatar
0 votes
1 answer
47 views

Color glitch with tilemap.SetColor() in Unity

I've been experimenting with Tilemap to display tiles (with random colors) in script with SetColor() and other methods: ...
user avatar
  • 117
0 votes
1 answer
43 views

Game Data Files security in unity

I have some game data files in PDF, excel, and video format. Is there any way to make it secure? Through encryption? I have almost encrypted my all files in .aes encryption format but there is a huge ...
user avatar
0 votes
0 answers
34 views

How to increase the size of an empty object with a "Pathfinding" component in Unity 2D?

I'm trying to make Enemy AI for my Unity game. To do this, I watch this tutorial - https://www.youtube.com/watch?v=jvtFUfJ6CP8&t=1163s. The tutorial describes how to use this pathfinding - https://...
user avatar
0 votes
1 answer
24 views

How to use OnDrop on non-UI elements?

I'm new to Unity and coding (C#), so sorry if this is a novice question. Is the OnDrop function only usable for UI elements? I am currently making an ARPG Card game ...
user avatar
0 votes
2 answers
50 views

How does a "static" IEnumerator work in this context? (The code works, but what is it actually doing?)

I am generating many objects procedurally in my Unity C# app/game such as user interfaces, user profiles, etc. I have made classes which feature static variables/functions to allow this. Everything ...
user avatar
  • 197
0 votes
1 answer
31 views

Remove gaps between 2D trail that is based on particle engine

Hi I'm using a particle engine suggested from this answer I'm trying to create a seamless particle trail effect every similar to this (same) question However, when the vehicle is travelling too fast ...
user avatar
0 votes
1 answer
20 views

Player object changes position when I click the pause button [duplicate]

I have a simple mobile game where every time I touch the screen, the car changes direction. The thing is, I need to implement a pause button, but when I click pause I need the car to stay still and ...
user avatar
0 votes
1 answer
36 views

How to round to a multiple of 0.25? [duplicate]

I have a problem when I any rational number so that it's 0.25, 0.5, 0.75, etc. ...
user avatar
  • 507

1
2 3 4 5
158