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
0answers
32 views

Can you somehow do WAN for Mirror in Unity without port forwarding?

Basically i'm using Mirror and it works perfectly when I and my brother wants to play the game I made, but we're on the same network. When my other brother who doesn't live at home can't connect ...
0
votes
2answers
43 views

Unity 2D Script affects all current objects in a Scene

I looked around for a fix because I am sure it's either super simple of a fix or something that is commonly run across but nonetheless it's about time I asked straight up. This is my code in the ...
0
votes
0answers
30 views

Playing Video Files in Windows Forms with MediaPlayer

With the following encoding, only the audio part of the video is played, but the video itself is not shown: ...
-1
votes
1answer
26 views

Setting joint angle from a slider makes joint spin continuously [closed]

I use sliders to change the rotation angle of my joint, like this: ...
0
votes
0answers
44 views

How to make a 3 hit combo in Unity

I had used a tutorial to set up the attack, but is was only for one attack. I tried to modify it for a combo, but it plays all the animations at once. How can I change this to work as a 3-hit combo? <...
0
votes
0answers
48 views

Slot machine labels get closer together after each spin

I have made a slot machine game. The problem is that after resetting each spin, the spinning value labels get closer together until they overlap. It seems that the problem appears the moment they stop ...
0
votes
1answer
22 views

how do place UI in code at bottom screen?

I am struggling to figure out how I can add a UI prefab on screen in code so that it appears "anchored" at the bottom center of the screen. I realize this might be a common question. I ...
0
votes
0answers
12 views

1. How to keep stopwatch counting after change to the next scene in Unity? I attached my code below [duplicate]

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class stopwatch : MonoBehaviour { Text text; float theTime; public float speed = 1; bool ...
0
votes
2answers
61 views

Triggers VS coroutine performance?

So I am using unity and wondering if I have an agent going to move to a position say Agent A moves to position B in x seconds guaranteed (avoids all physics or things that could disrupt the path). ...
1
vote
1answer
24 views

Discrepancy between ArticulationBody indexing and drive target list

My player is at the moment an ArticulationBody setup that looks like the lower half of a person: a waist, two thighs, and two shins. I'm currently just implementing moving the thighs, and my code ...
1
vote
1answer
61 views

Puzzle logic management

This is my first ever question here; I'm pretty stuck on a certain feature I'm working on in order to learn. I'm working in Unity 3D. I'm trying to make a set of buttons that work in unison to unlock ...
0
votes
0answers
26 views

Drag & drop: Cannot return object to its original position using Unity 3D?

I am working on a game where the user can take an object and drag it at the destination location provided or indicated. If he/she doesn't drag it to the target location and drop the object, it must ...
1
vote
2answers
71 views

Disable input and score count in pause menu?

I need some sort of an if statement, which allows me to disable any input and increment score while I'm in the pause menu. The problem is that I don't really understand this kind of pausing code, I'm &...
-1
votes
1answer
38 views

Each time a new platform spawns, rotate it 90 degrees from the previous

All I want is when the platform changes its position on the x or the z axis, then rotate the whole platform by 90 degrees. When I try to do this with the following code, I don't see any change - the ...
1
vote
1answer
46 views

Unity: Editor only monobehaviour (not gameobject!)

I'm well aware of the EditorOnly tag on gameObjects. However, my question is slightly different: I have a large number of gameobjects in my scene that only mark a spot, i.e. I only care about their ...
0
votes
0answers
45 views

character movment and physics on 2d game

I'm developing a client/server multiplayer game. in server side i need prevent players cross map objects like walls also i need prevent player go inside each others, instead want to slide them along ...
0
votes
1answer
76 views

Best practice for getting references to gameobjects unity

When structuring the script to control a gameobject with several generations of children underneath, I gather from one of Jason Weimann's videos that it's a bad idea to use the string based methods to ...
2
votes
2answers
84 views

How to program different types of monsters

I'm working with a group of programmers and I'm trying to program different types of monsters in Unity. I want to make it so that all the monsters have values like attack power, attack speed, moving ...
0
votes
0answers
18 views

How to select one game object and move it?

For example, I have two game objects, cube1 and cube2, in a scene. I want to be able to click on one and move it. I know how to use ray to highlight it, like below: ...
0
votes
1answer
67 views

I'm still not sure why the reverse state is not working?

The goal is to be able to change direction(reverse or forward) at runtime in real time without waiting the transform to reach the next waypoint first but at real time to change the direction/s. ...
4
votes
2answers
137 views

How to not cover up the Android/iOS top status bar (eg. with time, network/wifi icons) in mobile Unity app?

I am making an Android/iOS mobile app in Unity. Currently, when I build it and install it (for example from APK to Android) it loads completely full screen covering up the top phone status bar which ...
0
votes
0answers
34 views

Avoid clipping objects when looking at them close-up in the Scene view

I am making a game in Unity3D, but whenever I get about 5 meters close to an object, the camera acts like I am right by it and does not render part of the screen. Here is a screenshot: This is really ...
-1
votes
1answer
27 views

Why I'm getting message in the editor console window , Look rotation viewing vector is zero?

Look rotation viewing vector is zero UnityEngine.Quaternion:LookRotation (UnityEngine.Vector3) Waypoints:Update () Why I'm getting this message and what should I do with it ? It's not a warning and ...
1
vote
1answer
95 views

How can I draw gizmos only at runtime?

...
0
votes
1answer
38 views

How do I create a method that adds a new sprite to the game?

I want to have a script in my game that adds a card. I am using a Card class for all my cards, so I don't have to make a prefab for each card. Instead I can do ...
0
votes
0answers
34 views

How to snap an object to an axis in 3D?

I have a script that lets player move a Rigidbody in my game with a mouse, and I want some objects to snap to other objects' axis (let's say guide) when they are near. So when an object is close to ...
-1
votes
1answer
28 views

How to rotate my enemy so it scans the area?

Hi I am new to unity so I am not super familiar with methods. I am trying to make my enemy rotate left then right double the amount that it rotated and back to the middle like this: +10 degree, -20 ...
3
votes
1answer
931 views

Why is there only one variable displayed in the Inspector?

Using the following code, only one variable is shown in the inspector: [SerializeField] private GameObject _obj; This makes sense, since there is only one field. ...
-1
votes
1answer
32 views

Why does a public variable define a private one? [closed]

What is the point of such work with variables? public GameObject Obj => _obj; [SerializeField] private GameObject _obj; A private variable loses its privacy ...
0
votes
0answers
25 views

How to save a class full custom property types and their data to disk

Background: My app is a sandbox with a large number of parameters that I want to be able to easily add / selectively expose to the user, edit during runtime through the game UI or from the Unity ...
0
votes
2answers
41 views

How to make windows that pick up what appears in the other

Basically there are 2 windows that you can drag and drop around the screen. Whatever appears in one window will also appear in the other. The two windows cannot go one over the other. This is a demo ...
0
votes
0answers
12 views

Data not saving across scenes [duplicate]

I've been trying to save a player's score with PlayerPrefs, however every time i change scenes, the game simply stops tracking the score and doesn't even add score when told to, anyone has any idea of ...
0
votes
2answers
50 views

Loop over a list with within X seconds

I have a list of harvested crops. There's a capacity of let's say 100 crops(100 items in a list). Now I want to empty the list within X seconds when max full (2 sec in my case). This should be ...
0
votes
1answer
32 views

How can I create a custom plane with raycast?

...
0
votes
0answers
19 views

Rotate object from its current rotation value

I am rotating my gameObject with the rotation of another gameObject - "hand" in its z-axis. The rotation of the object jumps to the current rotation of the hand and then it starts to rotate ...
0
votes
0answers
30 views

How do i prevent the next player from being called?

I got help from someone on making a turn-based button but so far I am not able to prevent the button from getting the next player when a certain bool is activated in the room. Initially, the ...
2
votes
1answer
42 views

How to generate a correct RGB + Luminance histogram?

I am trying to create a debug tool that would help me visualize an image RGB and luminance histogram. I have created a compute shader where I gather the histogram data ...
0
votes
0answers
35 views

What's a good architecture for a simulation?

I have a concept that involves a world being simulated. Lots of entities and processes acting upon them, not to mention interactions, etc... Every SimulationTick, ...
0
votes
1answer
41 views

How Can I Order The Scores List By Newest Added? Unity C#

I have 5 scripts to make the scoreboard. But I don't know how to order the list (the scores which are stores in a list) by newest added. Can someone please help me? Thanks :) First Script: ...
0
votes
0answers
20 views

How to manage movement on a topdown shooter

I'm attempting to code a top down shooter in c#, I've worked out how to get my character to look at the mouse, and got it to be able to move in all 4 directions, but how do i make it go forwards ...
0
votes
0answers
39 views

Why the layer mask when using raycast is not working as supposed to?

The script is attached to the object with the lights. ...
0
votes
1answer
50 views

Why is OnTriggerEnter not called when my objects do not have Rigidbodies?

I am trying to get my enemy to take damage, however it is not working. I know the reason: the box colliders on not triggering the OnTriggerEnter message. I do not ...
0
votes
0answers
48 views

How do I write a script for Unity that allows a gameobject to be scaled using pinch & zoom touch controls?

I need a script for Unity that allows a gameobject to be scaled using pinch & zoom touch controls. I have found lots of answers for scripts that cause the camera to zoom in/out but I want a ...
1
vote
0answers
34 views

How can I turn on/off lights automatic depending on the surrounding lights areas?

When the player enter this dark area I want the lights to turn on automatic and if the player is getting out this area to the desert area in the screenshot the light should be turn off automatic. This ...
0
votes
1answer
45 views

Wait for time Unity C# when called to

I am currently programming a custom programming language and using Unity to run it. My current issue is that while loops freeze the game when their done. Is there a simple way to wait until end of ...
0
votes
0answers
28 views

How can I make the lights to start turning off faster?

The problem is not the duration it take to turn off the light but when the whole turning off action start. The first script is what make the lights turn off/on : ...
2
votes
1answer
80 views

Infinite Stairs Design

In Unity, I'm trying to create a puzzle in a 2D platformer game where the player has to face some infinite stairs. The player can move left, right and jump. The idea is that at some point the player ...
0
votes
1answer
22 views

What is Animator.Update(float deltaTime) doing?

It looks like it does the same thing as Time.timeScale, only for the Animator. But it works somehow specifically. You need to call each frame for it to work + you ...
0
votes
1answer
57 views

How to handle octave & frequency in the Perlin noise algorithm?

I would like to implement a Perlin noise algorithm into my MonoGame project in order to procedurally generate 2D terrain. I've been using engines in the past (Godot, mostly) where there was an API to ...