Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.

Questions tagged [unity3d]

Unity, also referred to as Unity3D, is a cross-platform game engine with a built-in IDE developed by Unity Technologies. It is a commercial development platform for creating games, interactive 3D applications, training simulations, and medical and architectural visualizations.

Filter by
Sorted by
Tagged with
28
votes
4answers
4k views

Snake Game in C#

Recently, I have been trying to learn SOLID principles. I learn the best through criticism. I made this snake game in Unity with C#, where I put my current understanding of SOLID principles to test. ...
15
votes
3answers
1k views

Simulating gravitational attraction between bodies

I'm currently working on a simple simulator in Unity3D that involves planets orbiting each other. I wrote the following C# script to do that. It uses the classic gravitational formula, $$F=G\frac{...
11
votes
5answers
10k views

Moving character in Unity3D based on accelerometer input

I am building a infinite vertical platformer for mobile platforms using Unity3D. I am using the accelerometer to move the character left and right on the screen. ...
11
votes
1answer
173 views

Multiple similar manager classes for handling scroll lists

I am working on my first object-oriented programming project, written in C# for Unity. My code does what I want it to do, but I am wondering if there is a better way to do it. I think I am building ...
10
votes
2answers
1k views

Bouncing map back into its bounds, after user dragged it out

Users like exploring maps, seeing all that is around. However they tend to go too far. To prevent the map from getting lost to the user it bounces back into the set bounds, as defined by a rectangle. ...
10
votes
1answer
4k views

Inspector interface serializer

I've written some code that allows Unity3D's inspector to display fields that conform to an interface. Unity has some quirks about their inspector, so as a preface they are listed here: If you add a <...
9
votes
2answers
740 views

Event system in Unity RPG game

I'm making event system for my RPG game, and I want to know what I can do better, because I think that there are a lot things that can be better. Note that this code is still not completed but it ...
9
votes
2answers
448 views

Dynamic network messaging

I'm building a client and server for a game but wanted a generic messaging system in a shared library that let me focus on application logic and was largely separate form the underlying networking I/O ...
8
votes
2answers
386 views

Procedural World in Unity3D

The idea here is that rather than placing objects directly into the scene, these building objects are instantiated at run time and placed in the correct locations. This gives me full control over ...
8
votes
2answers
473 views

Is my implementation of FizzBuzz overkill?

I am doing FizzBuzz on a take home test (in Unity). I am sure this is just a competency check, but I went ahead and followed some coding conventions such as using constant fields, dependency ...
8
votes
2answers
750 views

Roll-a-ball controller

I've been toying around with Unity 5 lately, and in an effort to start making an actual game, I've built a ball controller similar to the one found in the Unity tutorial Roll-a-ball. In essence, the ...
8
votes
1answer
2k views

Loop through JSON and create prefab in Unity3D

I am creating an app in Unity3D and it is my first time coding in C#. I use the following code to parse a JSON file hosted on my server and use the information to render prefabs within my scene: <...
8
votes
1answer
256 views

Game involving a squirrel and falling projectiles

I did this game as part of a game jam and I was hoping I could get some pointers on how to improve my code. I feel like the code is sloppy but have no idea of the correct way to do something. Whilst ...
7
votes
3answers
417 views

Rock Paper Scissors coding challenge

I did a job application to a Unity developer position and i was given a coding challenge which was implementing a Rock Paper Scissors game or a variation of it. I have implemented the game using Unity ...
7
votes
3answers
423 views

Averaging quaternions

To compensate for shaky hands when holding a mobile device I'm averaging the rotation of the phone over the last n (in this case 16) frames, and setting the camera'...
7
votes
4answers
291 views

Call a method from all GameObjects implementing a specific interface in Unity

my player has a gun with 3 bullets. If he runs out of ammo the scene should reset itself. I don't want to load the scene again, some components should reset themselves by using an interface. So my ...
7
votes
2answers
165 views

Finding a gameObject on a screen

I'm working on a warning system for my game. I want to display an arrow on the screen where the object is going to be coming from. Here is an image of what I have in mind: The object will spawn from ...
7
votes
1answer
192 views

My game manager

This is my game manager script and is there anyway i can improve this code. ...
7
votes
1answer
124 views

Hotkey detection for UI elements

I have several UI elements that can be opened using hotkeys for example the settings menu's key is Escape. The problem is that I have the Keycode stored in ...
7
votes
3answers
1k views

“Dice on a Yacht” game

I wrote a small program to address some assignment tasks related to making a game called 'Dice on a Yacht'. I sent the code to be reviewed by a company I was applying for, and I have not gotten the ...
7
votes
1answer
802 views

Car controlled by steering wheel

I'm a young coder who is looking to improve in my coding practices because I was told by my supervisor to look into a more healthier method to code. What I would like to ask is how can I improve my ...
7
votes
1answer
243 views

HoloLens Unity program

I recently finished writing an HoloLens proof-of-concept program. It involves generating a user interface based on a connection with an OPC server. OPC involves industrial PLCs, one or more PLCs send ...
7
votes
0answers
136 views

Unity3D shader for rendering 2D sprites with a pseudo-glitch effect

I'm making a puzzle game in Unity with sprite-based graphics. When the game is paused, I want to hide most game elements, because I don't want the player to be able to pause and leisurely think about ...
6
votes
4answers
3k views

Rocket controller for a Unity game

I'm currently learning C# so I can make real games with Unity. This is the first C# program I've built in Unity. Essentially what is does is control the thrust, and rotation of a ...
6
votes
2answers
1k views

Type-Safe Event System

I have recently started writing C# from a strong JavaScript background, and found myself wanting to do something I do all the time in JavaScript: events. Since I have a type system at my disposal, I ...
6
votes
2answers
141 views

