コード例 #1
0
ファイル: ItemWeaponMelee.cs プロジェクト: mengtest/2DRPG
 public ItemWeaponMelee()
     : base()
 {
     itemType = ItemTypes.MeleeWeapon;
     meleeWeaponType = MeleeWeaponTypes.Sword;
     damage = new Combat.DamageInfo();
 }
コード例 #2
0
 public ItemWeaponMelee()
     : base()
 {
     itemType        = ItemTypes.MeleeWeapon;
     meleeWeaponType = MeleeWeaponTypes.Sword;
     damage          = new Combat.DamageInfo();
 }
コード例 #3
0
        // Fired From Player Animation Event
        public void OnAttack()
        {
            if (weapon == null)
            {
                return;
            }

            if (weapon.itemType == Item.ItemTypes.MeleeWeapon)
            {
                // show a temp melee weapon spot
                if (tempWeapon != null)
                {
                    var ang = Vector2.Angle(player.mouseDirection, weaponArcPoint.transform.position);
                    Debug.Log(ang);
                    tempWeapon.SetActive(true);
                    tempWeapon.transform.position = (Vector2)weaponArcPoint.transform.position + player.mouseDirection;
                    //tempWeapon.transform.LookAt(player.mouseDirection);
                }

                var meleeWeapon = (ItemWeaponMelee)weapon;

                Combat.IHittable HittableObject;
                var rays = Physics2D.CircleCastAll((Vector2)weaponArcPoint.transform.position + player.mouseDirection, meleeWeapon.attackArc, player.mouseDirection, .01f, hittableLayers);
                if (rays != null)
                {
                    for (var i = 0; i < rays.Length; i++)
                    {
                        //Debug.Log("hit " + rays[i].collider.name);
                        HittableObject = (Combat.IHittable)rays[i].collider.gameObject.GetComponent(typeof(Combat.IHittable));

                        if (HittableObject != null && weapon != null)
                        {
                            Combat.DamageInfo damageInfo = meleeWeapon.damage.Copy();
                            // add damage bonuses from player stats here
                            HittableObject.Hit(new Combat.HitInfo(damageInfo, rays[i].collider.transform.position, false, Combat.HitInfo.HitSources.Player));
                        }
                    }
                }
            }
            else if (weapon.itemType == Item.ItemTypes.RangedWeapon)
            {
                var rangedWeapon = (ItemWeaponRanged)weapon;
                Instantiate(rangedWeapon.projectile, (Vector2)weaponHand.transform.position, Quaternion.identity);
            }
        }