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
9
votes
3answers
5k 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 ...
54
votes
4answers
80k 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
3k 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 (...
9
votes
3answers
3k 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^...
33
votes
4answers
59k 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 ...
3
votes
1answer
2k 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 ...
22
votes
4answers
10k 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
2answers
3k 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. ...
17
votes
4answers
20k 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?
5
votes
1answer
19k 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 ...
10
votes
2answers
6k 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
1answer
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 ...
0
votes
1answer
1k views

Car driving through walls with transform.Translate()

I need help with a script for a very simple car that uses transform.Translate: ...
68
votes
12answers
75k 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 ...
6
votes
5answers
19k 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 ...
4
votes
1answer
2k 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 ...
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 (...
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 ...
0
votes
1answer
706 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. ...
34
votes
2answers
9k 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 ...
8
votes
1answer
13k 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
2answers
4k 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 ...
3
votes
2answers
11k 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. ...
3
votes
2answers
805 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 ...
0
votes
2answers
168 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 ...
6
votes
1answer
267 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 ...
4
votes
7answers
8k 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 ...
4
votes
2answers
8k 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 ...
3
votes
1answer
676 views

Check if GameComponent is ready in Unity?

I am trying to create a MessageBox in Unity, but I'm having some troubles in C#.. This is my code (I'll explain my problem later): MsgBox.cs ...
3
votes
1answer
4k 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) ...
23
votes
2answers
93k 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?
15
votes
1answer
33k 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 ...
11
votes
1answer
72k views

Change the sprite of a Object in Unity

Inside the script code of the the hero(object) I want add the possibility to change its sprite. So the player hits the space button and the sprite changes into the other sprite already added to the ...
8
votes
1answer
7k 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. ...
6
votes
3answers
5k 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 ...
10
votes
1answer
954 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 ...
4
votes
1answer
20k views

How do I set the exact local position of a RectTransform?

I have a game object that creates a keyboard in side of my world canvas. I am working out the offset positions for each key, and appear to be doing that correctly. However, when I set the positions in ...
0
votes
1answer
4k 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 ...
5
votes
2answers
4k views

Unity prefab script “GameObjects” can't be ones on the scene?

Currently, I have an object on the scene, and one in prefab. I want the prefab's script to reference to the object on the scene through the public GameObject obj; ...
5
votes
1answer
2k views

How do I make an object face the mouse position, but only on one plane?

I want a game object to turn and look towards where the mouse was clicked (in world space). It works well when considering all 3 dimensions, but I really only care for the plane formed by the ...
5
votes
1answer
6k views

In Unity, why do my animator states wait until the end of each animation to change?

I'm trying to make a simple idle-walk transition in Animator using Unity. I've set a script that changes the Speed value from the Animator, and it works perfectly when I move the character forward ...
3
votes
1answer
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 ...
1
vote
2answers
2k 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 ...
0
votes
1answer
851 views

Difference between 'max distance' and 'radius' in Physics.SphereCastAll

I needed a way to check for all gameobjects within a set sphere of my player object. I found Physics.SphereCastAll which will return a RaycastHit[], exactly what I wanted. But, I am having trouble ...
0
votes
3answers
2k views

Check if all gameobjects are destroyed

I am making a shooting game, where I have a countdown as I destroy enemies. I want to implement logic when all the game objects are destroyed within the given time, and the countdown reaches zero. ...
25
votes
9answers
17k views

Best place for learning how to write games in Unity3d [closed]

What's the best place for tutorials & other learning resources for unity3d?
39
votes
9answers
82k 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 ...
24
votes
2answers
5k 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 ...
25
votes
3answers
6k 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 ...
29
votes
6answers
60k 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 ...