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
3answers
7k 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 ...
12
votes
3answers
6k 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 (...
88
votes
6answers
137k 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 ...
11
votes
3answers
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^...
4
votes
1answer
3k 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 ...
41
votes
4answers
69k 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 ...
0
votes
1answer
3k views

Car driving through walls with transform.Translate()

I need help with a script for a very simple car that uses transform.Translate: ...
25
votes
4answers
29k 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?
1
vote
2answers
393 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 ...
23
votes
4answers
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 ...
6
votes
1answer
31k 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 ...
3
votes
2answers
4k views

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

My goal is to program a camera to point towards the mouse cursor. I attached the following script to the Main Camera. ...
72
votes
13answers
96k 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 ...
10
votes
3answers
10k 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 ...
7
votes
5answers
32k views

Unity - Tiling of a material, independen 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 ...
2
votes
1answer
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 (...
7
votes
2answers
4k 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 ...
62
votes
10answers
166k 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 ...
26
votes
2answers
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 ...
12
votes
1answer
20k 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 ...
4
votes
1answer
3k 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 ...
4
votes
2answers
7k 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 ...
4
votes
2answers
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 ...
14
votes
4answers
15k 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 ...
5
votes
2answers
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
2answers
1k 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 ...
2
votes
1answer
468 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 ...
1
vote
1answer
9k 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 ...
4
votes
8answers
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 ...
3
votes
1answer
3k views

Why is Raycast hitting masked layer?

Many questions have been posted on this topic but I'm facing a weird behavior which I could not find an explaination for. I perform a raycast giving it a LayerMask parameter which is defined as ...
1
vote
2answers
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 ...
1
vote
1answer
971 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. ...
1
vote
2answers
1k 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 ...
35
votes
2answers
11k 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 ...
4
votes
2answers
17k 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
2answers
21k 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
1answer
4k 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 ...
6
votes
1answer
333 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 ...
1
vote
1answer
925 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 ...
1
vote
2answers
709 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
4answers
82k 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: ...
41
votes
4answers
14k 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 ...
29
votes
2answers
125k 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?
32
votes
6answers
79k 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 ...
8
votes
2answers
13k views

Best way to interpolate player movements in a very fast paced Unity game?

In my Unity online multiplayer game players move very fast and I currently use Lerp to interpolate between their last position and current position: ...
16
votes
1answer
49k views

Is it legal to sell or monetize games created with the Unity 3D free edition?

Is it okay to use Unity 3D programming and gaming software to create mobile game apps for Android and iOS? I am using a free version of Unity 3D and planning it to sell my current game app I've ...
8
votes
1answer
10k views

How do I compile a C# script at runtime and attach it as a component to a game object

The idea here is to let users program the behaviour of an agent in a way that reminds of the "Screeps" game, where you get to develop code which later runs and dictates the behaviour of your units. ...
10
votes
1answer
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 ...
7
votes
3answers
7k 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 ...
4
votes
2answers
4k 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 ...

1
2 3 4 5
18