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

-3
votes
2answers
68 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.
-5
votes
2answers
72 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.
0
votes
1answer
100 views

2d Player animation issue in UNITY 3D

I have a player and i want to move the player from left to right. I can move the player by the keyboard events.but the problem is that when i release the key the player animation should be idle. ...
2
votes
1answer
286 views

Modularization in a project

I'm writing a C# game in Mono, and I want the game to be as modular as possible. I've started by writing the whole Item (inventory) System of the game in a seperate .dll library But I've hit a problem....
0
votes
1answer
39 views

Creating 3D gravity in zero-G tied to mass in unity with c#

As a total beginner, I've been working on a patch-job script for a gravity mechanic in an open space sim, I want to derive all my objects from this "Block ALPHA" object and its' set of variable ...
0
votes
2answers
68 views

How do I reference one gameObject with script attached to other?

this is all in Unity 3D with C#. Thing is, I have attached a script to my player that should Destroy TreeGroup (as in forest) whenever I press 'Q' and Instantiate them when I press 'E'. Here is the ...
0
votes
1answer
32 views

Coroutine wrong Behavior when scene is loaded.

Ok so I have this coroutine : IEnumerator ShowCharTraits() { while(!hasPlayerChosen) { yield return null; traitPanel.SetActive(true); } ...
0
votes
1answer
94 views

Unity AddExplosionForce to a Navmeshagent

the navmesh agent is intaracting with the exploding object, explosion occurs and agent takes damage but no pushback occurs. expodingobject using UnityEngine; using System.Collections; public ...
1
vote
1answer
45 views

How do I toggle color writes in SlimDX 11/Direct3D 11 with FeatureLevel 10?

I'm having trouble setting the RenderTargetWriteMask field of a RenderTargetDescription struct. I simply want to toggle color writes but every time I try to enable the the color writes are changed ...
1
vote
0answers
21 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 ...
0
votes
1answer
505 views

3d Wall sliding collision

I'm working on collision for walls in my game and the way I currently have it I get stuck walking into a wall. I'm trying to make my character slide on the walls but still collide. My character moves ...
1
vote
1answer
47 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
1answer
40 views

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

Gamesparks has a documentation of the API but I am not sure how to send https requests to use that API.
2
votes
1answer
539 views

NegaScout with Zobrist Transposition Tables in Chess

I'm trying to put Transposition tables into my alpha beta scout. I do see an incremental speed boost I think toward mid or late game, however, even with a table size of 1-2GB, its may or may not be ...
0
votes
1answer
369 views

Unity5 TextAsset not functioning in WebPlayer

Preface I am working on a 2D Platformer in Unity5 utilizing TileMap techniques. I have a working system to read "Room Tile Data" from JSON files with the Unity TextAsset Class and the Newtonsoft ...
1
vote
3answers
95 views

Unity AddForce causing twitch

Since this wasn't clear enough, I've removed even more code. It kind of defeats the purpose I was aiming for, but I guess getting any answer relevant to the problem is better than none. What I want: ...
0
votes
1answer
40 views

Elastically Object movement in unity3d

I want to move an object towards the destination elastically. Currently I am using Vector3.Lerp it working to move the object, start with high speed and reached at destination with low speed but ...
1
vote
0answers
23 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
1answer
328 views

GUI.DrawTexture problem in Unity

I'm having a problem with GUI.DrawTexture() and I'm looking an alternative function to draw 2D Texture Images. The problem I have is that my textures draw above all other objects and when my camera ...
0
votes
3answers
65 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 ...
2
votes
1answer
213 views

2D lighting causes black rings to appear

A year ago I implemented 2d lighting in XNA using sprites. The sprites I used were created by placing a soft white photoshop brush on a transparant background. The result was this: (lights only) ...
-2
votes
4answers
96 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)?
0
votes
0answers
23 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 ...
3
votes
2answers
259 views

Mock Collision Object in Unity

Problem: I'm trying to set up some tests with mock collision objects, but i cannot construct collisions with custom objects. What I'm trying to do: Collision2D col = new Collision2D(); col....
0
votes
1answer
58 views

Trouble GamePad input on iOS but works perfect on Android

I am having trouble getting input from on iOS devices (iPhone 6 Plus and iPad). Here is my code, if (Input.GetKey (KeyCode.JoystickButton14))// A { chr_show = "A"; } if (Input....
0
votes
1answer
37 views

Move unit 64 pixels at a time Unity3d

I'm new to Unity and am trying to learn how to use it. I'm making a 2D top down Frogger-esque game. I was wondering how you would go about making the player move x pixels per button press. I currently ...
1
vote
2answers
23 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; ...
2
votes
2answers
739 views

Unity 2D Alpha cutout layer for Sprites

