Questions tagged [unity]

Unity is a cross-platform game creation system that focuses on easy art pipeline process. It consists of a game engine and an integrated development environment. The game engine's scripting is built on Mono.

Filter by
Sorted by
Tagged with
15 votes
3 answers
9k views

NullReferenceException in Unity

Since many users are facing the NullReferenceException: Object reference not set to an instance of an object error in Unity, I thought that it would be a good idea ...
Hellium's user avatar
  • 2,949
14 votes
4 answers
8k views

Why use Time.deltaTime in Lerping functions?

To my understanding, a Lerp function interpolates between two values (a and b) using a third value (...
AzulShiva's user avatar
  • 669
106 votes
6 answers
180k views

What is the proper way to handle data between scenes?

I am developing my first 2D game in Unity and I have come across what seems an important question. How do I handle data between scenes? There seems to be different answers to this: Someone mention ...
Enrique Moreno Tent's user avatar
13 votes
4 answers
7k views

How can I launch a GameObject at a target if I am given everything except for its launch angle?

I am trying to launch an object at a target, given its position, its target position, the launch speed, and the gravity. I am following this formula from Wikipedia: $$ \theta = arctan \bigg( \frac{v^...
Evorlor's user avatar
  • 5,793
1 vote
1 answer
4k views

Car driving through walls with transform.Translate()

I need help with a script for a very simple car that uses transform.Translate: ...
Starnight Studios's user avatar
42 votes
4 answers
73k views

How to not freeze the main thread in Unity?

I have a level generation algorithm that is computationally heavy. As such, calling it always results in the game screen freezing. How can I place the function on a second thread while the game still ...
DarkDestry's user avatar
  • 1,431
4 votes
1 answer
5k views

Any way to combine instantiated sprite renderers into one texture so I can apply into a plane at runtime?

So I am procedurally generating a tile set in Unity by instantiating different tiles that only have a transform and sprite renderer components. I managed to pack the sprites using unity sprite packer ...
Kepol's user avatar
  • 183
4 votes
2 answers
1k views

Nestling into contact with a group of physics objects without exerting forces on them

I'm making a pool game, and would like the circle (imaginary) to be in contact with the table and balls, and to fit perfectly as a ball would. Now I thought I would use Rigidbody and lerp the ...
John Smith's user avatar
  • 1,255
79 votes
10 answers
231k views

In Unity, how do I correctly implement the singleton pattern?

I have seen several videos and tutorials for creating singleton objects in Unity, mainly for a GameManager, that appear to use different approaches to instantiating ...
Zack Brown's user avatar
  • 1,459
28 votes
5 answers
42k views

When should I use velocity versus addForce when dealing with player objects?

I'm confused about these two methods in the Unity framework. Both make the player object move, stop, change direction, etc. When should one be used over the other and when is one appropriate?
Robert's user avatar
  • 604
22 votes
4 answers
12k views

Saving player's progress in a Unity game

I am making a game using the Unity game engine. I want to save the player's progress including level, experience points, chosen character, etc. Presently I am using playerprefs but I want to know ...
Shantanu Singh's user avatar
8 votes
1 answer
38k views

What sprite size should I use for 2D game?

I try to create a 2D game for Android. It looks like Cut the rope (it isn't a clone but it have same level representation) if it has a value. My problem that I can't understand that optimal sprite ...
Denis Steinman's user avatar
43 votes
4 answers
17k views

What happens when Time.time gets very large in Unity?

As it is said here : Time.time The time at the beginning of this frame (Read Only). This is the time in seconds since the start of the game. And as I know the time is stored in float. So, my ...
Yaroslav's user avatar
  • 771
26 votes
2 answers
6k views

Using Quaternions: What can I do with them? (without the maths)

I am a Game Developer and did not study Mathematics. So I only want to use Quaternions as a tool. And to be able to work with 3D rotation, it's necessary to use Quaternions (Or Matrixes, but let's ...
OC_RaizW's user avatar
  • 1,460
11 votes
1 answer
3k views

How can I fix zig-zagging UV mapping artifacts on a generated mesh that tapers?

I am creating a procedural mesh based on a curve and the size of the mesh gets smaller throughout the curve as you see below. And the problem is UV gets zig-zagged as the size changes (it works ...
fkkcloud's user avatar
  • 111
9 votes
5 answers
44k views

Tiling of a material, independent of its size

I am using Textures and Materials to tile my sprites, for instance when building a wall in my game. The problem with this is that everytime I resize the plane or size of my game object, I have to ...
Enrique Moreno Tent's user avatar
4 votes
2 answers
5k views

Why is the camera tilting around the z axis when I only specified x and y? [duplicate]

My goal is to program a camera to point towards the mouse cursor. I attached the following script to the Main Camera. ...
Nick B.'s user avatar
  • 143
4 votes
1 answer
4k views

Why is Raycast hitting a masked layer?

Many questions have been posted on this topic but I'm facing a weird behavior which I could not find an explanation for. I perform a raycast giving it a LayerMask ...
Leggy7's user avatar
  • 1,454
1 vote
1 answer
2k views

Unity block chunk generation pattern

I am trying to do something like Minecraft game in Unity. Currently I am trying to generate a chunk of blocks, given dimensions. I can successfully create a chunk of N x 0 x 0 sized chunk, but due to ...
Nick's user avatar
  • 561
9 votes
4 answers
12k views

Accessing DualShock 4 motion sensor in Windows (ideally Unity)

I'm trying to use a DualShock 4's IMU as a motion controller in Unity, under Windows 7. So far I've tried: DS4Windows (1.5.11): reads motion sensor data, but does not expose them to Unity as axes ...
DMGregory's user avatar
  • 134k
9 votes
2 answers
31k views

How to force keep the aspect ratio and specific resolution without stretching the output screen view?

I'm using Screen.SetResolution() But when I run in Android device, it shows the output image is stretched to fill up the full screen which I don't want. I want it to keep the aspect ratio properly. ...
elliotching's user avatar
5 votes
1 answer
10k views

How to randomly generate biome with perlin noise?

I want to generate a procedural world using perlin noise. As expected, my terrain is generating with a repetitive patern. I'd like to add biomes, zones separated with higher or lower amplitude to ...
Samuel Fyckes's user avatar
4 votes
2 answers
2k views

Reshapable polygonsprite

I have an sprite I want to use as a texture. I want to create an area, defined by a polygon collider, where the sprite is drawn. For example: Having the following sprite And the following polygon ...
Leo's user avatar
  • 1,585
4 votes
1 answer
6k views

How to make an Assert.IsNull test pass when the value is reported as <null>?

I've just started using unity tests with the built in editor tests. After making my test and finding out that it constantly failed I debugged the code and found that a static object was set to a new ...
user3797758's user avatar
  • 3,631
1 vote
2 answers
4k views

Lookrotation of a gameObject in just one axis

So I am trying to orient a gameObject ( house in the picture below) which is nothing but a plane and has a 2d texture on it as you see below. The whole game is made on a hex sphere. I am using ...
ckzilla's user avatar
  • 425
80 votes
13 answers
111k views

How do you handle aspect ratio differences with Unity 2D?

I've gotten a lot of answers to this question, but they are all generic and generally not very useful. None of the tutorials talk about aspect ratio and dealing with mobile devices and there are a ...
Michael's user avatar
  • 901
38 votes
2 answers
13k views

How do I make a character capable of walking on walls?

I am trying to get a character to move like a spider: Given a rising slope which a ball would normally not be able to roll up, the spider would slowly crawl up. Similarly, given a mid-air rectangular ...
pyko's user avatar
  • 493
14 votes
4 answers
19k views

How to solve the ground check problem?

I noticed a problem in Unity's third person controller's ground check. The ground check should detect whether or not the player is standing on the ground. It does so by sending out a ray beneath the ...
Black's user avatar
  • 621
12 votes
1 answer
26k views

Understanding pixel art in Unity 2d

I am struggling to understand the basics behind pixel art in Unity. I understand what a unit is, and that if I draw my sprite with 16x16 pixels, I should set PPU to 16. Take stardew valley for ...
Green_qaue's user avatar
  • 1,883
8 votes
2 answers
5k views

How to make prefabs independent?

I'm working on a Unity's Project and I want to modify a prefab, more precisely I want to change the texture of a prefab. The problem is that my modification is applied also to other prefabs. I read on ...
optimusfrenk's user avatar
2 votes
1 answer
3k views

Game states & passing data between scenes

I'm not entirely sure if I'm doing this right, but I always considered the scene system in Unity as some sort of state management (rather than e.g. a level system) which allows to group the contents (...
artganify's user avatar
  • 459
2 votes
2 answers
2k views

Camera relative movement is pushing into/off the ground instead of parallel

I'm building upon roll a ball tutorial in unity, and I have managed to rotate the camera around the ball just fine with the code below. But there's one problem. In this code, when I add force to the ...
MrChips's user avatar
  • 85
2 votes
1 answer
2k views

Issue with Sorting Layers with an NPC and Tilemap

I have a weird thing happening, that I can't quite explain. I have two scenes, my starting town, and an Arcanist's shop. When I go into the Arcanist's Shop, the Arcanist NPC stays on the same ...
Thomas Hutton's user avatar
12 votes
3 answers
41k views

Scale camera to fit screen size unity

My background and gameobjects are 2d sprites not UI images ,I want to know how to make my background scale with screen size and positions of 2d sprits on it don't change after building game (webGl) ...
Sh.Adel's user avatar
  • 191
5 votes
8 answers
12k views

Why is the IntelliSense not working when I open a new script in Visual Studio?

The strange thing is that opened scripts or newly opened ones are working fine. It's the new created C# scripts that are not working. With not working, I mean the MonoBehaviour is not in light blue ...
scriptal man's user avatar
5 votes
2 answers
10k views

2d metaballs with shader to give blobs of water effect?

I want to simulate blobs of water in a 2d game in Unity3d. One possible way of doing it is to use 3d metaballs moving in a 2d plane though this is very processor intensive. Do you think it would be ...
Guye Incognito's user avatar
4 votes
2 answers
9k views

How can I accurately simulate orbits in Unity?

I would like to create a space simulation with realistic gravity. This means planets in 3d space which act as central gravity sources and multiple objects which are attracted by those planets gravity ...
Philipp's user avatar
  • 119k
4 votes
2 answers
6k views

Can I clip a collection of geometry to render only inside a particular worldspace volume?

I am making a VR app in Unity. I have a giant map that I want to display on a virtual table. The map is too large to fit on the table, and I cannot change its size. (It is a third party asset, and ...
Evorlor's user avatar
  • 5,793
4 votes
3 answers
3k views

Floor is made up of tiles with their own box colliders. Pushable item gets stuck on the "seams"

So I have a scene where the floor is made up of some tiled objects. All of these have the exact same height and exact same Y position. I also have a block with a rigidbody that you can push on the ...
Andrio's user avatar
  • 221
1 vote
1 answer
1k views

How to assign game object references to a class instance created at runtime?

I'm creating a game where I have an Entity class that contains basic entity info (pos, health,..) and some functions. Enemies and Player later on inherit from this class. ...
MSKL's user avatar
  • 133
1 vote
1 answer
12k views

UV World mapping in shader with Unity.

Please refer to this Answer. DMGregory script is working for me, although I have a problem I can't fix because I don't talk shader :) The tiling will be applied correctly on geometry aligned on XY ...
Chiodo's user avatar
  • 13
1 vote
3 answers
2k views

How do you have the clothing mesh hide the body mesh underneath?

How do you have the clothing mesh hide the body mesh underneath, to prevent odd patches of body from sticking out in tighter modular clothing? Is there some sort of shader trick that can have the ...
ina's user avatar
  • 284
0 votes
4 answers
102k views

How to access a variable from another script in Unity c#

I need to access a variable from another script in Unity, but I can't figure it out. Script: ...
user1627724's user avatar
26 votes
4 answers
11k views

How can I rotate an object based on another's offset to it?

I have a 3D model of a turret that con rotate around the Y-axis. This turret has a cannon that is significantly off the center of the object. I want the cannon, not the turret, to aim at a specified ...
Franconstein's user avatar
6 votes
1 answer
463 views

Adding functionality to make individual anchor points of bezier continuous or non-continuous

I am creating bezier curves with the following code. The curves can be extended to join several bezier curves by shift clicking in the scene view. My code has functionality for making the whole curve ...
SuperHyperMegaSomething's user avatar
5 votes
1 answer
5k views

How to keep sprites sharp and crisp, even while rotating

How can I maintain crisp, sharp edges on sprites, while avoiding the aliasing caused by rotation? None of the things I've tried produce a pixel-perfect non-rotated block, while allowing rotation ...
Drin's user avatar
  • 51
5 votes
2 answers
24k views

How to make curved GUI in Unity?

I'm really new in Unity. I want to make a curved GUI by myself. How would I make one? I'm using Unity 5.6.
GuardFromUA's user avatar
5 votes
3 answers
35k views

How do I have a camera follow my object in Unity?

I have an object that automatically moves by itself and I want the main camera to automatically follow it.(Like in games such as geometry dash and jetpack joyride) This is the code for the automatic ...
user1627724's user avatar
4 votes
1 answer
3k views

How to develop both a client and headless server together in Unity

I'm making a multiplayer 2d shooter platformer in unity. And after studying the different options to program an authoritarian server and with the great help that many of you have already provided me ...
coantia's user avatar
  • 57
3 votes
1 answer
1k views

Problem finding correct value for Yaw

I use an Arduino and a 9dof sensor ( gyroscope, accelerometer and magnetometer ) and i'm trying to use the pitch, roll and yaw that the sensor gives me to rotate an object in unity. I managed to ...
BAmadeusJ's user avatar
  • 175

1
2 3 4 5
20