My advice would be to not make every thing a game object with a monobehavior derived class. When I first used Unity, everything I created was a C# script created from the Unity ui and I never created classes that weren't derived from monobehavior. But since it's C# you can create regular classes / struct and pass them to functions instead of creating GameObjects everywhere. I don't know if it's a good thing to do in Unity and it has been a few years since I used Unity.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 | public struct game_state_t {
public player_t p1, p2;
public board_t board;
... // Only data in here, no functions.
}
public static class game_t {
// Here are game logic functions...
public static void update( ref game_state_t state ) {
...
}
}
// This is the starting point of the game, it needs to be attached to a game object.
// And it probably needs to persist across level change.
public class main_t : MonoBehaviour {
game_state_t state;
void Start( ) {
state = new game_state_t( );
}
void Update( ) {
game_t.update( ref state );
}
}
|