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
14 votes
3 answers
8k 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 ...
  • 2,929
100 votes
6 answers
160k 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 ...
12 votes
3 answers
7k 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 (...
  • 619
13 votes
4 answers
5k 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^...
  • 5,333
41 votes
4 answers
71k 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 ...
  • 1,401
4 votes
1 answer
4k 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 ...
  • 65
3 votes
2 answers
652 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 ...
  • 1,217
0 votes
1 answer
3k views

Car driving through walls with transform.Translate()

I need help with a script for a very simple car that uses transform.Translate: ...
73 votes
10 answers
209k 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 ...
  • 1,389
27 votes
5 answers
34k 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?
  • 594
8 votes
1 answer
34k 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 ...
23 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 ...
3 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. ...
  • 133
9 votes
4 answers
11k 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 ...
  • 117k
4 votes
1 answer
6k 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 ...
8 votes
5 answers
37k 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 ...
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 ...
  • 1,444
1 vote
2 answers
3k 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 ...
  • 425
77 votes
13 answers
104k 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 ...
  • 871
43 votes
4 answers
15k 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 ...
  • 761
12 votes
1 answer
23k 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 ...
  • 1,863
11 votes
1 answer
2k 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 ...
  • 111
14 votes
4 answers
17k 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 ...
  • 541
2 votes
1 answer
2k 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 (...
  • 459
7 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 ...
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 ...
  • 85
38 votes
2 answers
12k 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 ...
  • 493
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 ...
  • 1,382
11 votes
3 answers
31k 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) ...
  • 181
8 votes
2 answers
26k 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. ...
4 votes
2 answers
8k 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 ...
  • 113k
4 votes
2 answers
2k 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 ...
  • 201
1 vote
1 answer
11k 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 ...
  • 13
5 votes
2 answers
9k 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 ...
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 ...
  • 1,515
2 votes
1 answer
1k 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 ...
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 ...
1 vote
1 answer
1k views

Unity: Assign GameObject to Class that hasn't been yet instantiated

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. ...
  • 33
4 votes
2 answers
20k 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.
5 votes
1 answer
4k views

Unity – 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 ...
  • 51
4 votes
1 answer
5k 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 ...
  • 3,571
6 votes
1 answer
389 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 ...
5 votes
3 answers
34k 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 ...
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 ...
  • 75
1 vote
1 answer
1k 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 ...
  • 541
1 vote
2 answers
885 views

Pixel Perfect 2D tiles

I'm trying to make an 64x64 tilemap using Super Tilemap Editor & Unity but my tiles looks terrible. I did my research about pixel perfect 2D and all of the solutions were for pixel art, they didn'...
0 votes
4 answers
93k 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: ...
31 votes
2 answers
135k views

Is it possible to use C++ with Unity instead of C#?

The title kind of says it all. Is it possible to replace C# with C++ on a game using Unity?
33 votes
6 answers
83k views

Can I legally remove the default Unity splash screen by removing it from the APK?

While using Unity I export an Android game as an APK. When the APK is run, the first thing that is displayed is the Unity splash screen. I worked out that I could replaced that image by opening the ...
20 votes
1 answer
8k views

What is the size limit to the Unity 2017.2 Tilemap?

I've been digging through the documentation on the Tilemap feature of Unity 2017.2. Does Unity limit the maximum number of tiles it will support for a particular tilemap mesh? I know that each tile ...
  • 1,740

1
2 3 4 5
19