//Initialize the Finite state machine for the NPC tank protected override void Initialize() { health = 100; elapsedTime = 0.0f; shootRate = 2.0f; curRotSpeed = 1.0f; curSpeed = 300.0f; //Get the target enemy(Player) GameObject objPlayer = GameObject.FindGameObjectWithTag("Player"); playerTransform = objPlayer.transform; if (!playerTransform) { print("Player doesn't exist.. Please add one with Tag named 'Player'"); } //Get the turret of the tank turret = gameObject.transform.GetChild(0).transform; bulletSpawnPoint = turret.GetChild(0).transform; int randomIndex = Random.Range(0, 2); AbstractFactory af; switch (randomIndex) { case 0: af = new DefenceEquipmentFactory(); break; case 1: af = new AttackEquipmentFactory(); break; case 2: af = new AgileEquipmentFactory(); break; default: af = new SimpleEquipmentFactory(); break; } Debug.LogWarning("randomIndex=" + randomIndex); initializeEquipment(af); curSpeed -= Armor.getWeight(); health += Armor.getDefence(); //Start Doing the Finite State Machine ConstructFSM(); }
void Start() { //Tank Settings rotSpeed = 150.0f; switch (tanktype) { case 0: initializeEquipment(new AgileEquipmentFactory()); break; case 1: initializeEquipment(new AttackEquipmentFactory()); break; case 2: initializeEquipment(new DefenceEquipmentFactory()); break; case 3: initializeEquipment(new SimpleEquipmentFactory()); break; } maxForwardSpeed -= Armor.getWeight(); health += Armor.getDefence(); HP.text = "HP:" + health.ToString(); }