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
24 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
20 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
0 votes
1 answer
26 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
2 votes
2 answers
30 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
17 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
26 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
15 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
27 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
0 answers
33 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
40 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
47 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
  • 41
0 votes
0 answers
23 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
56 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
40 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
25 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
33 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
18 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
21 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
  • 101
0 votes
0 answers
15 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
46 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
25 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
62 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
40 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
33 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
21 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
48 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
21 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
19 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
35 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
0 votes
0 answers
50 views

What is the best approach for achieving DI / testability in Unity development?

Sorry for the fairly open-ended question, but I'm hoping I can get some insight on how to tackle automated testing in Unity. I've been quite surprised to not find a "definitive" approach on ...
user avatar
0 votes
1 answer
25 views

How to keep gui button original color including the white content color?

This is just a test. The PING PONG button color is in Red and also the START/STOP button start with the Red color. but in the START/STOP button i'm trying to keep the original color and then to change ...
user avatar
0 votes
1 answer
32 views

How to change GUI box background color for each gui button individual?

The problem is at this part, the color is changing the background also for the PAUSE button and not only for the PLAY/STOP button. Before i added this part the PAUSE button color changing was working ...
user avatar
0 votes
1 answer
31 views

Why when changing gui box color ith a color variable in the inspector in run time the color on a gui button is not the same?

When setting the color i'm not using the alpha because then it will not change the color at all and it will be transparent. in this line : ...
user avatar
0 votes
1 answer
18 views

How to use pingpong in the waypoints script?

I tried this : And the pingPong is working but after some times changing the pingpong flag true false many times i'm getting index out of bound exception : The pingpong line that give the exception : <...
user avatar
0 votes
1 answer
20 views

Is there an alternative to Update for continuously spawning an object?

What I did here works, but it looks messy and funny to me. ...
user avatar
0 votes
1 answer
16 views

Attach images via script into array unity

I have 3 objects of Image type in game scene. So I need to attach this 3 objects via script into Image array inside of this ...
user avatar
  • 3
0 votes
1 answer
50 views

Action delegate always return null

I have two separate classes(Tree, Inventory), OnCollision I trigger the Interact function, in which there is an Invoke of an Action delegate event TreeCollected, it seems to always return null ...
user avatar
  • 1
0 votes
0 answers
33 views

When drawing a circle around object the radius is seems to be not accurate. what could be wrong with the circle?

This script is attached to a gameobject with a linerenderer and draw a circle around the object it's attached to : ...
user avatar
0 votes
0 answers
29 views

Finger (Sensor) Shaking Detection

I want to make the user be able to shake a certain object through the phone's sensor. I have drag&drop mechanics now, and I want this shake to be directly related to that mechanics. How would that ...
user avatar
0 votes
0 answers
36 views

(FSM) Detect a change on a variable on Update, and trigger certain State

So, I'm working on a FSM that ticks on every frame. The inner workings can be simplified to this: The user (me) creates the States: ...
user avatar
0 votes
1 answer
34 views

How to create IOS style rubber scrollbar in unity?

I'm looking to create a scroll bare similar to IOS scroll when you load page or something when it lets you pull all the way down but the tension gets higher like it is on spring. How would I approach ...
user avatar
  • 127
0 votes
1 answer
36 views

How do I resume the rotation where it last rotates when it got pause?

...
user avatar
0 votes
1 answer
82 views

Is there a good practice for defining names programmatically?

In my use of Unity so far, I've been defining element names programmatically with classes like this: ...
user avatar
0 votes
0 answers
23 views

Unity Photon doesn't add physics to the second connection

I am trying to make a multiplayer air hockey game in Unity, but encountered some problems. When the first user creates the room, the hockey puck is spawned along with the first player's mallet (the ...
user avatar
  • 101
1 vote
1 answer
85 views

Speed up Reaction-Diffusion simulation calculations in Unity

I'm trying to use Unity Job system to speed up some calculation related to Reaction-Diffusion simulation. The calculations requires 2 matrixes, current and ...
user avatar
  • 117
1 vote
0 answers
28 views

How can I instantiate an object at a certain position?

In my game, the player drives a car and when the car reaches the end of the road, I want a different road prefab to be spawned. I have multiple road prefabs, and want to be able to spawn one when the ...
user avatar
0 votes
1 answer
22 views

Why lookat is working but when using slerp to rotate smooth to look at the same target is not working?

This is the part when i'm trying to rotate the objectToThrow smooth slowly. ...
user avatar

1
2 3 4 5
157