示例#1
0
文件: Enemy.cs 项目: tdcoish/JAM_MLS
    // If you aren't attacking, then you can do something cool, like pause and swipe at the player
    private void HandleAttacking()
    {
        if (!_Attacking && _CanAttack)
        {
            if (Vector2.Distance(_PlayerReference.transform.position, transform.position) < _DistanceToAttack)
            {
                _Attacking = true;

                // Play Animation
                // Spawn collision2d to check for player hit.
                // do other things I'm sure.
                // Integrate with the Weapon System Carlos wrote.
                _WH.Attack(0, transform.rotation);

                // play different sound if melee or ranged.
                if (_MeleeType)
                {
                    AkSoundEngine.PostEvent("Play_Sword_Swings", gameObject);
                }
                else
                {
                    AkSoundEngine.PostEvent("Play_Throw", gameObject);
                }

                // After x seconds, you can attack again.
                Invoke("RecoverSwipe", _TimeBetweenAttacks);
            }
        }
    }
示例#2
0
    // Some of this code is duplicated in Crosshairs.cs. Perhaps give us a reference to the crosshairs, and just aim towards that.
    // Also, obviously there's going to be some complicated logic here, Carlos is working on that. this is just for testing.
    private void HandleFiring()
    {
        bool lmb = Input.GetMouseButton(0);
        bool rmb = Input.GetMouseButton(1);

        _Crosshair.SetShooting(lmb | rmb);

        // for animations
        _IsFiring = lmb | rmb;

        if (Input.GetMouseButton(0))
        {
            // On first frame of state change, play audio.
            if (!_IsFiringMG)
            {
                AkSoundEngine.PostEvent("Play_MachineGun", gameObject);
            }
            _IsFiringMG = true;

            _WH.Attack(0, transform.rotation);
        }
        else
        {
            if (_IsFiringMG)
            {
                AkSoundEngine.PostEvent("Stop_MachineGun", gameObject);
            }
            _IsFiringMG = false;
        }

        // Now do shotgun.
        if (Input.GetMouseButtonDown(1))
        {
            if (!_IsFiringShotty)
            {
                AkSoundEngine.PostEvent("Play_Shotgun", gameObject);
            }
            _IsFiringShotty = true;

            _WH.Attack(1, transform.rotation);
        }
        else
        {
            _IsFiringShotty = false;
        }
    }