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.
15
votes
3answers
484 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
7k 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.
...
10
votes
1answer
2k 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 <...
8
votes
2answers
279 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
318 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
236 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
1k 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
2answers
201 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 ...
7
votes
2answers
153 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
126 views
7
votes
3answers
527 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
108 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
1answer
84 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
...
6
votes
4answers
935 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
335 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
119 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
1answer
531 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
1answer
128 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
243 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
4k 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
248 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
860 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
414 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 ...
5
votes
2answers
71 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
527 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
131 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
1answer
175 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
352 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 ...
5
votes
1answer
240 views
Random interval generator for a game
I have been working on a few games which all have a need to create "events" randomly over time. The intervals need to get shorter as time goes on if the event is negative or they need to get longer ...
5
votes
1answer
55 views
Simon says in Unity
I've made the Simon says game in Unity
You start by guessing a pattern of 3 colors and each time you complete the pattern a new, random one, is generated and the length of the pattern is incremented ...
5
votes
1answer
142 views
Long Player movement script
All of this does just one thing. Move my player by finding the first finger that was used to touch the ship and drag it.
I have a few questions:
The first thing is I have an embedded class of ...
4
votes
2answers
581 views
Checking for duplicate materials
This is a follow up question of Importing different type of files into Lists. Where the original lists are acquired.
In this script I am processing the obtained lists, and comparing them with each ...
4
votes
3answers
503 views
Simple Q&A game
I just wanted to get some criticism on my programming to make me better. I made a game in Unity, just a simple question and answer game.
Demo
...
4
votes
2answers
265 views
Importing different type of files into Lists
I am using a recursive directory scan to find all objects inside a Unity3D project. After that, I wish to move all these files to a sorted List. Is there a cleaner ...
4
votes
2answers
96 views
Player Rotation script
This is my player rotation script. I just want to make sure my naming conventions are right. If there is any way to make this code more readable I'm open to suggestions. This is also my 3rd post about ...
4
votes
3answers
154 views
Generating Heighway dragons in Unity C#
I'm basically looking for a general critique. I'm just starting out and would like to know if I should have done anything differently to make it faster or to make it much more readable. I don't know ...
4
votes
2answers
658 views
Dynamic Storing Objects from XML in RPG
I would prefer if more experienced users could give pointers on how I can optimize and think better when writing code.
If you are unfamiliar with unity3d, ignore the use of UnityEngine, the heritage ...
4
votes
3answers
212 views
Facebook helper class
This is my initial Facebook helper class. Is this code efficient or is there a way to improve this code?
...
4
votes
2answers
292 views
Triggered movement script for triggered objects
I am trying to more or less perfect a movement script that activates when "triggered" by another object. Below I have the code for both the triggering object as well as the object being triggered.
I ...
4
votes
2answers
276 views
Voxel Islands - Dynamic mesh generation
While I can often understand the performance reasons behind using fixed-size arrays to store vertex, triangle and UV data, I've often found it annoying because it makes dynamically generating meshes ...
4
votes
1answer
357 views
Object pooling for a top down shooting game
I have an Asteroids clone I'm working on and I want to see if my object pooling is written correctly. The code works I just want to know if there is anything else I need to change to make it more ...
4
votes
1answer
237 views
Creating a masonry effect with varying height rectangles
The following is used to create a masonry effect with varying height rectangles. How can I simplify and make this more elegant in Unity?
...
4
votes
2answers
149 views
Spell and cooldown system for an Unity game
So I have doubts about my code and if it is any good. I have a parent class Spell:
...
4
votes
1answer
75 views
Snake game in Unity
I've made a simple snake game in Unity and it has 3 different types of foods.
Note - 5 blocks = 1 point
This is a screenshot from the game here I'm colliding with myself and the game is restarted ...
4
votes
1answer
106 views
Sequentially displaying a list of game objects
A chat background is created and text[0] is displayed with a button created under it. The created button iterates thru text[] ...
4
votes
1answer
97 views
How to separate data from logic when serializing types - grid tile map example
I am creating a tile based game in Unity and ran into a problem with my architecture of the Map and Tile types. The tile class contains logic like events when the tile type changes. When I tried to ...
4
votes
2answers
95 views
Calculating which direction my enemy should face when moving
I have just implemented an algorithm which calculates the direction an enemy in my game should face when moving to a location.
This is a 2D game where characters can face in one of four directions: (...
4
votes
1answer
241 views
Water generating waves and reflection
For the last few days I have been working on wave generation script. As there are a lot of calculations involved I was looking for possible optimizations to improve the performance of the code.
This ...
4
votes
1answer
93 views
Method for obtaining adjacent chunk positions
I'm currently in the process of making a 2D tile based game. This game has an "infinite" world that can be traversed and modified as needed. I am creating the chunks with a mesh and I apply a texture ...
4
votes
1answer
82 views
A* Algorithm speed improvement
Currently I have a very general purpose A* algorithm, which I've submitted as open sourced at https://github.com/kd7uiy/AStar . I've been trying to speed it up for the last month or so, and while I'm ...