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
14 views

(Fluid Behavior Tree) Random NavMesh position returning the same position, instead of calculating a new one

I have a NavMesh agent that wanders around every x seconds, moves to a random position, and lastly it repeats the sequence. I made a test using a coroutine, which was called through a context menu ...
user avatar
0 votes
1 answer
31 views

How to measure deltaTime? [duplicate]

I'm trying to make a simple console application and don't want to use Unity, but I want to implement a timer, so I would want to use Time.deltaTime.
user avatar
0 votes
1 answer
40 views

Trying to generate a Tile labyrinth in Unity

So I have a generator code that renderes a TileMap on the scene, but It keeps creating a sollid block of walls Where I want it to have empty cells(This is not the final algorythm(Recursive ...
user avatar
  • 11
0 votes
3 answers
48 views

How to flip enemy patrolling side to side with Mathf.PingPong?

I am making a 2D platformer in Unity and I programmed one of the enemies to move back and forth with the ping pong function. I would like to change the local scale depending on which direction the ...
user avatar
0 votes
1 answer
35 views

How to reference a script that's on just one object in the same scene via code?

private TileMovement tileMovement; As you can see in the code above I am trying to reference a TileMovement script, where I ...
user avatar
  • 3
0 votes
0 answers
39 views

Game networking with physics different client and server languages

We are currently having only "turn based" multiplayer games in our party game lobby system. Now we considered to add realtime multiplayer games as well, for example golf in 3D. Our current ...
user avatar
0 votes
2 answers
49 views

How to move an object when a specific event occurs?

...
user avatar
0 votes
1 answer
37 views

Send an array of struct to compute shader

I am using Unity to send two types of data to the Compute Shader: A struct: struct Flock { public Vector3 position; public Vector3 velocity; } And an ...
user avatar
  • 13
0 votes
1 answer
47 views

Transforming world to canvas goes wrong when camera is moving

I am attempting to draw a box around a selected target in my space game. I had this working fine using normal techniques when my canvas was set to Screen Space - Overlay. However my setup is that ship ...
user avatar
0 votes
0 answers
37 views

What are some strategies for handling multiple sources of control on a given entity?

Let's say I have a character controller on my player that is typically controlled using a script that reads human inputs and manipulates it using those inputs. But what if I also have a scene in my ...
user avatar
0 votes
1 answer
47 views

Player is able to interact with objects but enemy isn't able to

Newbie here, I have a player script that interacts with objects just fine and I made an enemy script for the same object and it gets completely ignored: Below there are 4 scripts. The ...
user avatar
0 votes
1 answer
62 views

Rotating dials with increments, one works and the others doesn't. Why?

I have 4 dials that rotate by increments when the players drag them. They all exactly have the same code, but I can't figure out why only one of the dial works as intended (dial 2). My code stops ...
user avatar
0 votes
1 answer
21 views

Apply an offset to a camera rotating around an object

I have a camera that rotates around an object to simulate the rotation of this object. To do this, I simply move my camera to the object before making my rotation and then translate it back: ...
user avatar
  • 1
1 vote
1 answer
61 views

How to implement a dial control that snaps to increments?

How can I implement snapping via code? I have this 2d circle that the players rotate via drag and it works like a rotating dial. The best way to describe what I wanted to achieve is similar to a clock ...
user avatar
0 votes
1 answer
39 views

3D CharacterController ride moving platforms in Unity?

I have a player controller script that I'm writing that uses the CharacterController component to move around and handle collisions. I've been able to implement ...
user avatar
1 vote
2 answers
56 views

How should I implement the idea behind this abstract class setup in a Unity-Friendly/Inspector-Usable way?

First up, the name of the question is terrible and I am open to suggestions. For context: I'm still relatively new to C#/Unity and it's hard to ask questions properly when I don't know the terminology....
user avatar
-2 votes
2 answers
54 views

Collision callbacks not working

I'm a beginner at coding and wanted to make a quick little program to test my googling skills so far. I'm trying to make the player GameObject be given a speed boost when it collides with the "...
user avatar
0 votes
0 answers
39 views

Datatype for procedural terrain generator

I'm making a kind of infinite runner style engine. It generates the terrain in chunks each time a milestone is reached, and stores each chunk as a custom class in a list. To minimize overhead, it only ...
user avatar
0 votes
1 answer
39 views

Unity reference randomly becomes null

This issue has stumped be for 2 days and I still can't figure it out. I have a leveling script that references and image and subscribes to a global event. ...
user avatar
  • 63
3 votes
2 answers
1k views

When should I store a reference to a component instead of searching for it?

In the code I'm doing, I usually use global and local variables, as recommended. If the variable is not going to be used in more than any method, I make it local, otherwise, I make it global. In ...
user avatar
1 vote
1 answer
91 views

Trouble adding to a dictionary using a for loop

I'm trying to create a hotbar system where you can press 1 through 0 to activate abilities placed in the hotbar slots. Instead of a giant block of if/else statements I want to make a single check that ...
user avatar
-1 votes
1 answer
44 views

How to detect objects within a radius without using a trigger collider?

I want an object to run code that detects objects around them, in a specific radius. BUT I cannot use a trigger... or any game objects or components. What could I do just using code?
user avatar
0 votes
0 answers
16 views

Trying to position all chunks for distinct LoD levels

Well, my question is pretty simple to understand, I'm trying to create a grid of chunks but on each step, I want to double the distance of a chunk. Then, this is the code I have: ...
user avatar
  • 141
2 votes
1 answer
113 views

How to design an upgradeable skill system?

In my game skills can be leveled up to modify base stats like reducing cooldown by 20% and increasing fired projectile count by one. How would I architect the system so that each skill has its own ...
user avatar
  • 63
0 votes
2 answers
64 views

Why is Vector3.ProjectOnPlane() "drifting" further from desired rotation on steep slopes

I'm writing a simple player movement script in Unity 3D, and I've been using Vector3.ProjectOnPlane() to accomplish slope/ramp movement. For the most part, this ...
user avatar
0 votes
0 answers
27 views

Unity's Collider.OverlapCollider is not consistent

I am making a 2D level editor and when I am placing a sprite over another collider it should prevent me from being able to place the item. When the collider being placed is completely over an item it'...
user avatar
0 votes
1 answer
58 views

Why does the player rotate nonstop?

...
user avatar
0 votes
0 answers
16 views

How to utilize stacking blocks under the player object(cylinder) by using rigidbodies in unity3d?

I am working on a hyper-casual game project which is very similar to Matching Cubes. Initially, I was using transform to stack blocks under my cylinder(player object). But in the game there will be a ...
user avatar
0 votes
1 answer
36 views

Why rotating backwards is too fast, even if I set the time to 3 seconds?

The rotation is very fast. It takes less than a second and for sure not 3 seconds. Maybe it's better to do it without using a coroutine? Or something in the ...
user avatar
0 votes
0 answers
51 views

How to stop the agent when target is unreachable

I want my player characters to stop when the target is unreachable. Please watch this video. As you can see in this video, the agents don't stop when the target is unreachable. This is my code: ...
user avatar
0 votes
1 answer
50 views

Unity coroutine not yielding sometimes

I'm making a 2D platformer controller and I want to implement a coyote time and buffered jump, the way I implement both is by setting a bool to true when either action is enabled like this: ...
user avatar
0 votes
1 answer
22 views

How to reference an object that was not destroyed from a previous scene in the inspector

In a game I'm working on, I have a button on the pause menu that allows me to mute and unmute the background music. The toggle button, in the inspector, references the audio manager object and calls ...
user avatar
0 votes
0 answers
27 views

Unity - How to completely disable auto refresh everywhere (in favor of manually compiling them)

Question: Is it possible for me to create a custom script that will fully disable auto refresh everywhere within Unity (not just on script changes; in my case, asset creation/deletion in addition to ...
user avatar
0 votes
1 answer
22 views

How to make the transform rotate backwards but in FixedUpdate instead in coroutine?

First time I tried this method: ...
user avatar
-2 votes
0 answers
36 views

How to rotate towards a target but only on the y axis?

I tried this and it's rotating facing to the target but also on the x and i want it to rotate only on the y : ...
user avatar
0 votes
0 answers
24 views

How can i use a class for either vector3 or transform in the same variable in a mono script?

I created this class, which is attached to an object with some colliders: ...
user avatar
0 votes
1 answer
37 views

Why is my character controller deacceleration not working?

I want my player to deaccelerate when he stop not just stop in place. Here is my code: ...
user avatar
  • 127
0 votes
0 answers
34 views

How to limit camera rotation angle

I want to rotate my camera horizontally around the object 360 degree and want to limit my vertical rotation from -45 to 45 degrees. I have found some solution over internet but none of them are work ...
user avatar
  • 7
0 votes
0 answers
21 views

CreateWithShader can only be called from the main thread

Note: I encounter a strange problem. I know that as the title suggests I have to create shader/material in main thread but the same code is working with other data without using the main thread. I ...
user avatar
0 votes
1 answer
22 views

Raycast collision not working

I've tried to do a gun mechanic for my 3d game but when I tried to write ray cast it didn't work only layer that is printed is 0 even though it shoots and gets stopped by an obstacle here's the ...
user avatar
0 votes
1 answer
71 views

How to detect if hit by raycast from object with name/tag

INTRODUCTION: In unity, I want to make a dynamic, object use system. Where the main player camera shoots a raycast when left mouse button is clicked and if an object that can be used for example a ...
user avatar
  • 169
0 votes
1 answer
13 views

Finding GameObject with Tag, excluding this object and its children

I am new to Unity. I'm trying to create a combat game. I want to access different game objects by tag through the FindGameObjectWithTag method, but I want the ...
user avatar
0 votes
0 answers
36 views

How to quickly calculate the number of tiles between buildings in a tile system

my friend and I are currently working on a city builder game like Anno/Cities Skylines but with some own ideas and tweaks. (of course, on a much smaller scale) Currently, we are struggling a bit with ...
user avatar
  • 1
0 votes
2 answers
72 views

Passing a method as a parameter of another method

I'm working on a game project in Unity with a point and click interface and I'm trying to make a method that moves the player towards a target object and invokes another method depending on what the ...
user avatar
0 votes
1 answer
33 views

Refresh resource folder during runtime

I am directly download some object file (3D Models) inside resource folder and the using Resource.Load I am loading those model in unity. This work perfectly but the problem is I have to refresh the ...
user avatar
0 votes
0 answers
22 views

I am trying to make a multiplayer game, and my 2d sprite shows up when I click play normally, but not when I press build and run?

When I press the play button at the top of the screen, I can see my sprite, but not when I press build and run. Why is this? (enter image description here
user avatar
  • 1
0 votes
1 answer
25 views

Save Resource Usage when Player is inactive

I have a windows standalone player which is running on surface laptop. As you know it works on batteries so i want to add a feature of power save/resource save when the player is inactive? Is there ...
user avatar
1 vote
1 answer
47 views

Implementing ability system with ability parameters

I am trying to implement an ability system in Unity for a game similar to XCOM (turn based, team consists multiple of units, grid based). Every unit have X action points per turn. I would like to do ...
user avatar
  • 13
0 votes
2 answers
48 views

How to load DontDestroyOnLoad object from menu scene when testing other scenes?

I have an audio manager that plays background music for a game I'm making in Unity. Since the music persists between some scenes, I've set up a means of not destroying the audio manager between all ...
user avatar
0 votes
1 answer
35 views

A point on a sphere surface needs to be converted to origin coordinate

I have a central point, a planet is moving around it on the orbit A (a circle) And the planet is rotating at a certain speed on its axis ( B ) I have a Data Structure representing the Base Mesh ...
user avatar
  • 105

1
2 3 4 5
158