Moving from Java to Unity

Hello everyone,
I’ve been a Java developer for a few years now and I recently got involved in a game development project using Unity. I’ve messed around in Unity in the past, but never attempted a full game.

My question is how do you make a full game in Unity? I can’t figure out where to store variables such as player stats and such. In Java I would just put all of them in the main class, but in Unity you can only add scripts to objects. Is there a way to make a script that runs without being attached to something and controls everything?
Any tips for moving from a programming language to a scripting engine are appreciated!

Thanks everyone for your help!

i am a java programmer like you (but not advanced,maybe intermediate but i am not sure ) after going through
the first three projects in the learning site (roll ball,space shooter,nightmare) i think you should create an empty game object (call it main maybe that will help :))and attach a script to it that manage the game(what happen when the game start ,end ,background music, spawn enemies ,etc) and i think you cannot have an independent script . i hope that this will help and i recommend going through the projects in the learning site .(note:i am still a beginner in unity but that what i have
learned from the projects , i am sorry if something was wrong:).

Hey,

You could make an empty game object and attach your script to it, but I would say try to do it the “common” way.

Meaning, create a player, attach a script to it and inside that script declare his lifepoints and stuff. Then, make an enemy, attach a script to it containing his lifepoints etc. Then you could do a script for a weapon containing the damage and stuff.
In Unity it is more component based.

Playerstats or something like the amount of players/enemys I would put, as suggested above, in an empty gameobject (call it GameManager or something) and then let all the other objects get their information from the GameManager object.

Hope that helped?

You can write all your game code in a single script attached to an empty Gameobject in the scene, and treat the Start() function in that as your main entry point. However, doing so would be fighting against the “Unity way” of doing things, rather than embracing it.

If you’re a competent programmer, I recommend downloading one of the Unity sample projects from the asset store and dissecting the “correct” way of doing things…

For beginners I recommend to take a look at http://www.it-ebooks.org/tag/unity You have many free ebooks about Unity. Here you can learn the basics(workspace,syntax etc.)