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 ...
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 ...
0 votes
2 answers
2k views

How to set a variable from the selected text of a dropdown menu in Unity?

I am trying to set a variable from the value of a DropDown menu in Unity. I wrote a script as follows, attached it to the dropdown and set it to run it in Unity under: On Value Changed (Int32). I have ...
0 votes
1 answer
86 views

Control does not work if motion is set in FixedUpdate

I made touch controls, but when I set forward movement, the control stops working. ...
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.
2 votes
2 answers
4k views

Vibration duration for mobile devices in Unity

I'm used the Handheld.Vibrate() method. I know that if you call it several times, you can increase the vibration time, but when it is called once, the vibration ...
0 votes
3 answers
154 views

Can I replace the source image of slices by script?

I have a Unity2D prefab that uses several slices from a single PNG. (in it sprite renderer, and in its animation clips). If I replace that PNG in the Finder, all slices taken from that PNG are ...
1 vote
1 answer
92 views

Throttling or adding delays between OnTriggerEnter2D calls

I have 2 game objects: Explosion and Enemy. At any given point, an enemy can collide with multiple ...
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 ...
1 vote
1 answer
251 views

Testing Message-Based Events using Unity's New Input System and InputTestFixture, getting unhelpful error

My player has an Action in the Input System Move, that takes a Vector2 and moves the player based on that input. Straight-...
0 votes
1 answer
421 views

How can I use offset to make the camera rotate around the player, but keep the distance from player?

The script is attached to the Main Camera. At the top : ...
0 votes
3 answers
6k views

Gyroscope Parallax Effect In Unity

I want to make a parallax effect in Unity 3D with gyroscope like the one on this site: http://matthew.wagerfield.com/parallax/ I found an asset, but it is too expensive. So I need a script which I ...
0 votes
1 answer
51 views

Simulating Road Traffic/Overtaking - Overtake works mostly, but starts clipping other vehicle

I am trying to improve on my Car class, which is used to make a small road scene with 3 lanes each direction with the ability to overtake by changing lanes. I had a very basic version working with all ...
2 votes
1 answer
1k views

ScriptableObjects events execution order?

Given the code: ...
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 ...
3 votes
1 answer
1k views

Character creation using spritesheets

I am currently creating a 2D fighting game and have implemented a system where upon starting a new game, the player is presented with the option to create a custom character. I have a set of string ...
0 votes
0 answers
44 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 ...
0 votes
0 answers
403 views

How to Create a Blast of Liquid in Unity

I am making a small cartoon-ish fighting game, and one of the weapons is a Hot Coffee Sprayer, which is a shotgun style weapon. How do I create a thick blast of dark liquid to come from it, with a ...
1 vote
1 answer
3k views

Unity C# Input Buffering

So, I've got a fighting game with some pretty tight input windows, and I'd like to buffer the inputs for a few frames. Basically, if the fighter is in the neutral state, pressing attack should lead ...
4 votes
1 answer
3k views

How to implement a professional fighting game input buffer?

Ok guys, I understand how to make a basic input buffer. Here is my code: ...
0 votes
1 answer
173 views

Refactoring fighting game Movement class responsibilities

I'm a web developer, new to C# and trying to learn Unity. I've learned the C# syntax, I understand how to write working code, although I'm having a hard time understanding when and to what classes ...
7 votes
2 answers
9k views

Fighting Game and input buffering

In fighting game, there is an important thing called input buffering. When your character is doing an action, you can input the next action that will activate as soon as possible (the buffer is 5-10 ...
0 votes
2 answers
192 views

Turning around an enemy when hitting a wall or after x time

I have an enemy that is supposed to go in one direction and after hitting the wall or if a certain amount of time passes, it should turn around and go back. After hitting another wall, it should turn ...
0 votes
1 answer
111 views

How can I play a audio clip only when the volume slider value changed?

...
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 ...
0 votes
2 answers
67 views

How can I wait for the coroutine to over before starting again using a flag?

...
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 ...
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 ...
0 votes
2 answers
49 views

How to move an object when a specific event occurs?

...
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 ...
0 votes
3 answers
1k views

Jittery collisions in Unity 2D

I tried to implement a simple movement to my object. My object moves perfectly fine but I'm having issues with its collision. When I keep on moving object towards the obstacle/ground, collision are ...
1 vote
2 answers
85 views

Get vertices of a terrain mesh affected by a brush or placement shape

I have the following mesh, it has very simple structure. You can think of it as a terrain from top-down view: each vertex (red and numbered) is a fixed distance away from its four neighbours in the ...
0 votes
1 answer
50 views

Angle object only in the X axis

I'm trying to code a turret to angle towards a target, where I have one part of the turret only rotating on the left/right, and I want to animate another part to only angle up/down. I've got the left/...
0 votes
2 answers
189 views

Custom FPS Controller in Unity 5.6.6f2 not letting me look up or down

Due to the FPS Controller seeming to be broken in Unity now, I started using a custom one by kinifi on GitHub. For some reason though I can't look up or down. I removed the Main Camera so it should of ...
0 votes
1 answer
42 views

BoxCollider2D used as reference to Collide with GameObjects but it uses the original size Sprites size to Collide

I'm a beginner in Unity and pretty much copy and pasted the code but I can't figure out why the game is using the size of the sprite and not my BoxCollider2D as a ...
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 ...
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 ...
0 votes
1 answer
52 views

Change the min width/height of a LayoutElement to scale with the screen size

I want to change the Min Width and Min Height configured in my LayoutElement so that they scale proportionate to the screen size. For example, at a screen resolution of 1920x1080, the min width is 300....
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....
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 ...
0 votes
1 answer
63 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 ...
71 votes
10 answers
203k views

In Unity, how do I correctly implement the singleton pattern?

I have seen several videos and tutorials for creating singleton objects in Unity, mainly for a GameManager, that appear to use different approaches to instantiating ...
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 ...
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 ...
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: ...
2 votes
1 answer
4k views

Change color, or material of specific line segments on Line Renderer

We're making a game that plays with a LineRenderer, and we want to give it a different visual feedback relative to the side of the screen that it's on. We want to change the feedback of the specific ...
0 votes
1 answer
130 views

How Do I Separate Dragging My Finger On Joystick And Swiping?

I am currently making a 2D top-down view shooter game for Android, where the game is played horizontally. On the left side of the screen, you can touch anywhere to spawn in a joystick and aim by ...
-1 votes
1 answer
62 views

How can I spin a child capsule of a cube parent?

I have a parent cube and to make it like a surface I had to change the rotation of the cube on the X to 90. and as a child, I added a capsule, and to make the capsule-like standing I had to change the ...
-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 "...
0 votes
1 answer
912 views

Rotating character for 2.5D platformer in Unity

I'm currently making a prototype for a college project in Unity. The game is a 2.5D platformer, though I've incorporated a script for the camera from a 2D platformer so the camera moves ahead of the ...

1
2 3 4 5
158