I'm trying to make a simple Fog of War effect for my 2d game, similar to these: . I want to have a sprite layer of black and then have a sprite to cut out itself from the black layer, leaving a ...
0
votes
1answer
13 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
1answer
62 views

C# OpenTK Text rendering

I've been looking everywhere for a solution on how to render/draw text for my 2D OpenTK-based game. Been trying quite a few QuickFont ones without success (either a AccessViolation exception or text ...
1
vote
1answer
442 views

XNA (BEPU) Physics Performance

Im using XNA 4.0 with the BEPU physics engine v1.2 and I have encountered some performance problems on Xbox. Im not sure if the my mesurements are an expected result of the Xbox (with alot of dynamic ...
0
votes
0answers
50 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 ...
0
votes
2answers
52 views

MonoGame Gamepad Y axis flipped?

I'm following a book I bought on Google Play that is teaching me the ropes of MonoGame, and in Chapter 2 it introduces creating an input wrapper that takes care of all the input methods for a game pad ...
2
votes
2answers
18k views

How to add a UI Text for keeping Score in Unity 5

My Problem is simple I want to show scores on my game. The examples on internet are good but in Unity 5 there are no GUI elements but instead these are now UI elements. I was following this example: ...
3
votes
1answer
1k views

How do i define array in shader's constant buffer with C#?

I am using SharpDX to render 3D graphics and i cannot get to work constant buffer in my shader since it contains an array. Currently it looks like this: cbuffer cb0 : register(b0) { matrix mWorld;...
0
votes
1answer
114 views

Slow collision detection at low frame rates

I'm experiencing an odd issue with my collision detection. I'm using the Update method to move the player (I don't want to use FixedUpdate because that creates an undesired weird movement). The fixed ...
30
votes
5answers
6k views

Use an instance or a class for game resources (wood,iron,gold)

So I'm making a game where you can send ships to locations to sell or buy resources like wood, iron, gold, etc. Now I was wondering how the resources should be created in de game. I came up with 2 ...
0
votes
1answer
119 views

Creating a Board Game Strictly Using Windows Forms

I'm working on my final project for a Software Design class, and we've been tasked with creating a board game, specifically Risk. Right now, the back-end game logic is functional, however I'm ...
0
votes
3answers
303 views

Arrow key control on winforms RichTextBox

I am making a faux console using winforms for the game I am working on. Right now I am moving a '0' across the screen using the arrow keys. In order to provide fine grain formatting on the text, I ...
0
votes
1answer
105 views

Distance based item interaction

I'm having an odd issue in my implementation of distance based object interaction in Unity. Basically it's a simple "Press [key] to [search/pickup/open/etc]" function which requires the player to be ...
1
vote
1answer
144 views

Keeping object a fixed distance from the ground, buggy behavior

I'm trying to make a script that will keep my object exactly 1 meter from the ground. So far I've got the following code : using UnityEngine; using System.Collections; public class ...
0
votes
2answers
46 views

snap an object to another object?

so I have some walls which are cubes stretched along a direction.and I have some windows and doors that are suppose to snap to a wall and don't let go until the desired location is out of the snapping ...
1
vote
3answers
430 views

UNITY : I want to make my UI text fade in after 5 seconds

I know this question has been asked and asked but none of the topics i visited gave me an answer. I'm making a game programmed in c# where you control a boat and i want my UI to appear smoothly by ...
3
votes
2answers
103 views

Start Menu Does not Work

On starting the game, a basic startmenu should load. startScreenUI is the background image, and startUI is the buttons for "play" and "exit". I set Time.timescale to zero in Awake() so that the time ...
0
votes
1answer
76 views

Rotation Continuity help

First the issue im having: Basically its the fact that the angles of a circle aren't continuous, they rise from 0 to 2pi then immediately fall back to 0. I want to make a game where the player ...
0
votes
1answer
27 views

Unity 2d square position not lining up with its size

I want to have one square that rests at the Unity 2d coordinates (5,5). Using transform.localScale I make the square be 3 units by 3 units large. So I thought that if I made another square that is the ...
0
votes
1answer
73 views

Game crashes when sound is finished

I'm trying to code a simple audio playback test game (which will be used in my actual project), and everything works fine, except for the fact that after the audio has finished playing, the game will ...
0
votes
0answers
12 views

How to write array of rgba to RenderTarget as a bitmap?

I have data in rgba format that I want to display as an image in my OnRender() method. I would like to do something similar to this: // initial data int [][] rgba; ...
2
votes
3answers
478 views

2D Game has very bad lag because of one script?

I am making somewhat of a flappy bird clone (mostly for practice) and everything works fine, but it is just really slow with a low FPS of 13 and a max FPS of 28. Why would this be? So I ran a check ...