Sims-style walls part 2: Flood fill

A follow up to this post. I've ported all of it to Unity, and generally cleaned it up a little, but looking over the code, the code for flood filling is messy and repetitive. Here's a visual of how it ...
6
votes
2answers
239 views

Multiplayer Peer-To-Peer position interpolation

I have coded this movement interpolation for Unity3d using Photon. OnPhotonSerializeView gets called at the tickrate. Any kind of criticism/improvement suggestions are welcome. I tried to make the ...
6
votes
2answers
923 views

Ability System Implementation

I'm making an RPG in Unity with an ability-based combat system, think Guild Wars 2 or World of Warcraft. I'm implementing abilities in an inheritance tree structure which makes creating multiple ...
6
votes
2answers
3k views

C# to C++ function call that fills and auto resize array if size is not enough

I have a C# function that calls a C++ function to fill the array with pixel data from a camera. This is better than allocating memory on the C++ side and marshaling it on C# side each time the ...
6
votes
2answers
195 views

Do you want to be a super (voxel) hero?

I have implemented an upgrades system in my Unity3d game, and I am pretty sure that I am not doing things in an optimal way. Any advice regarding best practices would be much appreciated. The idea is ...
6
votes
1answer
1k views

Unity3D native iOS plug-in to read pedometer data

I've made a plug-in for Unity3d for iOS. The plug-in's job is to get the Pedometer data from history within a specified period of time and return that to Unity for later use. I am confident in my C# ...
6
votes
2answers
234 views

Simulating gravitational attraction between bodies - follow up

I've decided to revisit a chunk of code I wrote a while back, and see what I could do to make some changes. As a result, I know have slow, but working piece of code which is able to simulate ...
6
votes
2answers
297 views

Pulsing Alpha Channel

The following script makes an image pulse in Unity by fluctuating its alpha channel. However, I feel like there is a lot of duplicate code in the update method. How can I clean up that code to have ...
6
votes
1answer
265 views

Video Game AI State Change

I have here a snippet of code from a simple video game AI enemy. The basic idea behind the enemy is that he can be in one of a few states. By default he is in a patrolling state, where he moves ...
6
votes
2answers
6k views

Enemy patrol script using NavMeshAgent

I'm piecing together an Enemy script to attach to my characters. This is the portion that related the a game objects ability to patrol to given locations. Basically,...
6
votes
2answers
465 views

Rotating a character upside down and vice versa

I have a pretty straightforward task, but I find it hard to figure out how to improve it. The code is pretty straightforward, but rather bad. There are some clarifications / extra details at the ...
6
votes
1answer
9k views

TCP authentication server and client

This is the first time I'm dealing with C# as I'm accustomed to Java sockets, so I do want your full review and anything you think I can accomplish better or optimize in the code will be very ...
6
votes
1answer
1k views

Generating 3D voxel terrain with Perlin Noise

I've created this simple 3D voxel terrain generator using Perlin Noise. I have a few concerns about it though. Is there any way to make it more performant? It currently takes ~1.5 seconds to generate ...
6
votes
1answer
2k views

Tic-Tac-Toe AI in C# Unity

So I have a working game of Tic-Tac-Toe with an AI that plays random moves. Is anyway to maybe shorten the endturn() function so it's not so long? Also is this set up well enough to add a mode where ...
6
votes
1answer
85 views

Object creation pattern for component classes

I've been grappling with Unity's architecture for the last few days, trying to work around the fact that you can't use constructors for your MonoBehaviours (and by ...
6
votes
3answers
215 views

Improving Game EventSystem

There is a Unity EventManager class from Unity tutorial that allows events to be registered, unregistered and invoked. The bad side of that ...
6
votes
1answer
3k views

Sliding puzzle game of fifteen

I've made the Game of Fifteen in Unity this is how it looks : The code is rather short there's one class for the pieces and one for the game logic : MovablePiece : MonoBehaviour ...
5
votes
2answers
74 views

Method that renders all existing drawn lines on the view

I have several tabbed views with a Unity scene in them. What I do between scene is hide the elements in that scene, then render them if the right view is shown. The method below is the method that ...
5
votes
2answers
1k views

Calling a method to draw parallel lines

This question is a followup to the last one. I followed RobH's advice and his edge case bug found in my code with this solution: ...
5
votes
3answers
141 views

Determining vehicle jump landing quality

I am writing a game where a car drives and makes jumps. When a jump is landed, the player is rewarded if they land all four wheels either at the same time, or near to the same time. If they don't, ...
5
votes
2answers
3k views

Fastest way to find and replace inside a large amount of files

Currently I am looping through dependencies of objects, and I am trying to replace GUID (unity object ID's) inside the files. Right now I am using the following code, any suggestions for improvement ?...
5
votes
1answer
3k views

A* Algorithm in C# for pathfinding 2D tile grid

I am very new programming and am trying to develop a small tycoon game as a hobby project in Unity. This algorithm executes beautifully but if 100+ agents are getting new paths simultaneously there is ...
5
votes
1answer
322 views

Multiple functions to establish a fallback value for a property until not null

I have a property (called "Head") that can be set externally. When "Head" is not set, it uses Unity3D's MonoBehaviour functions to try to find the best value for "...
5
votes
2answers
168 views

Model-to-Prefab mapper and factory

I am creating a fluent interface to build user interfaces in the Unity game engine. As a subcomponent of this library, I have a set of objects called Components (e.g. Panel, Button, etc) that I want ...
5
votes
2answers
469 views

Visual boardgame

The visual board game is currently a game in unity, where I've created a map and a grid. The visualization is like this: Making this code obviously needed nested for loops and the like, but ...