Game Development Reference
In-Depth Information
21 //Add enemy to Game State
22 GameManager.StateManager.GameState.Enemies.Add(ThisEnemy);
23 }
24 //------------------------------------------------
25 //Function called when loading is complete
26 public void LoadGameComplete(Component Sender)
27 {
28 //Cycle through enemies and find matching ID
29 List<LoadSaveManager.GameStateData.DataEnemy> Enemies =
GameManager.StateManager.GameState.Enemies;
30
31 //Reference to this enemy
32 LoadSaveManager.GameStateData.DataEnemy ThisEnemy = null;
33
34 for(int i=0; i<Enemies.Count; i++)
35 {
36 if(Enemies[i].EnemyID == EnemyID)
37 {
38 //Found enemy. Now break break from loop
39 ThisEnemy = Enemies[i];
40 break;
41 }
42 }
43
44 //If we reach here and no enemy is found, then it was destroyed when saved.
So destroy now
45 if(ThisEnemy==null){DestroyImmediate(gameObject);return;}
46
47 //Else load enemy data
48 EnemyID = ThisEnemy.EnemyID;
49 Health = ThisEnemy.Health;
50
51 //Set position
52 Agent.Warp(new Vector3(ThisEnemy.PosRotScale.X, ThisEnemy.PosRotScale.Y,
ThisEnemy.PosRotScale.Z));
53
54 //Set rotation
55 ThisTransform.localRotation = Quaternion.Euler(ThisEnemy.PosRotScale.RotX,
ThisEnemy.PosRotScale.RotY, ThisEnemy.PosRotScale.RotZ);
56
57 //Set scale
58 ThisTransform.localScale = new Vector3(ThisEnemy.PosRotScale.ScaleX,
ThisEnemy.PosRotScale.ScaleY, ThisEnemy.PosRotScale.ScaleZ);
59 }
60 //------------------------------------------------
Lines 03-22. As with the Player class, the Enemy class fills in the required Enemy
data, and then uses the List.Add function to add the Enemy data into the
GameStateData class as a serializable object.
Search WWH ::




Custom Search