Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Assossa · Aug 14, 2015 at 04:08 PM · c#unity 5game

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!

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image RLin · Aug 14, 2015 at 04:15 PM 0
Share

What's wrong with attaching it to an object? You can use playerPrefs to save the values of variables, and have an object that contains the script.

avatar image SuperRaed · Aug 14, 2015 at 04:53 PM 0
Share

how about attaching it to the main Camera? or an empty game object that's always going to be in the scene?

avatar image Owen-Reynolds · Aug 14, 2015 at 05:12 PM 0
Share

UA works better if the title of our question is a question. Thinking of a good question-y title can also help give ideas where to Search.

This is a pretty common Q.

Try a Search on "unity game manager." Can also try "unity singleton" (obviously, from the java-trained, since only they use Design Patterns.) Generally it's any script on an empty with dontDestroyOnLoad. Others use a class with all statics.

4 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by whaleinthesea · Aug 14, 2015 at 08:56 PM

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.)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by fares90 · Aug 14, 2015 at 05:08 PM

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:).

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by TotalAnnihilation · Aug 14, 2015 at 05:07 PM

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?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by tanoshimi · Aug 14, 2015 at 05:13 PM

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....

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Attacking Enemies at an Angle 0 Answers

Multiple Cars not working 1 Answer

Unity 5 - Adding a Pre-made Countdown Timer C# Script to the Game Scene as a Text UI Element 1 Answer

Firing projectiles on the XZ Plane 2 Answers

Distribute terrain in zones 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges