/// <summary> /// Close 'New Skill Unlocked' panel, only when you drag the item into the skillbar. /// If you drag the item anywhere else, it will return to the panel, the panel will not close /// and will display the apropriate message to the user. /// </summary> public void ClosePanel() { if (Slot.childCount == 0 && Input.GetMouseButtonUp(0)) { defInstance = instance.GetComponent <DefensiveItems>(); GameObject[] skillBar = GameObject.FindGameObjectsWithTag("SkillBar"); GameObject itemParent = defInstance.transform.parent.gameObject; bool found = false; foreach (var item in skillBar) { if (itemParent.transform.parent.gameObject == item && itemParent.tag != "Parent") { anim.Play("NewSkillUnlockedPanelOut"); found = true; } } if (!found) { StartCoroutine(GUIManager._instance.ShowMessage("Drag the skill first to the skillbar.", 2)); } } }
void Update() { /*We set in the editor all the skill prefabs. If a skill get unlocked (matching its level with player's level), * the panel is shown with the skill's prefab in its slot */ foreach (var item in AllSkills) { var skill = item.GetComponent <DefensiveItems>(); if (GameManager._instance.player.Level >= skill.LevelRequired && skill.IsUnlocked == false && GameManager._instance.currentState == GameManager.GameState.PREPARATION) { OpenPanel(); instance = Instantiate(item, new Vector3(0, 0, 0), Quaternion.identity) as GameObject; instance.transform.SetParent(Slot, false); skill.IsUnlocked = true; // set it to true to avoid infinite instantiation SkillName.text = skill.Name; // Play sound SoundManager._instance.ItemUnlocked.Play(); defInstance = instance.GetComponent <DefensiveItems>(); } } if (Slot.childCount != 0) { ItemAttackValue.text = defInstance.ItemDamagePerSec.ToString(); ItemHealthValue.text = defInstance.MaximumHitPoints.ToString(); ItemDescription.text = defInstance.Description; } ClosePanel(); }
void Update() { defItem = GameObject.Find(gameObject.name).GetComponent <DefensiveItems>(); ShowAttackStats(); ShowHealthStats(); ShowItemInfo(); }
void OnTriggerStay2D(Collider2D item) { itemScript = item.gameObject.GetComponentInParent <DefensiveItems> (); if (item.gameObject.tag == "FloorCollider") { itemScript.Floor = this.gameObject; } }
public void PlaceItem(GameObject gameObject) { if (gameObject != null) { try { foreach (var slot in skillSlotsArray) { // If skill is drawn at mouse position, left click to spawn it at mouse position on a valid floor. if (slot.defensiveItem.drawOnMouse == true && Input.GetMouseButtonDown(0) && slot.defensiveItem.NumberAvailable > 0) { Vector2 mousePos; Vector3 targetPosition; // Get mouse position translated to wold cords mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); // Set the target position with round so it will be placed on floor tile targetPosition = new Vector3(Mathf.Round(mousePos.x), Mathf.Round(mousePos.y), -4); // Instantiate prefab DefensiveItems instaPref = (DefensiveItems)Instantiate(slot.defensiveItem, targetPosition, Quaternion.identity); // Play sound SoundManager._instance.ItemPlaced.Play(); // Copy values to instance instaPref.ItemDamagePerSec = slot.defensiveItem.ItemDamagePerSec; instaPref.InitialBonusDamage = slot.defensiveItem.InitialBonusDamage; instaPref.MaximumHitPoints = slot.defensiveItem.MaximumHitPoints; instaPref.CurrentHitPoints = instaPref.MaximumHitPoints; // Get Rect transform so we can reset its width and height - defined by grid layout. Otherwise healthbar won't be visible RectTransform rt = instaPref.GetComponent <RectTransform>(); rt.sizeDelta = new Vector2(0, 0); // Instantly, set the INSTANTIATED object's drawOnMouse to false, else we will forever have its image drawn at cursor pos instaPref.drawOnMouse = false; // Decrease the amount avaiable of the Defensive Item that was used slot.defensiveItem.NumberAvailable -= 1; // Change the floor pref tag so we cannot place any other object on top gameObject.tag = "FloorOccupied"; } } } catch (Exception e) { Debug.Log(e.Message); } } }
// Aply Damage void OnTriggerStay2D(Collider2D item) { creature = gameObject.GetComponentInParent <ICreature> (); defItem = item.gameObject.GetComponentInParent <DefensiveItems> (); if (item.gameObject.tag == "Health") { float calc_health = defItem.CurrentHitPoints / defItem.MaximumHitPoints; defItem.CurrentHitPoints -= creature.CreatureDamage * Time.smoothDeltaTime; defItem.Healthbar.transform.localScale = new Vector3(calc_health, 1, 1); } }
// Use this for initialization void Start() { defItem = GetComponentInParent <DefensiveItems>(); InfoText.SetActive(false); }