void Update()
        {
            // IF there isn't a player active on the scene.
            if (playerManager == null)
            {
                // Get the Player GameObject.
                playerManager = Character_Manager.GetPlayerManager();
                return;
            }
            // IF the equipment component isn't set yet
            if (equipment == null)
            {
                // Get the Equipment script that is on the player GameObject.
                equipment = playerManager.GetComponentInChildren <Equipment> ();
                return;
            }

            // Create a variable to hold the item.
            Item equip = null;

            // IF we have a weapon image we want to update,
            // ELSE IF we have a armour image we want to update,
            // ELSE IF we have a bracelet image we want to update,
            // ELSE IF we have a ring image we want to update.
            if (itemSlot == "Weapon")
            {
                // Get the weapon from the Equipment script.
                equip = equipment.GetWeapon();
            }
            else if (itemSlot == "Armour")
            {
                // Get the armour from the Equipment script.
                equip = equipment.GetArmour();
            }
            else if (itemSlot == "Bracelet")
            {
                // Get the bracelet from the Equipment script.
                equip = equipment.GetBracelet();
            }
            else if (itemSlot == "Ring")
            {
                // Get the ring from the Equipment script.
                equip = equipment.GetRing();
            }

            // IF there is an item,
            // ELSE there is not a item.
            if (equip != null)
            {
                // Grab the weapon.
                equipmentImage.sprite = equip.SpriteImage;
                // Set the color.
                equipmentImage.color = new Color(equip.R, equip.G, equip.B, equip.A);
            }
            else
            {
                // Set the color.
                equipmentImage.color = new Color(0f, 0f, 0f, 0f);
            }
        }
示例#2
0
        void Update()
        {
            // Load stats from bonus stats, default stats and items.
            LoadStatsFromItems();
            // Make the player look at the NPC it is interacting with.
            PlayerLookDirection();
            // IF the InteractionKey is the same as the AttackKey. (In this case, interaction has a higher priority than attacking.)
            if (InteractionKey == AttackKey)
            {
                // IF we pressed the Interaction Key.
                if (Input.GetKeyDown(InteractionKey))
                {
                    // IF we are close enough to an Action Key Dialogue component.
                    if (DialogueInteraction())
                    {
                        // Create the dialogue with the closest GameObject with an Action Key Dialogue.
                        ClosestAKD.CreateDialogue();
                        // This is what we are focusing on now so lets return.
                        return;
                    }
                    // IF there is an Animator on the player AND we actually have a weapon to attack with.
                    if (CharacterAnimator != null && equipment.GetWeapon() != null)
                    {
                        // ATTACK!!!
                        Attack("IsAttacking", AttackSound);
                    }
                    return;
                }
            }

            // IF we pressed the Attack Key.
            if (Input.GetKeyDown(AttackKey))
            {
                // IF there is an Animator on the player AND we actually have a weapon to attack with.
                if (CharacterAnimator != null && equipment.GetWeapon() != null)
                {
                    // ATTACK!!!
                    Attack("IsAttacking", AttackSound);
                }
            }
        }
        // Purpose of this script is to just set the GameObject's Sprite Renderer to our currently equipped weapon sprite.
        override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            // Referencing to make code easier to read.
            Character_Manager charManager    = animator.GetComponentInParent <Character_Manager> ();
            Equipment         charEquipment  = charManager.characterEquipment;
            SpriteRenderer    weaponRenderer = charManager.meleeWeapon.GetComponent <SpriteRenderer> ();
            Item weapon = charEquipment.GetWeapon();

            // Let's set the weapon sprite to look like our currently equipped weapon.
            weaponRenderer.sprite = weapon.SpriteImage;
            weaponRenderer.color  = new Color(weapon.R, weapon.B, weapon.G, weapon.A);
        }
