Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Game Logic Programming in Unity

Tags:

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!

like image 859
Sebastian Avatar asked Mar 22 '17 22:03

Sebastian


1 Answers

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

like image 182
Kelvin Chandra Avatar answered Sep 24 '22 10:09

Kelvin Chandra