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

0
votes
1answer
40 views

Draw a Texture to fit a rectangle

I would like to draw a texture in a rectangle that is smaller than the texture, normaly the texture will be scaled to fill the rectangle, which results in a squished image. I want to draw it to fit. ...
0
votes
1answer
65 views

Always operate at Time.timeScale = 1?

How do I make a specific script always operate at Time.timeScale = 1 no matter what? I want it to override even when another script calls Time.timeScale = 0 for example.
0
votes
0answers
52 views

MonoGame RenderTarget2D mipmapping fades textures when zooming out

I recently ported my XNA game to MonoGame. Unfortunately, some of the textures are being faded when: They are scaled-down from 32*32 to 16*16 When the camera zooms out, the texture fades from ...
0
votes
2answers
39 views

Get vector3 position of Cursor on a fixed 2D plane within a 3D scene

How is it possible to get a cursors X and Y Location relative to the scene planes rather than using co-ordinates based upon pixels of screen height and width? I have the start of a very basic game, ...
-2
votes
1answer
75 views

Is it possible to convert this if-else chain to switch-case? - Unity C#

Here is the code: if (Input.GetMouseButtonDown(leftMouseButton)) { OnLeftMouseButtonDown(); } else if (Input.GetMouseButton(leftMouseButton)) { ...
0
votes
1answer
82 views

Unity 5.3 C#: How to disable multiple game objects with one collision?

I'm making a top down perspective game with a gunner automatically moves on a pre-set path, and you shoot and destroy targets to remove barriers. The idea is that you control the bullet's direction ...
0
votes
0answers
39 views

Lock Z axis from the gyroscope rotation [UNITY 3D]

Here's the code I use. public class CameraGyro : MonoBehaviour { private float initialX; private float initialY; private float initialZ; // Use this for initialization void Start () { ...
3
votes
5answers
177 views

Generate random numbers in loop without repeating

How to generate Random numbers without repeating any numbers in the given target like(1-5000) there should be no reparation and I should be able to get 5000 randomized numbers. I should be able to run ...
0
votes
2answers
76 views

Build a vbo once every second

I have a VBO storing some data in my game. The thing is, the data can change at a rate of about a second. The data is not fixed size, meaning that some objects will sometimes be visible, sometimes ...
0
votes
0answers
47 views

Unity crash on iOS - GameObject.SendMessage()

Unity Version: 5.3.2p2 It's crashing from within Unity's internal code when doing a GameObject.SendMessage() call, it should be noted that this particular line itself is not the source of the crash ...
1
vote
1answer
114 views

How would I create a save function to my random generated game? [duplicate]

I'm making a 2D Tower Defense and currently looking into making a save feature. The problem is that my game is procedural generated (based on the rogue-like tutorial posted by Unity): At runtime I ...
0
votes
2answers
34 views

Stop rotating when select the game object by mouse input

I am new to Unity and I am confused about how to solve this problem. Initially, I want to make a platform rotate to its center vector up like this. transform.Rotate (Vector3.up, speed * ...
0
votes
1answer
39 views

Camera moving down

I'm working on Unity and I have already set how to smoothly move up camera when player get on higher position. But if player is on position which is below on camera, then you lost " life ". I need a ...
1
vote
2answers
73 views

Achieve a red lighning effect in unity for a 2d game

Effect that im refering to: http://youtu.be/jaBY83WvS3M#t=05m36s How could I achieve this kind of red lightning/flashing/shadowy effect in Unity3D for a 2D game? I'm trying to think of a way but I'm ...
0
votes
2answers
98 views

Detect Input.GetMouseButtonUp outside a GameObject in Unity?

How do I detect Input.GetMouseButtonUp outside a specific GameObject's area in Unity? Are there any Unity Assets for this?
0
votes
0answers
31 views

Clarifications about usage of delegates, events and coroutine in a Unity script

So, the question is a bit broad, but I need to clarify my ideas about how to use proficiently such tools. Background: I am writing a simple demo that basically does what simcity does: it start a ...
-1
votes
3answers
55 views

IEnumerable Elements 'Where' and 'Select' In Unity?

I have a C# program that has a function that reads an XML. I took that function and brought it over to my Unity game which will be using the same XML. However, my reading method doesn't seem to work. ...
-1
votes
1answer
61 views

Attack Targetted Enemy Only

I have a perfectly working targetting script and I want to be able to deal damage to my currently selected enemy. I have a targetting script which is below:? public GameObject enemy; public ...
0
votes
0answers
28 views

List derived class serialization

I have an extremely simple ObservableCollection<T> implementation using [Serializable] public class ObservableCollection<T> : List<T>, INotifyPropertyChanged {...} in Unity3D with ...
0
votes
1answer
31 views

Issue with in game replay system

I am creating a game in Unity 3D and I have recently come up with my own simple replay system. It works well except for one small problem: it doesn't always start off where I would prefer it to in the ...
1
vote
0answers
34 views

Map generation, issues with midpoint displacement algorithm

I'm trying to generate an endless 2d terrain. So the terrain isn't random per say as the random function I'm using is a hash based on an X,Y coordinate. static public float rand (System.UInt32 x, ...
0
votes
3answers
51 views

C# temporary variable error [closed]

I get the following error when running the code below: Cannot modify a value type return value of `UnityEngine.Transform.position'. Consider storing the value in a temporary variable public ...
0
votes
1answer
59 views

How can I instantiate in the current rotation in Unity 2d?

Backstory I'm currently working on a 2D sidescroller/platform game as a hobby, and I just started recently. Followed a few tutorials and such I managed to wrote my own code for basic command like ...
0
votes
2answers
55 views

Sprite doesn't move

Trying to create a 2d Top down random movement. I have the blendtree setup so that it faces the sprite in the right direction. However, I can't get it move right. It just flips back and forth between ...
2
votes
1answer
82 views

How can I draw my shapes based on their Z order value?

I'm using C# and I'm drawing shapes to a PictureBox. I'm not drawing anything in 3D. Instead, I draw 2D shapes and have a "depth" value. (which changes the size of the shape and its opacity) My ...
0
votes
1answer
33 views

Cannot define Public Transform Target On Unity C#

Getting UnityError Saying "UnassignedReferenceException: The variable target of Movement_Script has not been assigned Which is line 5 "public Transform target" I've tried a lot of things... I ...
0
votes
0answers
18 views

Cannot define “Public Transform Target” [duplicate]

I'm trying to create a fairly basic controller The Controls are meant to work as followed: Moving up one 'section' or line at a time Moving Right one 'section' or line at a time. The controller is ...
5
votes
2answers
101 views

Unity 2D graphical glitch cuts sprite diagonally

While making a game in unity, we found a graphical glitch that only happens on one of our mobile devices (a htc) where the screen will be oddly sliced by a triangle as shown in this image; I've ...
-1
votes
1answer
170 views

How to display text when mouse hover button in Unity 3D

I have a scene, where a panel containing 24 buttons. I need to show some piece of text when hover a mouse cursor over the button. For example, for detecting clicks, I'm using onClick event trigger, ...
0
votes
3answers
167 views

Correct architecture for weapon class in RPG

So, I'm a little stuck on what the best way to implement weapons is. The problem I'm running into is, what exactly is a weapon. I have a Player Class that has an attack method. public class ...
0
votes
1answer
67 views

Raycast from ScreenCenter hits object but does not return its tag

Here is my code: using UnityEngine; using System.Collections; public class Crosshair : MonoBehaviour { public Camera cam; RaycastHit hit; Quaternion rot; // Update is called once per ...
0
votes
2answers
86 views

how to create a play button and load game on play? Monogame

I need help with understanding how I can make my function work and load the game when pressing play. At the moment, when I press Play, it won't update or missing update o knowing the button is ...
0
votes
1answer
60 views

How to avoid recursive and or infinity loop monogame return function

This piece of code is returning on a infinite base how to fix? public GuiElement MoveElement(int x, int y) { GUIRect = new Rectangle(GUIRect.X += x,GUIRect.Y += y,GUIRect.Width,GUIRect.Height); ...
0
votes
0answers
41 views

Use Same Animation To All Object Having Diffrent Position

I am new in unity. create one animation to the object and create 10 duplicates of same object. I want to apply Same animation to the all objects without starting animation at the same time and without ...
0
votes
1answer
51 views

Referencing multiple canvas images through script in C#

What is the best way to reference multiple Canvas Images within C# script attached to my player in Unity? Currently I have something similar too: public Image image; //Finds the Image Object being ...
0
votes
1answer
87 views

Enable and disable different component on a Gameobject

So far I am not clear how do you actually access the various components on a game object, to enable and disable them. I have a component that has various scripts and elements, like a camera, ...
1
vote
0answers
32 views

How does this work? Data catching without displaying client [closed]

Alright so this is about a game, but more generally this can probably be done for all games, I just want to figure out how the application accomplishes it. So it's for a game called League of ...
-1
votes
1answer
59 views

Game State being skipped

One of my game states is being skipped (pressing space goes straight to the 'GameScreen' game state skipping the 'CharSelect' state). All help is appreciated. if (currentGameState == ...
1
vote
1answer
43 views

How can I once run For Loop in void OnGUI?

I want once run GUI on screen same Initialization a number. I try say my think In easiest way then please payattention to this code: using UnityEngine; using System.Collections; public class ...
3
votes
2answers
321 views

2D Platformer AABB collision issues

Before anyone say that this questions already has a answer, I will list all the questions I read and tried: AABB collision resolution issues Trouble with AABB collision response and physics Hard ...
3
votes
1answer
151 views

Unity: C# Spell System

I couldn't find any proper tutorials in the internet how to make one so I tried it myself. I've written a base "Skill" class with methods like Cast(), DealFlatDamage(), ShootProjectile() and they all ...
0
votes
2answers
39 views

How do you create test for unity variables that are set through the [SerializeField] tag?

I need to create some tests for a bunch of variables that are initialized via the editor, So in the script they are always null and can't be set publicly. Usually using the tag is a good way to ...
0
votes
1answer
82 views

Spawning random objects at random positions in the 3D world

My main character can move horizontally and not vertically. It can move from x = -4 to 4 and z = -4 to 4 (a square area). I don't want objects to spawn where my character can move but every where ...
6
votes
1answer
239 views

How to do Chromatic Aberration on a transparent background?

I have a problem with a chromatic aberration shader effect... If I produce the effect on a white background I get exactly what I want: But if I do the same effect on a transparent background I get ...
0
votes
1answer
40 views

Change material emission for a second then go back to default

I'm looking for a way to change the emission of a material for a second then get it back to where is was by default Here's what I have for now float emission_lvl = 5.0F; float emission_lvl_start = ...
0
votes
1answer
49 views

MonoGame-based animation system fails to change animation [closed]

We have a problem with the animation. The problem is that it won't play the right animation. We are using a spritesheet with 4 frames: idle, movement and so on. Here's the code we are using: class ...
2
votes
0answers
111 views

Tower Defence stat storing system

I'm trying to find a smart way to store and retrieve stats for a tower defence game, but am currently unsure as to which approach would be best. Description: The stats system should quite basic, ...
0
votes
0answers
65 views

2d Lighting over Sprites in C#

I am currently working under a project , a small application where i have to implement 2d lighting . For example , in the GDI+ canvas , a image will be drawn and i will have to put a lighting effect ...
0
votes
1answer
66 views

How would I handle collision to all instances of one object? (C# and monogame)

What I'm saying is, let's say I have a list. That list contains all the tiles in the game. I use this to update them all, draw them all, etc. for (var i = 0; i < Tiles.Count; i++) { ...
0
votes
2answers
82 views

Get Particular Object's collision status via C# script

My current scripts creates and modifys the location of various prefab objects as they go along the screen. One of the things I want to find out about the active object is whether it has collided with ...