private GameObject GetFreeTextObject() { foreach (var o in _textPool) { //Return first inactive object in pool if (!o.activeSelf) { o.SetActive(true); var routine = DeactivateAfterTime(.5f, o); Script_GameManager.GetInstance().StartCoroutine(routine); return(o); } } //If no objects available, create new one and add to pool var obj = GameObject.Instantiate(_textPrefab); _textPool.Add(obj); obj.transform.SetParent(_poolHolder.transform); //Deactivate text after a time var coroutine = DeactivateAfterTime(.5f, obj); Script_GameManager.GetInstance().StartCoroutine(coroutine); return(obj); }
public override void Refresh() { foreach (Transform child in _equipedGrid) { Destroy(child.gameObject); } foreach (Transform child in _inventoryGrid) { Destroy(child.gameObject); } foreach (var item in Script_GameManager.GetInstance().Inventory.GetEquipedItems()) { var obj = Instantiate(_inventoryImagePrefab); obj.SetItem(item); obj.VisualType = Script_VisualItemUI.VisualItemType.Inventory; obj.transform.SetParent(_equipedGrid); } foreach (var item in Script_GameManager.GetInstance().Inventory.GetUnEquipedItems()) { var obj = Instantiate(_inventoryImagePrefab); obj.SetItem(item); obj.VisualType = Script_VisualItemUI.VisualItemType.Inventory; obj.transform.SetParent(_inventoryGrid); } _currencyText.text = Script_GameManager.GetInstance().Inventory.Currency + " G"; }
public bool BuyItem(Script_Item item) { var entry = ShopEntries.Find(x => x.Item == item); var inventory = Script_GameManager.GetInstance().Inventory; if (entry.Item != null && inventory.Currency >= entry.Price) { //Remove item from shop --entry.Item.Amount; if (entry.Item.Amount <= 0) { ShopEntries.Remove(entry); } //Adjust currency inventory.Currency -= entry.Price; //Move item to inventory inventory.AddItem(entry.Item); //Refresh shop panel Script_GameManager.GetInstance().UIManager.ShopPanel.Refresh(); //Refresh inventory if open if (Script_GameManager.GetInstance().UIManager.InventoryPanel.IsActive()) { Script_GameManager.GetInstance().UIManager.InventoryPanel.Refresh(); } return(true); } return(false); }
//Object that finishes game when object is in trigger public void OnTriggerEnter(Collider other) { if (other.tag == "Player") { Script_GameManager.GetInstance().CompleteGame(true); } }
public void UnEquip(Script_Item item) { if (item != null && item.Equiped) { item.Equiped = false; if (item == Weapon) { Weapon = null; } if (item == Helm) { Helm = null; } if (item == Chest) { Chest = null; } if (item == Legs) { Legs = null; } //Switch inventory image from equiped to unequiped Script_GameManager.GetInstance().UIManager.InventoryPanel.SwitchItemInventoryList(item.UIItem); } }
private void ShopClick() { //Buy item if possible if (Script_GameManager.GetInstance().UIManager.ShopPanel.AttachedKeeper.BuyItem(_attachedItem)) { ItemNameDisplay.SetActive(false); } }
private void Update() { //If player is close and presses e, open shop panel if (_playerInRange && Input.GetKeyDown(KeyCode.E)) { Script_GameManager.GetInstance().UIManager.ShopPanel.SetShopKeeper(this); Script_GameManager.GetInstance().UIManager.ShopPanel.SwitchState(); } }
public void ShowGameComplete(bool win) { var endScreen = GameObject.Instantiate(Resources.Load <GameObject>("Prefabs/UI/GameCompleteScreen")); endScreen.transform.GetChild(0).GetComponent <Text>().text = win ? "Game Completed" : "Game Over"; endScreen.transform.GetChild(1).GetComponent <Button>().onClick.AddListener(Script_GameManager.GetInstance().ResetScene); endScreen.transform.SetParent(Canvas.transform); endScreen.transform.SetAsLastSibling(); endScreen.transform.localPosition = Vector3.zero; }
public void Start() { if (ItemNameDisplay == null) { ItemNameDisplay = Instantiate(Resources.Load <GameObject>("Prefabs/UI/ItemNameDisplay")); } ItemNameDisplay.transform.SetParent(Script_GameManager.GetInstance().UIManager.Canvas.transform); _itemDisplayText = ItemNameDisplay.transform.GetChild(1).GetComponent <Text>(); ItemNameDisplay.SetActive(false); }
public void Show() { if (!_active) { ++Script_GameManager.GetInstance().UIManager.ActivePanels; Time.timeScale = 0f; } gameObject.SetActive(true); transform.SetAsLastSibling(); Refresh(); _active = true; }
public int GetAttackDamage() { if (_attachedCharacter.CharType == Script_Character.CharacterType.Dog) { return(_attachedCharacter.Attack); } int equipedBoost = 0; Script_GameManager.GetInstance().Inventory.GetEquipedItems().ForEach(x => equipedBoost += x.AttackBoost); return((int)(equipedBoost * GetCurrentChargePercentage()) + _attachedCharacter.Attack); }
public virtual void Hide() { if (_active) { --Script_GameManager.GetInstance().UIManager.ActivePanels; if (Script_GameManager.GetInstance().UIManager.ActivePanels == 0 && !Script_GameManager.GetInstance().GameOver) { Time.timeScale = 1f; } } gameObject.SetActive(false); _active = false; }
public void Destruct(Script_Weapon sendWeapon) { if (sendWeapon == null) { return; } //Destroy object if hit by correct type of weapon if (sendWeapon.WeapType == TypeToDestroy || TypeToDestroy == Script_Weapon.WeaponType.None) { Destroy(gameObject); Script_GameManager.GetInstance().Inventory.Currency += _currencyReward; } }
void Attack() { //Left mouse button pressed if (Input.GetMouseButtonDown(0) && Script_GameManager.GetInstance().UIManager.ActivePanels == 0) { //Attack with weapon if you have one if (_attachedCharacter.Weapon != null) { //Check what was hit by weapon var hit = _attachedCharacter.Weapon.GetHitObjects(this); foreach (var o in hit) { //Deal damage to hit enemies if (o.tag == "Enemy") { var es = o.GetComponent <Script_EnemyBehaviour>(); if (es != null) { es.GetAttachedCharacter().TakeDamage(GetAttackDamage()); } } //Destruct destructables if (o.tag == "Destructable") { var ds = o.GetComponent <Script_Destructable>(); if (ds != null) { ds.Destruct(_attachedCharacter.Weapon); } } } } //Hit enemy right in front with "fist" else { RaycastHit hit; if (Physics.Raycast(transform.position, transform.forward, out hit, 2f, ~(1 << LayerMask.NameToLayer("Player")))) { if (hit.collider.tag == "Enemy") { hit.collider.GetComponent <Script_EnemyBehaviour>().GetAttachedCharacter().TakeDamage(GetAttackDamage()); } } } _currentChargeTimer = 0f; } }
public void OnPointerEnter(PointerEventData eventData) { //Change item display to use this object name ItemNameDisplay.SetActive(true); _itemDisplayText.text = (_attachedItem != null ? _attachedItem.Name : "Dummy") + (_attachedItem.Amount > 1 ? " x" + _attachedItem.Amount : ""); //Add price at end of text if shop item if (VisualType == VisualItemType.Shop) { _itemDisplayText.text += " " + Script_GameManager.GetInstance().UIManager.ShopPanel.AttachedKeeper.ShopEntries .First(x => x.Item == _attachedItem).Price + "G"; } //Put display in front ItemNameDisplay.transform.SetAsLastSibling(); }
public override void Use() { bool canBeUsed = false; foreach (var character in Script_GameManager.GetInstance().CharacterManager.GetCharacters()) { if (character.CurrentHealth < character.MaxHealth) { character.Heal(_healAmount); canBeUsed = true; } } if (canBeUsed) { Script_GameManager.GetInstance().Inventory.RemoveItem(this); } }
public void RemoveItem(Script_Item item, int amount = 1) { //Find inventory slot of item type var inventoryItem = _itemList.First(x => x.Name == item.Name); if (inventoryItem != null) { //Remove amount of items inventoryItem.Amount -= amount; //Delete item type from inventory if none are left if (inventoryItem.Amount <= 0) { _itemList.Remove(inventoryItem); Script_GameManager.GetInstance().UIManager.InventoryPanel.Refresh(); } } }
// Use this for initialization void Start() { var uip1 = transform.GetChild(0); _playerUI1 = new PlayerUI { HealthText = uip1.transform.GetChild(0).GetComponent <Text>(), ChargeText = uip1.transform.GetChild(2).GetComponent <Text>(), TrackCharacter = Script_GameManager.GetInstance().CharacterManager.GetCharacters()[0].GetVisualCharacter() }; var uip2 = transform.GetChild(1); _playerUI2 = new PlayerUI { HealthText = uip2.transform.GetChild(0).GetComponent <Text>(), ChargeText = uip2.transform.GetChild(2).GetComponent <Text>(), TrackCharacter = Script_GameManager.GetInstance().CharacterManager.GetCharacters()[1].GetVisualCharacter() }; }
public void EquipItem(Script_Item item) { if (item.Type == Script_Item.ItemType.Weapon) { //Unequip current weapon if in same slot UnEquip(Weapon); //Equip new weapon Weapon = item as Script_Weapon; Weapon.Equiped = true; } else if (item.Type == Script_Item.ItemType.Armor) { //Unequip armor of same type and equip new one var armor = item as Script_Armor; switch (armor.GearType) { case Script_Armor.ArmorType.Chest: UnEquip(Chest); Chest = armor; Chest.Equiped = true; break; case Script_Armor.ArmorType.Legs: UnEquip(Legs); Legs = armor; Legs.Equiped = true; break; case Script_Armor.ArmorType.Helm: UnEquip(Helm); Helm = armor; Helm.Equiped = true; break; default: throw new ArgumentOutOfRangeException(); } } //Switch inventory image from unequiped to equiped Script_GameManager.GetInstance().UIManager.InventoryPanel.SwitchItemInventoryList(item.UIItem); }
private void OnTriggerEnter(Collider other) { if (other.tag != "Player") { return; } switch (_type) { case PickupType.Key: Script_GameManager.GetInstance().Inventory.AddItem(new Script_Key()); break; default: throw new ArgumentOutOfRangeException(); } Destroy(gameObject); }
public void TakeDamage(int number) { //Get defense boost var equipedBoost = 0; Script_GameManager.GetInstance().Inventory.GetEquipedItems().ForEach(x => equipedBoost += x.DefenseBoost); //Take adjusted damage var damage = Math.Max(0, number - (Defense + equipedBoost)); CurrentHealth -= damage; //Die if (CurrentHealth <= 0) { CurrentHealth = 0; Die(); } //Show combat text Script_GameManager.GetInstance().CombatTextManager.AddText(damage.ToString(), _visualCharacter.transform.position + 2 * Vector3.up); }
private void OnTriggerEnter(Collider other) { if (other.tag != "Player") { return; } //Show text transform.GetChild(0).gameObject.SetActive(true); //Check if item is in inventory var item = Script_GameManager.GetInstance().Inventory.GetUnEquipedItems().FirstOrDefault(x => x.Name == ItemName); if (item != null) { //Destroy object and remove required item from inventory Destroy(gameObject); Script_GameManager.GetInstance().Inventory.RemoveItem(item); } }
public override void Refresh() { foreach (Transform child in _shopGrid) { Destroy(child.gameObject); } if (AttachedKeeper == null) { return; } foreach (var entry in AttachedKeeper.ShopEntries) { var obj = Instantiate(_itemImagePrefab); obj.SetItem(entry.Item); obj.VisualType = Script_VisualItemUI.VisualItemType.Shop; obj.transform.SetParent(_shopGrid); } _currencyText.text = Script_GameManager.GetInstance().Inventory.Currency + " G"; }
public override void Refresh() { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("Name: "); stringBuilder.Append(_character.Name); stringBuilder.Append("\n"); stringBuilder.Append("Weapon: "); stringBuilder.Append(_character.Weapon != null ? _character.Weapon.Name : "/"); stringBuilder.Append("\n"); stringBuilder.Append("Health: "); stringBuilder.Append(_character.MaxHealth); stringBuilder.Append("\n"); stringBuilder.Append("Attack: "); stringBuilder.Append(_character.Attack); stringBuilder.Append("\n"); stringBuilder.Append("Defense: "); stringBuilder.Append(_character.Defense); stringBuilder.Append("\n"); _baseText.text = stringBuilder.ToString(); //Item Boost Text stringBuilder.Length = 0; stringBuilder.Append("Attack: "); stringBuilder.Append(Script_GameManager.GetInstance().Inventory.GetTotalAttackBoost()); stringBuilder.Append("\n"); stringBuilder.Append("Defense: "); stringBuilder.Append(Script_GameManager.GetInstance().Inventory.GetTotalDefenseBoost()); stringBuilder.Append("\n"); _itemBoostText.text = stringBuilder.ToString(); }
private void InventoryClick() { //Consume item if (_attachedItem.Type == Script_Item.ItemType.Consumable) { (_attachedItem as Script_Consumable).Use(); _itemDisplayText.text = (_attachedItem != null ? _attachedItem.Name : "Dummy") + (_attachedItem.Amount > 1 ? " x" + _attachedItem.Amount : ""); } //Equip / Unequip item else { if (!_attachedItem.Equiped) { Script_GameManager.GetInstance().CharacterManager.GetCharacters()[0].EquipItem(_attachedItem); } else { Script_GameManager.GetInstance().CharacterManager.GetCharacters()[0].UnEquip(_attachedItem); } //Update equiped stats for if characterwindow would be open Script_GameManager.GetInstance().UIManager.CharacterPanel.Refresh(); } }
void Update() { //Follow selected character when in followrange var selectedChar = Script_GameManager.GetInstance().CharacterManager.GetSelectedCharacter().GetVisualCharacter(); if ((selectedChar.transform.position - transform.position).sqrMagnitude <= _followPlayerRange * _followPlayerRange) { _navAgent.destination = selectedChar.transform.position; } //Stand still if not in range else { _navAgent.destination = transform.position; } _attackTimer += Time.deltaTime; //Attack if (_attackTimer >= _attackInterval) { //Get characters in cone of vision foreach (var c in Script_GameManager.GetInstance().CharacterManager.GetCharacters()) { var between = c.GetVisualCharacter().transform.position - transform.position; var angle = Vector3.Angle(transform.forward, between); if (angle <= _viewAngle / 2f && between.sqrMagnitude <= _baseAttackRange * _baseAttackRange) { //Hit player c.TakeDamage(_attachedCharacter.Attack); _attackTimer = 0f; break; //Only can damage one character each attack } } } }
protected override void Die() { Script_GameManager.GetInstance().CompleteGame(false); }
protected override void Die() { GameObject.Destroy(_visualCharacter.gameObject); Script_GameManager.GetInstance().Inventory.Currency += 50; }
public override void Initialise() { _character = Script_GameManager.GetInstance().CharacterManager.GetCharacters()[0]; _baseText = transform.GetChild(0).GetComponent <Text>(); _itemBoostText = transform.GetChild(1).GetComponent <Text>(); }