Facebook
From Walloping Parakeet, 4 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 150
  1. using UnityEngine;
  2.  
  3. public class BuildManager : MonoBehaviour
  4. {
  5.     public static BuildManager instance;
  6.  
  7.     void Awake ()
  8.     {
  9.         if (instance != null)
  10.         {
  11.             Debug.Log("More than one BuildManager in scene!");
  12.             return;
  13.         }
  14.         instance = this;
  15.     }
  16.  
  17.     public GameObject MG1TurretPrefab;
  18.     public GameObject MissleLauncherPrefab;
  19.    
  20.     private TurretBlueprint turretToBuild;
  21.  
  22.     public bool CanBuild { get { return turretToBuild != null; } }
  23.     public bool HasMoney { get { return PlayerStats.Money >= turretToBuild.cost; } }
  24.  
  25.     public void BuildTurretOn (Node node)
  26.     {
  27.         if (PlayerStats.Money < turretToBuild.cost)
  28.         {
  29.             Debug.Log("Not enough money to build that!");
  30.             return;
  31.         }
  32.  
  33.         PlayerStats.Money -= turretToBuild.cost;
  34.  
  35.         GameObject turret = (GameObject)Instantiate(turretToBuild.prefab, node.GetBuildPosition(), Quaternion.identity);
  36.         node.turret = turret;
  37.  
  38.         Debug.Log("Turret build! Money left: " + PlayerStats.Money);
  39.     }
  40.  
  41.     public void SelectTurretToBuild (TurretBlueprint turret)
  42.     {
  43.         turretToBuild = turret;
  44.     }
  45.  
  46.  
  47. }