I have some questions regarding Game Programming with Unity and I am very new to Game programming.
One of my questions: How do i program the "Game Logic" in Untiy? I am using Visual Studio with C#, Unity and Blender for Models. I assumed that i would have something like "main" method, where my complete Game starts and where i am loading animations/characters/maps etc. and also can include logic like when to show menus, cutscenes, intros, what would happen at what point of the game, etc.
But all i saw in tutorials is some .cs scripts which controls the animation of some GameObject. But how do i manage the complete Game logic (as stated above) with all that belongs to a full video game?
What am i missing?
And i assume that i will have something like a Database/Files, for saving save games, configurations, highscores, etc...how do i manage this?
Thanks!
Every Unity script can be run only if attached to game object. there is no main method because its already handled by Unity itself.
The approach you can have is like create a game object GameController which has script named GameController.cs
The GameController.cs
has method such as Awake, Start, Update
you can create your game rule, game logic, etc in that class.
Other script such as PlayerController.cs
that is attached on Player game object will access the GameController to put its score, and other things
In the PlayerController.cs
script you will have
GameController gameController = GameObject.findGameObjectWithTag("GameController");
gameController.score++
This is just example of the simple work flow
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With