Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [c#]

C# is a multi-paradigm, managed, strongly typed, garbage-collected, programming language created by Microsoft in conjunction with the .NET platform.

0
votes
1answer
68 views

Should I use dependency injection in Unity? [closed]

As learned about dependency injection on the internet, I found that it's something that can be done simply by the Singleton Pattern. But there are 2 completely different views on this issue: Some ...
0
votes
0answers
17 views

Error modify bools from script1 iin script2 then get bools value frrom script2! [duplicate]

I have a GameObject called "emptyobject" with a FullOrFree component attached, containing several public boolean variables: ...
0
votes
1answer
182 views

How to start a game with “3-2-1 go”?

I want my game to start after a "3-2-1 go" countdown. My Player Script : ...
0
votes
1answer
67 views

Server-side real time position calculation based on destination position - C#

What I want to achieve is to calculate the real object position based on its speed and a destination position. In my server, I have a MapInstance that have a list ...
1
vote
1answer
21 views

Inflating a balloon while the user touches & holds the screen

I'm trying to create a simple balloon which will enlarge as the user touches and holds the screen. So I wrote something like this: ...
0
votes
1answer
27 views

Access a clone of an instantiated object - not all the clones?

I am trying to access the object I instantiate - basically a prefab car instantiates cars (one after one) ..the problem that when try to move one .. they all move together ... what's the best way to ...
1
vote
1answer
45 views

In Unity C#, how can I change weapon a few frames later?

I have this Input code to change weapon: ...
0
votes
1answer
25 views

Sprite won't change with direction

I am making a top down Pacman game. I have two sprites: one for facing up and one for facing left. When I press W, the sprite showing is still the one for when Pacman is moving left, but I want to ...
0
votes
1answer
47 views

If statements seem to act as though the condition is always true

I have other scripts in the same project using boolean if statements that work fine, but I've tried multiple methods of testing if the if statements below are working and none of them worked! I don't ...
0
votes
1answer
23 views

XNA 4.0 How to change GraphicsDevice Default DepthStencilState Value

I want to change one of the deafult values of my GraphicsDevice to that: GraphicsDevice.DepthStencilState.DepthBufferEnable = true; But I know only to change it ...
0
votes
1answer
37 views

How can I use the colours of a swatch in a script?

In Unity's editor I have set a swatch with some colours that are used throughout our game: This swatch is saved in a file in the project's Assets folder: ...
0
votes
1answer
35 views

Unity - Calculating a rotation based on game time

I have a simple script to make an object spin: Spin Speed is the speed to rotate the object on each axis (preferably in degrees per second). Local is whether the rotation should be done based on ...
0
votes
2answers
40 views

Unity - Instantiate GameObject from client on Network

I am building a game where a weapon shoots prefab bullets. I am trying to make this a multiplayer game, so the bullets need to be spawned into the Network. What ...
0
votes
0answers
19 views

nullreferenceexception : object reference not set to an instance of an object [duplicate]

How to solve this nullreferenceexpttion ...
0
votes
1answer
43 views

checking if an array rank is not equal to an int C#

I'm creating an inventory system for a dungeon crawler, I've got world gen, and player controls down, and this is the only snag.` ...
0
votes
2answers
58 views

Why does using .Lookat() cause the enemy to look left instead of at player, and how can I fix it?

I am new to Unity. I have searched but I couldn't find any answers on this. Here is my code: ...
0
votes
1answer
28 views

Second input not working when using 2 virtual joysticks

We are trying to make 2 virtual joysticks for both sides of the screen. Movement joystick can be enabled at any pressed position of the left side of the screen and shooting joystick can be enabled on ...
0
votes
0answers
46 views

Unity: AddForce problem

I have two spheres on a plane. I'm applying AddForce to the first ball after which it collides with the second one. The weird thing is that the impulse is not passing from the first ball to the second ...
1
vote
1answer
134 views

2D snake game ( how to rotate snake's head with movement ?)

I want to know: how to rotate snake's head with movement how to make tail prefabs (body) follows head direction. ...
0
votes
1answer
104 views

Creating multiple levels in Unity without duplicating scripts

I'm trying to create a falling word typing game like z-type. I have used the code provided here I want to create multiple levels in the game, and it seems like I need to make some changes in the ...
0
votes
1answer
24 views

NullReferenceException when using GetComponent

I have a script that is attached to all the NPCs in my game. Here's what the variable declarations and Awake() function look like: ...
0
votes
1answer
23 views

Resetting The object scale to it's original size!

I have this sprite renderer in unity. I have made so that it increases it's scale. The Object is: This object is a child of empty gameObject and I have resized the parent gameObject rather than this ...
1
vote
1answer
97 views

OnMouseEnter() function stops working when I set the canvas render mode to: Camera Overlay

Basically the title says it all. I have a OnMouseEnter() function that works fine when I have the canvas render mode on Worldspace but stops working when I change it to Camera Overlay. Before, it ...
0
votes
1answer
33 views

Preventing the final segment in a linerenderer from being stiff?

I am creating a fishing pole, and have the script that draws the line -mostly- worked out using verlet physics. However, the final segment is stiff. The code follows an old Unity3D Subreddit post. ...
0
votes
1answer
33 views

Unity Word Matchmaking Validation C#

Hi everyone I am new in game development, in my first development I am trying to validate if the the words if they are match with the input, unfortunately the only word it finds correct is the last ...
0
votes
0answers
22 views

Rendering fibres in Unity

I would like to make this is Unity. How to to setup the script so that Unity could render such with gradient color/material as fibres? https://portsmouth.github.io/fibre/ ...
0
votes
1answer
35 views

unity input controls

so im going through the roll a ball tutorial for unity and ive gotten though setting up all the controls to allow my ball character to move around the space ive built. but the tutorial says nothing ...
0
votes
0answers
20 views

How to fix 3D AABB Collision not working on corners?

I'm currently working on a minecraft clone and right now trying to implement player to terrain collision. My approach is to get the blocks which the player might collide with through the collision box ...
3
votes
1answer
43 views

Calculate angle between player and end point

I have such question: how to calculate angle between player and end point? Things, which i have: Player. I have X, Y, Z position of player and his Z-angle (0-360) Endpoint. I have only X, Y, Z ...
0
votes
1answer
29 views

Unity | Camera - Follow target with view port point's offset from center

Some additional remarks before I address the issue: How Viewports work in Unity: Whatever the dimensions of the screen's rect, the viewports coordinates are mapped in normalized coordinates, where 0 ...
0
votes
1answer
20 views

Unity Inspector | Displaying min and max variables on a single line

In a C# Unity script, how can I add fields that will be displayed in the Unity Inspector with min and max values on a single line? (like it is done for the Particle System, where you can choose ...
0
votes
0answers
53 views

Multiplayer Client Side Prediction and Extra/InterPolation

I'm developing a game like Slither.io but I have planned to add weapons and another additional stuff, I implemented the Gabriel Gambetta example which runs perfectly only if the character is updated (...
0
votes
1answer
79 views

Shooting the closest enemy that you can see

I'm trying to make my main character aim at the closest enemy that he can see. My issue is with the close range criterion taking priority. If the enemy is near the player but the player can't see him,...
0
votes
1answer
57 views

How to scale an object in one direction without moving the opposite edge?

I am using Unity. In my game, I have an SpriteRenderer and I'd like it to increase its size I'd like it to lengthen to the right, without moving the left edge. I tried changing its scale to ...
0
votes
0answers
13 views

Pathfinding/Steering with limited rotation [duplicate]

I am looking for an algorithm to guide some ships in a turn based game. The trouble is they should have a limited rate of turn, and I want them to navigate them to both a target position and a target ...
0
votes
1answer
55 views

Name doesn't exist in current context in Unity

I'm currently making a collectible heart in unity, the kind that updates your health bar when you collide with it, and I made two scripts: This one is called 'healthmonitor': ...
0
votes
0answers
19 views

Unity C# reference source code within VS Code

Is there a way to inspect Unity C# reference source for a particular Unity class/method within the IDE (vscode) itself, rather than having to search thorough source files in GitHub. In VS Code I ...
0
votes
0answers
36 views

Inaccurate rotation of Aiming Dots that are supposed to represent trajectory of launch object

I am trying to create aiming dots that will help assist the player in launching the object is the desired direction. The Aiming dots are the white dots beside the character that are supposed to rotate ...
0
votes
1answer
25 views

What's a good way of implementing traits/promotions/buffs? [duplicate]

I basically need something that modifies existing code without the need to go back and change it. So for instance, if I have a game where the player or NPS can eat food to gain health back, and eating ...
0
votes
0answers
23 views

Same button doing a different action depending on what the player is colliding with

I am working on 2D infinite runner game for mobile devices. The game uses 4 buttons that carry different colors, and basically you have to match the colors of the challenges. Example Currently I ...
1
vote
0answers
52 views

Where is Advertisement.Banner class in Unity Advertisement v2.3.1 package?

I'm implementing Unity Ads in my game, now i'm using Advertisement package v2.3.1 from package manager. I set up rewarded and video ad, but can't do anything with Banner ads. I set up id in a project ...
0
votes
1answer
19 views

Disabling, overriding or hooking a VS warning to Unity's Vector's ToString()?

I've just spent 2 hours debugging a misbehaviour because ToString() truncates to 1 digit by default. I want to disable the parameterless version so I won't use it by accident and I will always have ...
0
votes
1answer
21 views

2D platformer course - Infinite waves with stronger enemies

I am currently following a tutorial on how to make a 2D platformer in Unity (https://www.youtube.com/watch?v=OEaU_mcYsRM&list=PLPV2KyIb3jR42oVBU6K2DIL6Y22Ry9J1c&index=36). The tutorial ...
0
votes
0answers
26 views

Unity how to access animation states (from blender) with C# ONLY

I KNOW this is possible, so: I have (several) models with animation "actions" made in blender, and when exported as FBX I can read them in unity with the animation controller component and all etc.. ...
1
vote
1answer
51 views

Jerky Character movement after adding mouse orbit script

I added a custom mouse orbit script to my project. When the right mouse button is clicked, the camera can be rotated around the player. The issue, after this change, is my player movement has become ...
0
votes
0answers
18 views

Unity static meshes and performance?

Ok, I need help understanding this as Im experiencing severe fps drops with different variations of applying materials to meshes. What is the advance of making a mesh static, regarding how it affects ...
0
votes
0answers
30 views

When I build from unity to Xcode a calculation doesn't happen properly

I am building an app which calculates the elevation and azimuth of 2 points using latitude, longitude and elevation. I have built it and run it on Xcode and the azimuth is locked on either 270º or 90º....
0
votes
1answer
60 views

Sequencing / triggering messages based on conditions in an adventure game

I've been struggling conceptualizing the best way to make a level flow with dialog and help hints changing as you play etc. Imagine your goal is to make this one screen 'adventure' game, where you ...
0
votes
0answers
266 views

How to sort cards' on-screen positions by their suit?

I have a 13 cards and sort button. When I click that button, I want all the cards of each suit to be grouped-together on screen. So if I have 4 diamond cards in my 13-card hand, all 4 diamonds must ...
-1
votes
1answer
54 views

Interstitial Ads Not Showing in 1st Scene

I want to show interstitial ads in my game's 1st scene. Whenever game is opened, ads should show inside it. When I use the Play Button ads work ok, but it's showing on the next scene. ...