C# is a multiparadigm, managed, garbage-collected, object-oriented programming language created by Microsoft in conjunction with the .NET platform.

learn more… | top users | synonyms

1
vote
1answer
116 views

C# How to add inventory to player, NPCs, and in-game objects?

I'm a beginner in C# and trying to implement a player, an item interface, and some kind of storage system (for player inventory, NPC inventory/drop list, and storage like chests), and having some ...
0
votes
1answer
43 views

(Unity) Player movement script keeps moving

My player in unity moves but doesn't stop when i let go of the key heres the code: using UnityEngine; using System.Collections; public class Player : MonoBehaviour { Vector3 movement = new ...
1
vote
0answers
44 views

Moving along the surface of a mesh?

I'm trying to replicate the movement in this game: https://www.youtube.com/watch?v=OcvD8BXars8 The players ship along with all other game elements move along the surface of a mesh. I've tried ...
1
vote
1answer
41 views

UDP server in unity not working

I know there are a lot of UDP examples out there, but I really need to know specifically what I am doing wrong. I have Wireshark monitoring my data traffic and according to that program Unity is not ...
-3
votes
1answer
40 views

How to assign GUIText from heirarchy into prefab object?

I want to assign GUIText from heirarchy into prefab using that C# code: private Text HighScoreText; void Start(){ HighScoreText = GameObject.Find("HighScore").GetComponent(); } But ...
58
votes
6answers
14k views

How do bullets work in video games?

I came across this question when I was designing a video game in C#. If we consider games such as Battlefield or Call of Duty, hundreds or even thousands of bullets are flying at the same time. ...
0
votes
1answer
59 views

Unity saving and loading of images in game

So I'm planning out this game for unity but I don't know how feasible it will be with all of the image loading and saving. I've worked with some other coding, and while I am in the process of ...
1
vote
0answers
33 views

UDP client code throwing a very nonspecific exception

so I'm writing a UDP server and client on a couple of the machines in my virtual reality environment to allow (in this case) data from the location in the environment to trigger some air nozzles. The ...
0
votes
1answer
62 views

Sudoku generation doesn't finish

Heyho, i got problems with my sudoku generator. First of all I generate some numbers between 1 and 9 and put them (according to the sudoku rules) into my game. After that I solve it using my second ...
1
vote
0answers
45 views

How to compare two skeletons by using kinect sensor? [closed]

I need to know about how to compare record skeleton with live skeleton in C#. If there are any reference please let me know. example image for what I done up to now
0
votes
1answer
39 views

Unity 5 - Occlusion culling 2D error

I'm trying to set a Occlusion culling on my topdown 2D game. I have made a sprite object with a Occlusion Area on it.Once I try to bake it, it gives me the following error: No Renderers that are ...
0
votes
2answers
87 views

Need some advice on how to decide where to implement my enemy behaviours

I'm in the middle of writing a platformer game in Unity using C#. I have my character, if he presses the kick button his state switches to kicking. During this "kicking" state the character doesn't ...
1
vote
2answers
57 views

How to slow down this rotation

My goal here is simple. I am making a top down shooter kind of game, and I want the player to simply rotate in one axis, towards where the mouse is on the screen. I got it working, but it rotates so ...
1
vote
1answer
50 views

Correctly creating/handling events for keypress in MonoGame C#

I'm having trouble finding the best approach to registering an instantaneous user key-press with MonoGame (where the key has been held down and then released), using events in C#. Unlike the click of ...
1
vote
1answer
76 views

Tire mesh rotates faster than wheelcollider in Unity

I have a car in Unity. Scripts are C#. I have noticed that my tire meshes' rotation is faster than whellcollider rotation. I am using this code for wheel rotation flWheel.localEulerAngles = new ...
-1
votes
2answers
50 views

AddComponent with string in unity5

At runtime I want to copy one Gameobject component to another gameobject. In my case I have one camera where multiple scripts are added with values settings. the same components i want to add into my ...
0
votes
0answers
30 views

Scaling window with Monogame.extended issue

