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

-5
votes
1answer
305 views

Check elapsed time in Unity?

How can I check the elapsed between two intervals? I want to do the following: "start time counter when Input.GetButtonDown("Fire1") , stop counter when collision is detected` And then Debug.Log the ...
1
vote
1answer
33 views

Trying to make a respawn trigger, but any rigid body (or collider probably) keeps triggering it. Any ideas?

I'm trying to make it so that if any object passes through with the matching tag it will reload the level. However, any rigid body (or collider) is setting it off which is not the desired behavior. ...
3
votes
1answer
156 views

new graphicsdevice returning null

I tried to make a collision box visible (for testing) with spriteBatch.Draw(with a blank texture) in my TileSprite class. I needed a GraphicsDevice for this so these are my variables: Texture2D ...
2
votes
1answer
142 views

Replace black color by transparent color XNA

I'm actually trying to replace black color of my texture by a transparent one. How can I do to remove the black pixels, should I use a AlphaTestEffect, or can I use the BasicEffect? Thank you.
3
votes
1answer
60 views

Drawing collision detection boxes

So I have a TileSprite class that makes a TileSpriteobject with a collision box in it named bCollisionRect: public TileSprite(Texture2D textureImage, Vector2 position, Point frameSize, Point ...
2
votes
0answers
36 views

How do I display an image after pressing an UI button in unity3d? [duplicate]

I am working on a game in unity3d in which I want to display the details about the players when a button is being pressed. Suppose there are 12 players so for that I will have to make 12 UI buttons as ...
2
votes
1answer
148 views

How do I set the Jump distance and height of my sprite in C#

I have been able to make my sprite jump for a platformer I am making in unity. I can't seem to be able to make him jump a certain height or distance though, every time he jumps it's like he's jumping ...
1
vote
1answer
91 views

Applying Transformation Matrices to VBOs in OpenGL

So I've recently tried to add Vertex Buffer Object Matrix transformation to an OpenGL engine I'm working on. I could go about this by applying the matrix to a copy of each vertex individually, but ...
1
vote
0answers
59 views

Collision issue [closed]

I have a player who i control with tilting. Also i have some game objects (something like ground or areas where player can not move). The problem is that if these objects are too small the player can ...
3
votes
1answer
210 views

Filling a polygon with a texture (or a color) C# Visual Studio

I'm trying to figure how to put a texture or fill a "DrawPolygon" with a simple color in C# Visual Studio (using right now 2015). //Left Wall 1 Point lw1a = new Point(18, 7); Point lw1b = new ...
2
votes
1answer
216 views

Texture tearing with UV texture atlas mapping

The following code maps the texture from a texture atlas to a UV. The problem is I'm having texture tearing issues. Does anyone know how to overcome this problem and have any suggestions? Here is the ...
2
votes
5answers
775 views

Jump a gameobject when a key is pressed

I am working on a platform game,When I press the space bar the object should jump and when I release the space bar it should come down. The code I have used for jump is void Update () { ...
5
votes
2answers
114 views

How to find out the vertices of the polyhedron formed by the overlapping area of two rotated boxes?

What is the most efficient way for finding out the vertices of the polyhedron formed by the overlapping area of two rotated 3D boxes? If it is still confusing what I mean by "polyhedron formed by...",...
1
vote
2answers
141 views

Error with Quaternion.FromToRotation in Unity?

I get multiple errors whenever I run this code: transform.rotation = Quaternion.FromToRotation (Vector3(0, 0, 0), Vector3(0, 0, 270)); Can you suggest a fix for this code? Errors: Expression ...
5
votes
2answers
2k views

My game crashed… Access Violation (0xc0000005)

I guess this is the first official crash I've had in Unity (that is not just an infinite loop.) The game works just fine in the editor but when build and run it, the game won't even start. I just ...
2
votes
2answers
207 views

How I can count how many time gameOver scene is loaded?

I'm building a game using unity 3d and I want to add an interstitial ads to it, but I want it to appear after the player lost every 3 times. So when the player loses for the first time the ads will ...
1
vote
1answer
37 views

Unity object stuck where it shouldn't

Here's the thing. I am making a 3D top-down game about cars on the road. Right now I have different-colored cuboids representing cars. They are position-locked in Y and rotation-locked on all three ...
1
vote
1answer
542 views

Failed to load QCARWrapper.dll

I am using unity 5.1.0f(64 bit) and Vuforia SDK Version: vuforia-unity-5-0-5 The web cam is operating normally in windows but in unity in Play Mode not. I am getting an error message "failed to ...
2
votes
1answer
91 views

Game over when both players die

I watched the Unity Space Shooter video tutorials and then I have added a second player. I can not seem to get the 'Game Over' when they both die. It will happen when one player dies but not both. ...
-5
votes
1answer
327 views

Make Camera follow object only on Y axis?

Can someone give me a script that makes the camera follow a specific gameObject only on Y axis without changing the camera's X axis position, in C#?
-1
votes
1answer
62 views

Moving vector shooting at other moving vector

The following code creates an accurate shot to be made at a moving target from a stationary position. (ie a tower or non-moving vector). It works GREAT, but I need it to consider the movement of the ...
2
votes
4answers
117 views

Wall-Sliding, Stuck at Corners

I am having trouble with my 2-D wall-sliding. Namely, when the player avatar collides with the wall, it "snaps" to the corner (see screenshot, below) and sticks there. The red, transparent rectangle ...
2
votes
1answer
224 views

How to convert UV position to texture atlas pos and reapply to UV in Unity

I'm trying to apply a texture from an atlas to a mesh by reiterating through the UV array on that mesh, but I'm a bit lost on converting the coordinates. For example, if the texture required is at x,...
-1
votes
2answers
61 views

FixedJoint error in Unity?

I get the following error every time I run the code: error CS0120: An object reference is required to access non-static member `UnityEngine.Joint.breakForce' Joint.breakForce = Mathf.Infinity; How ...
0
votes
1answer
83 views

What are some good namespaces for gameplay code? [closed]

I always struggle with naming namespaces when working in a team. I'd be very thankful if someone could share your preferred way of namespacing gameplay code? At least the root namespaces. Edit: As ...
2
votes
1answer
108 views

In Unity, why does my IndexOutOfRange exception disappear when trying to debug it?

I don't get errors when playing from Unity "Game" tab. But when I build an executable (development or not) it stucks. I get "IndexOutOfRange" exception. Which also magically disappears (yes) when I ...
1
vote
1answer
65 views

Error calling another class? [closed]

I get the following error every time I run the code: error: error CS0119: Expression denotes a `type', where a `variable', `value' or `method group' was expected void OnCollisionEnter() { Stick (); ...
3
votes
3answers
209 views

2D Collision at corners using C# - without xna or unity

I'm trying to make collision for a 2D game, the player (car) has to collide with the walls of the track when it hits them. I looked into pixel color detection, and X,Y -based collision (But since its ...
1
vote
1answer
134 views

In Unity, How to format Old RPCs into new “PunRPCs”

In older unity versions you could simply used RPC. With newer verisons of Unity my code now doesn't work and it says that it needs to be transformed into "PunRPC" , Pun being "Photon Unity Networking."...
-1
votes
1answer
64 views

Issue with my script; An object reference is required to access non-static member

I'm having an issue with my script and I don't have a clue what is wrong. The error I get is: Assets/Scripts/BlackBirdDrag.cs(43,41): An object reference is required to access non-static member `...
5
votes
3answers
765 views

Is a custom coordinate system possible in Unity

Is it possible to create a custom coordinate system (i.e the one using double for coordinates or the one dividing the world into 'chunks' of safe size) not constrained by the floating point precision ...
0
votes
1answer
133 views

Choosing random array indexes in Unity C# [closed]

I want to change a string by randomly choosing an index in an array, using the random.range command in unity. Bare in mind that I'm using strings here, not floats or integers. Here is a code example(...
6
votes
3answers
535 views

Overcoming float limitations for planet-sized worlds in Unity

As far as I know, going further than 1M units from the world origin in Unity is hardly possible due to floating point precision issues. Making a world more than 1M units in radius would require ...
1
vote
2answers
515 views

Is there a random command for Boolean variables in Unity C# [closed]

Can you randomly choose a Boolean's value in Unity C#. I tried random.range, but it only works with floats. Here is an example of what I'm trying to do: Boolean = (random boolean value command)(false,...
1
vote
1answer
308 views

Make gameObject “stick” to another gameObject after it has collided with it? [duplicate]

Currently, I am using the following code to make objects stick to other gameObjects. rb = GetComponent<Rigidbody>(); rb.isKinematic = true; gameObject.transform.SetParent (col.gameObject....
2
votes
1answer
317 views

“Squeezing” a game object based on distance to another game object [duplicate]

I am trying to "squeeze" a gameObject. When distance starts to be 6.98, execute this code: "The smaller the distance between gameObject1 and gameObject2, the thinner and longer this gameObject is". ...
2
votes
0answers
241 views

In Unity, how do I make a 3D flight arc preview?

I'm stuck on how to make a preview trajectory for a projectile appear when holding a button. The trajectory should start at a certain position on the scene and end wherever the player points their ...
1
vote
1answer
164 views

Making isKinematic false when OnCollisionEnter()?

I have an issue with my script, I want to make rb.isKinematic go from true to false when collision is detected. With this script, nothing happens when a supposed collision is happening which means ...
8
votes
4answers
812 views

How do I efficiently check if a point is inside a rotated rectangle?

Part for the sake of optimization, part for learning purposes, I will dare to ask: How can I most efficiently check whether a 2D point P is inside a 2D rotated rectangle XYZW, using C# or C++? ...
3
votes
1answer
659 views

How to get direction and velocity of movement of an object dragged with the mouse in Unty (C#)

I have an object that is dragged by the mouse (X and Z positions) over a table, with the following simple code: Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if(Physics.Raycast(ray, ...
2
votes
1answer
99 views

Toggling Mouse Lock

I've been having some trouble toggling on and off the Cursor.lockMode and Cursor.visible. My goal is that when you are playing, the cursor is locked and invisible, and when you press escape, a pause ...
0
votes
1answer
95 views

How can I disable a RigidBody?

I have tried to set Rigibody enabled to false with this code but I get multiple errors. What is the correct version of this code? GetComponent<RigidBody>().Enabled = false;
1
vote
0answers
94 views

Chartboost Adds are not showing up in android

I am testing chartboost example but no adds are being shown up. I have added app ID and signature. and Even test mode is enabled still its not showing up. I am using chartboost SDK Provided by ...
1
vote
0answers
74 views

XNA Collision In An Entity Part System

I've hit a loss in creating a "game engine" in XNA, I'm extremely confused over how to approach collision in an Entity-Part System ( following this as a reference ). I can make all the entities with a ...
2
votes
1answer
118 views

How can C# access JavaScript variables in Unity 5?

I have a static public boolean in a JavaScript and I want to access it in a C# script. When I tried the way that you would call a static variable from another script though, it said that the variable ...
2
votes
1answer
99 views

Find out hit child with RaycastHit

Let's assume having a (2d-) gameobject with 3 images: Head, body, feet. By using RaycastHit2D I can find out if the gameobject was hit (for example by the mouse): RaycastHit2D newSelectedObject = ...
-1
votes
1answer
81 views

How do I show the ranking images at winning post?

I am working on a racing game in Unity3d and I have to show the rank as the winners touch the winning point. As the winners reach at the winning point the image of the winner number should pop up for ...
5
votes
2answers
777 views

Is there an efficient way to identify in which run-time generated room a character is, in a non-grid 3D environment? How?

Here is what I am trying to implement. I wrote a script that allows the player to place walls during run-time, in non grid-based 3D environment (walls can be diagonal with rotation increasing/...
-1
votes
1answer
63 views

Unity 5: Stays slow after code runs

Hi guys :) I have just tweaked the FPSController Script so that when you are below 6y, you are slower and gravity is a little weaker. This is to simulate underwater effects, but when you come out of ...
1
vote
2answers
269 views

Position UI.Button to mouse position

This has been discussed a couple of times, but I didn't find any solution: I want to set the position of an UI.Button to my mouse position. I can get the mouse position like this: Vector3 ...