示例#4
0
        void OnEnable()
        {
            // Get the Equipment script.
            Equipment equipment = Character_Manager.GetPlayerManager().GetComponentInChildren <Equipment> ();

            // Get the Sprite Renderer of the player.
            playerRenderer = Character_Manager.GetPlayer().GetComponent <SpriteRenderer> ();
            // Get the Weapon the player has.
            Item weapon = equipment.GetWeapon();

            // Get the sprite renderer of the this weapon.
            weaponRenderer = GetComponent <SpriteRenderer> ();
            // Get the Sprite Image of the weapon and set it to this GameObject's Sprite.
            weaponRenderer.sprite = weapon.SpriteImage;
            // Set the coloring of the Sprite renderer.
            weaponRenderer.color = new Color(weapon.R, weapon.G, weapon.B, weapon.A);
        }
示例#5
0
        void OnEnable()
        {
            // Get the Equipment script.
            Equipment equipment = Character_Manager.GetPlayerManager().GetComponentInChildren <Equipment> ();

            // Get the Sprite Renderer of the player.
            playerRenderer = Character_Manager.GetPlayer().GetComponent <SpriteRenderer> ();
            // Get the Weapon the player has.
            Item weapon = equipment.GetWeapon();

            // Get the sprite renderer of the this weapon.
            weaponRenderer = GetComponent <SpriteRenderer> ();
            if (weapon != null)
            {
                weaponRenderer.sprite = weapon.SpriteImage;
                weaponRenderer.color  = new Color(weapon.R, weapon.G, weapon.B, weapon.A);
            }
        }
示例#6
0
        void OnTriggerEnter2D(Collider2D coll)
        {
            // Whatever is colliding with us, let us check for the player.
            // IF the colliding GameObject has a Character Manager.
            if (coll.GetComponentInParent <Character_Manager> () == null)
            {
                // We leave as the only thing that can destroy environmental things will be the player.
                return;
            }
            // IF our Character is a Hero/Player.
            if (coll.GetComponentInParent <Character_Manager> ().characterType != CharacterType.Hero)
            {
                // We leave as the only things we want to destroy the environment is the player.
            }
            // A Character exists so lets get the main parent incase we need to traverse downward to find other scripts/components.
            Character_Manager characterManager = coll.GetComponentInParent <Character_Manager> ();
            // So now that we have a Player_Manager lets scope down the children and find the Equipment script.
            Equipment equipment = characterManager.GetComponentInChildren <Equipment> ();
            // Lets get the current weapon's subType we are wielding.
            string subType = equipment.GetWeapon().SubType;

            // Loop the amount of times we have subTypes.
            for (int k = 0; k < subTypesThatDestroy.Length; k++)
            {
                // IF we have a matching subTypeThatDestroy and subType.
                if (subTypesThatDestroy [k] == subType)
                {
                    // Reduce the numberOfHits (really this is just a simulation of HP in a nutshell but not really health per say).
                    // IF you didnt want to do just flat amount of hits you can always set up a higher variable for numberOfHits and apply the damage the player has in their Character_Stats to apply damage here.
                    // Normally though these type of destroyables are # of flat hits then they go bye bye.  You can also do flat amounts and base the damage done to these destroyables based on the "Rarity" or "Damage" of the item,
                    // so like :
                    // int rarity = GetIntBasedOnRarity(equipment.GetWeapon().Rarity) // There isnt a method GetIntBasedOnRarity() but you get the idea that Common = 1, Rare = 2, Epic = 3, etc.
                    // numberOfHits -= rarity;
                    // or
                    // numberOfHits -= equipment.GetWeapon().Damage;  // Remember we labeled the SubType so if you wanted to set damage to this item and not have it effect other types we can.

                    // Reduce the number of hits.
                    numberOfHits -= 1;
                    // IF numberOfHits is less than or equal to zero.
                    // ELSE we still have numberOfHits left.
                    if (numberOfHits <= 0)
                    {
                        // Loop the amount of times we have locations to spawn our destroy effects.
                        for (int i = 0; i < afterDestroyEffectLocations.Length; i++)
                        {
                            // Create our Destroy Effect at one of our locations specified.
                            Instantiate(afterDestroyEffects, afterDestroyEffectLocations [i].transform.position, Quaternion.identity);
                        }
                        // Check and see if there is a State_Handler script.
                        Grid_Helper.helper.CheckState(isPlaced, gameObject);
                    }
                    else
                    {
                        // We are not getting destroyed but since we are taking "damage" we need to display to the player that something is happening to this GameObject.
                        // If not the player can swing a sword/shovel/axe on a bush/dirt hole/tree and with no indicator that player will probably not try it again which can result in bad experience for the player.
                        // Now, there are MANY ways to handle this, you can run a coroutine and alter the colors to show contact that something is happening OR you can spawn like "poof" leaves/rubble/wood chippings/clouds.
                        // What we do in the demo is we take the "poof" effect and leave the variable hitEffects for this as I have created sprites for this purpose.  IF you are lacking sprites to display this effect I would recommend using the color effect.

                        // Loop the amount of times we have locations to spawn our effects.
                        for (int i = 0; i < hitEffectLocations.Length; i++)
                        {
                            // Create our Effect at one of our locations specified.
                            Instantiate(hitEffects, hitEffectLocations [i].transform.position, Quaternion.identity);
                        }
                    }
                    // We found a match for our SubType so it cannot match with anything else.
                    return;
                }
            }
        }