I'm trying to scale the game window in Monogame (I also have installed Monogame.Extended). (Example of what I want to achieve) I've been doing this setting manually the PreferredBackBuffer when ...
3
votes
1answer
133 views

Are there spritebatch drawing limitations on monogame?

I've reached a point that it seems when I draw too much on screen, monogame starts doing weird things. When I call this code in the Draw method public void drawDialogBox() { if (...
1
vote
1answer
51 views

How to follow a car with correct rotation

I am making a game where car will follow a user car. I am moving use car using keyboard keys it is working fine running on my game environment roads smoothly. To follow enemy car i am using nevMesh, ...
4
votes
2answers
80 views

Changing some color of a texture using C# in Unity

It's almost 2 days that I'm looking for a way to do this in Unity using C#, but still no luck. Imagine you have a texture with different colours (this texture can be a rug), and you just want to ...
3
votes
1answer
60 views

Respawn not working properly upon scene reload. Why is this?

So I made a respawn function and what is supposed to happen is the script it supposed to load a saved checkpoint. However I need to reset the scene (and again this worked just fine last night which ...
1
vote
4answers
70 views

How to find nearest gameobject on one side

Here is an example: The left enemy robot is closer than the right enemy robot, but I want the character to attack the robot that is closest to him on his right side. I can't use Physic.SphereCast ...
0
votes
0answers
41 views

Unity C# - The object of type 'Object' has been destroyed but you are still trying to access it

I have a cube on a plane and I'm tring to move it to certain locations. I've baked the area and added a navmeshagent to the cube. My moving script for the cube looks like this: using UnityEngine; ...
1
vote
1answer
277 views

Calculate the displacement of device in unity

I'm making a 3D game in unity where the object should move forward and backward as the android device moves/accelerates in the Z axes. ie. When the player moves the devise in the direction of the +ve ...
1
vote
1answer
45 views

Can't access properties of a class

Sorry for the bad title, but I couldn't think of a way to word my problem for a title. So I have this script, with two classes: using UnityEngine; using System.Collections; public class GameItem { ...
1
vote
1answer
40 views

Should I slow down my animation with co-routines or update the animation state?

I want to gradually stop the car animation as it collides with another car gradually speed up the car animation as it exits the collider I have two ways to achieve this. Update Co-routine For ...
0
votes
1answer
62 views

Is drawing an entire game to a render target and then scaling it up a viable solution to a pixel-mismatching problem?

To clear up some possible confusion caused by my title, my game is meant to be pixelly. I currently achieve this by multiplying sprite sizes and locations by a constant called World.Scale (currently 8)...
0
votes
2answers
94 views

How do I make a game over screen like Temple Run or Subway Surfer?

When you die in one of these 2 games I took screenshots of (Temple Run and Subway Surfers), what exactly comes up to say "Game Over" and posts your score and all-time high score? Is it a different ...
0
votes
0answers
47 views

How to make Level Editor in C# for a DirectX engine in C++ [duplicate]

I have been trying for months to make a Level Editor for my C++ DirectX Engine. I have tried using a C++/CLI wrapper or P/Invoke to do this. Neither seems to work. Can someone let me see a sample of ...
1
vote
0answers
28 views

Unable to control trigger events for car animation collsion control

I have different car animation running on the road which have imported from max. I want to make such an intelligent System that if car start to trigger from another car it become stop. So far I have ...
3
votes
1answer
82 views

Dragging text element into Text variable unity 4.6

So I was trying to make a UI element to keep score in a unity (4.6) project and I'm having trouble assigning the 'Text' element to the Text variable. So I have the text element with the script ...
1
vote
0answers
62 views

Export UnityProject inside Android Studio's existing project

I am new to the Unity3D, but I have made a small Unity project with a humanoid gameobject. I can move this humanoid with the demo data but I want to move it with the quaternion data which I am already ...
1
vote
1answer
30 views

How to Ignore Raycast for Boxcollider2D by layer or boolean?

how can I ignore Raycasting for specific object,perhaps you say use Queries Hit Trigger but when I use it Ignore all Raycasting for triggers but I want filter Ignore Raycasting for some objects I need ...
1
vote
2answers
84 views

Using my pathfinding more efficiently

I'm making a roguelike in C# with the Roguesharp libraries, in which the map can be as large as 200x200 cells. When I have an entity requiring pathfinding, I am using Roguesharp's built in pathfinding ...
3
votes
2answers
189 views

Traffic system in isometric game

I would like to create a traffic system in my tile-based isometric game and I would like to ask for some good approaches because I don't have a clue how to begin. Right now I have a tilemap and keep ...
2
votes
2answers
82 views

object smooth orbital limit around another object depending on mouse drag

I am working in Unity. I have special objects that can each be dragged freely around in 2d. The objects cannot get too close to other objects (minimal Vector3.distance allowed is 1.5f). I also have ...
-3
votes
2answers
85 views

How do I write to a text file in Update function of a script? [Unity|C#]

I have a Unity C# Script which updates a variable each time the Update function is called. I would like to know how to write to a file from the update function.
1
vote
1answer
237 views

How do I render my DirectX C++ engine to a C# Panel?

The title pretty much sums it up. I'd like to know how I can get the HWND of my C# Panel object to my DirectX engine so I can render to it. I know it involves making a C++/CLI wrapper, but I'm not ...
-4
votes
2answers
75 views

How can I test which of two gameobjects is closest to a third gameobject?

It would be nice if it was as simple as: public void Closest() { if (A.distance > B.distance) {} } But any sort of workaround would be acceptable.
3
votes
1answer
157 views

Trying to implement forward rendering in OpenGL

I'm working on implementing forward rendering in my 2D engine, as far as I'm aware everything should be set up correctly, I've ran into some issues earlier but I'm sure I've fixed those at this point. ...
1
vote
0answers
29 views

Weapon Sway Script messes up weapon rotation

So I'm in the process of learning Unity 5 and scripting in it. One thing I wanted to give a try was to make a simple weapon sway script like you see in games such as battlefield or csgo. After a bit ...
1
vote
1answer
51 views

How to switch between sprites in Unity

So I made an empty game object in inspector, called it "squareTest", and I clicked and dragged 3 sprites in. One is the square being black, one is the square being red, and one is the square being ...
1
vote
0answers
49 views

Unity - SerializedObject.ApplyModifiedProperties() using relavant property setting method

The problem I have is this. I have an editor script, at the end of OnInspectorGUI() I want to apply all the changes with the serialized object. The simplest way to show my problem is thus: [...
0
votes
3answers
78 views

How do I make my Unity application quit programmatically?

I made a script and I want to make my game quit, but this does not work. How should I go to make the app quit? using UnityEngine; using System.Collections; using UnityEngine.SceneManagement; public ...
0
votes
0answers
26 views

Lense distortion correction with unity5

I am working on lens distortion correction in Unity. I created a new scene dragged the "Cardboard" prefab to the scene. In the cardboard setting I have set the Distortion correction as "Non". and I ...
0
votes
1answer
65 views

How to use NoSQL REST API of Gamesparks in my Unity project? [closed]

Gamesparks has a documentation of the API but I am not sure how to send https requests to use that API.
-1
votes
4answers
130 views

How can I exclude a range of values when generating random numbers?

If you are using Random.range to generate values, is there any way to exclude some values within the range (for example: pick a number between 1 and 20, but not 6 through 8)?
2
votes
2answers
29 views

Modify the Y position of a GameObject on startup

I'm trying to modify the Y position of a GameObject on startup with the script below: int y; void Awake() { y = Random.Range (140, 155); Vector3 temp1 = transform.position; ...
0
votes
1answer
20 views

Playing an animation all the way through with one quick keypress with Mechanim Unity

I have an if statement inside of the Update function that is only called if three other conditions are met. The problem is that right now the function sets a boolean to true which causes the animation ...
0
votes
0answers
51 views

C# Moving object from point to point and back

I was trying to make an algorithm that makes an object move from a point to another point and back (in C#), but I can't make it work. Does anyone know a correct way of doing it? The code I used is ...