Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'd like to write a game completely in C#. In my search for an engine, I found Unity3D, but all the tutorials and documentation are speaking about a visual editor and the Unity IDE in which you click and point around to create scenes and scripts.

I don't want to do that. I prefer full code coverage over designers abstracting things away from me. I'd like to only write pure C# code from scratch or if required the Unity scripts as an addition. I couldn't find any explanation or documentation about doing so; how can I build a game using Unity and making minimum (or no) use of the visual editor?

share|improve this question
    
Voting to close, this is a framework recommendation disguised as a question about Unity. –  BlueRaja - Danny Pflughoeft Aug 10 at 18:14
    
I'm not actually sure if I agree with that, though I wouldn't overturn a community close vote. However, I will note that this question is specifically asking about some capability of Unity: answers that don't address that may be removed. Let's not turn this into an off topic question if we don't have to, okay? –  Josh Petrie Aug 10 at 18:37
    
@BlueRaja-DannyPflughoeft yeah maybe the last sentence throws this discussion into the wrong direction, primarily i'd like to know if pure code is possible in Unity –  DebugErr Aug 10 at 19:32
2  
Most developers look for a visual editor at some point to design their levels, because visually positioning stuff is so much simpler than setting the position of every little doodad in code. Same goes for editing/designing GUI layouts. Having this stuff already built-in is a huge benefit IMHO. –  bummzack Aug 11 at 7:01
3  
I prefer writing my own level editor which provides only the stuff really neccessary for my game okay that basically means you don't want to be using a game engine, you want to be programming with a graphics library. However you already hit a technical snag when trying to do that, so... I sense a contradiction here. –  jhocking Aug 11 at 13:19

3 Answers 3

up vote 5 down vote accepted

I am a complete beginner in Unity, but this is how I do it at the moment, and it reduces the editor usage to minimum:

In editor, I only have three objects: An empty GameObject called "main", a camera, and a light. And this is only because so far I only work with a single camera and a single light, so it was faster this way. Later I will probably remove them, and only the "main" will remain.

In "Assets/MyScripts" I have a class "Main", which is added to the "main" GameObject as a behavior. Which means that when the program starts, the "Main" class in instantiated and its method is called. The "Main" class is like this:

using UnityEngine;

public class Main : MonoBehaviour
{

    void Start ()
    {
        // initialize the game
    }

    void Update ()
    {
        // update physics
    }

}

In the game I dynamically build the environment like this:

GameObject floor = GameObject.CreatePrimitive (PrimitiveType.Cube);
floor.renderer.material.color = RandomGreen ();

But this is because so far I am only making a prototype. Later I will want to replace the cubes with some nice things edited in Blender. Which will require making them in Blender, and importing them to Units as "prefabs". Then, I will similarly instantiate the "prefabs" from the C# code.

If you want to make an object react to events, such as collisions with other objects, you can instantiate the object and add them dynamically a behavior class, which is a C# class derived from MonoBehavior. For example, if you want to have a car, you make a car prefab, and write a "CarBehavior" class for its behavior in the game.

This way you can reduce the interaction with the editor to a minimum, although probably not completely to zero. Now it depends on whether this is an acceptable solution for you.

share|improve this answer
2  
I'd say this looks like a pretty clear and solid answer for just a Unity beginner :) –  DebugErr Aug 11 at 14:31
    
Thanks! I am an experienced programmer otherwise, but this is my first project in Unity and it is far from finished. I haven't used prefabs yet. There may be some complications I am currently not aware of, so I recommend taking my advice with a grain of salt. By the way, serialization in Unity feels a bit counter-intuitive to me. I will have to study it deeper, and it may influence some design decisions. –  Viliam Búr Aug 13 at 9:43

When working with Unity you have to do some work within Unity's editor; that's simply how Unity works.

However the vast majority of what you'd be doing as a programmer doesn't happen within Unity's editor; the script files are external text files written in an external IDE, and as a programmer you only use Unity's editor for linking which scripts to run and then hitting Play to actually run the game. That's not unlike linking in classes in the project settings, and then hitting Run within your IDE.

Most other game development tools that have a central visual editor are also saddled with limited and inflexible scripting support, but Unity doesn't suffer that disadvantage. Although everything created for Unity ultimately goes through the visual editor, this core interface involves a lot of linking projects to custom code that runs in Unity's game engine. Experienced programmers, don't dismiss this development environment, mistaking it for some click together game creator with limited programming capability!

(also, it sounds like the book I'm currently writing would be a great resource for you, since it's targeted at experienced programmers)

share|improve this answer

I believe what you are looking for is the Futile Framework for Unity.

Basically, you can then do all your programming using scripts without having to "drag and drop" stuff or mess with the visual editor much. All you need is a single GameObject in your Scene which will be the container for your entire game. You then do everything procedurally as you would with a non-visual editor.

Disclaimer: While Futile is very code centric, it is inevitable that you will have to mess with the Unity editor in some fashion. But this is very much reduced with Futile.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.