示例#7
0
        /// <summary>
        /// Showing our tooltip.
        /// </summary>
        public void OnPointerEnter(PointerEventData data)
        {
            //// DEALING WITH A PRESET BAR ////

            // IF we are dealing with a weapon,
            // ELSE IF we are dealing with armour,
            // ELSE IF if you want to add more.
            if (weaponOnly)
            {
                // Get the equipment that is on our player.
                Equipment charEquipment = Character_Helper.GetPlayerManager().GetComponentInChildren <Character_Manager> ().characterEquipment;
                // IF we don't have a weapon.
                if (charEquipment.GetWeapon() == null)
                {
                    // We leave.
                    return;
                }
                // Since we have a weapon we can now display our tooltip.
                Grid_Helper.tooltip.ActivateItemTooltip(charEquipment.GetWeapon(), transform.parent.gameObject);
                // We leave.
                return;
            }
            else if (armourOnly)
            {
                // Get the equipment that is on our player.
                Equipment charEquipment = Character_Helper.GetPlayerManager().GetComponentInChildren <Character_Manager> ().characterEquipment;
                // IF we don't have armour.
                if (charEquipment.GetArmour() == null)
                {
                    // We leave.
                    return;
                }
                // Since we have armour we can now display our tooltip.
                Grid_Helper.tooltip.ActivateItemTooltip(charEquipment.GetArmour(), transform.parent.gameObject);
                // We leave.
                return;
            }
            else if (helmetOnly)
            {
                // Get the equipment that is on our player.
                Equipment charEquipment = Character_Helper.GetPlayerManager().GetComponentInChildren <Character_Manager> ().characterEquipment;
                // IF we don't have helmet.
                if (charEquipment.GetHelmet() == null)
                {
                    // We leave.
                    return;
                }
                // Since we have a helmet we can now display our tooltip.
                Grid_Helper.tooltip.ActivateItemTooltip(charEquipment.GetHelmet(), transform.parent.gameObject);
                // We leave.
                return;
            }
            //// END OF DEALING WITH A PRESET BAR ////


            // IF we have a tooltip.
            if (Grid_Helper.tooltip != null)
            {
                // IF there is an item in this action bar,
                // ELSE IF there is a skill in this action bar.
                if (itemBar != null)
                {
                    // Show the tooltip.
                    Grid_Helper.tooltip.ActivateItemTooltip(itemBar, transform.parent.gameObject);
                }
            }
        }