public void UpdateState(MonsterViewModel viewModel) { if (follower == null) { follower = GetComponent <PathFollower>(); } if (attacher == null) { attacher = GetComponent <PrefabAttacher>(); attacher.AttachPrefab(); healthBar = attacher.GetInstance().GetComponent <Bar>(); healthBar.pointsImage = attacher. GetInstance(). transform.Find("Health"). GetComponent <Image>(); } healthBar.UpdateState(viewModel.Health, viewModel.MaxHealth); follower.movementSpeed = viewModel.Speed; if (viewModel.IsDead) { FlyingTextSpawner.SpawnGoldEarned(viewModel.KillReward, gameObject); Destroy(gameObject); } }
public void UpdateState(TowerViewModel viewModel) { if (viewModel.IsSold) { FlyingTextSpawner.SpawnGoldEarned(viewModel.SellPrice, gameObject); Destroy(gameObject); return; } if (ammoBar == null) { attacher = GetComponent <PrefabAttacher>(); attacher.AttachPrefab(); ammoBar = attacher.GetInstance().transform.Find("Ammunition Bar").GetComponent <Bar>(); ammoBar.pointsImage = attacher. GetInstance(). transform.Find("Ammunition Bar/Ammo"). GetComponent <Image>(); disabler = GetComponent <ObjectDisabler>(); GameObject buttons = ammoBar.gameObject.transform.parent.Find("Buttons").gameObject; disabler.toBeDisabled = buttons; disabler.Disable(); reloadButton = buttons.transform.Find("Reload").GetComponent <Button>(); sellButton = buttons.transform.Find("Sell").GetComponent <Button>(); reloadButton.onClick.AddListener(OnReload); sellButton.onClick.AddListener(OnSell); } range = viewModel.Range; ammoBar.UpdateState(viewModel.Ammo, viewModel.MaxAmmo); int ammoPercentage = (int)(viewModel.Ammo / viewModel.MaxAmmo * 100); if (ammoPercentage != lastAmmoPercentageShown) { lastAmmoPercentageShown = ammoPercentage; if (ammoPercentage < nextMilestone) { FlyingTextSpawner.SpawnAmmunitionLeft(ammoPercentage, gameObject); nextMilestone -= 100; } } if (viewModel.ReloadPrice != 0) { FlyingTextSpawner.SpawnGoldSpent(viewModel.ReloadPrice, gameObject); } }