Ejemplo n.º 1
0
    /// <summary>
    /// Method to swing the sword
    /// </summary>
    public void Swing()
    {
        // reset the time since last swing
        sinceLastSwing = 0;
        // turn towards the enemy first *** will be the closest enemy ***
        if (closestEnemy != null && closestEnemy != gm.gameObject)
        {
            transform.LookAt(closestEnemy.transform);

            //Stops the player from rotating when hitting a bolt
            transform.rotation = new Quaternion(0, transform.rotation.y, 0, transform.rotation.w);
        }
        // make sure there is a closest enemy
        if (closestEnemy != null)
        {
            // get distance to closest enemy
            float distance = Vector3.Distance(this.transform.position, closestEnemy.transform.position);
            // if the distance is instead the hit radius we have set for the player
            if (distance <= hitDistance && closestEnemy != gm.gameObject)
            {
                // enemy is in range, good job player, kill the enemy (or do damage at least)
                closestEnemy.GetComponent <Enemy>().health -= 1;
                // get the distance difference between the player's range and how close the enemy was
                // *** Add the 1 for compensation since we'll round down, so a 9.1 is really a 10.1 which will be a 10
                float distanceDifference = (distance / hitDistance) * 10 + 1;
                distanceDifference -= (distanceDifference % 1f);
                gm.scoreAdded       = distanceDifference;
                // show our enviromental effects for it

                gm.EnvironmentEffect();

                /*
                 * // to test camera shake mechanics, every 50 points
                 * if (gm.score % 50 == 0)
                 * {
                 *  gm.Shake(0.05f, 0.002f);
                 * }
                 */
                //Debug.Log("Destroy: " + es.currentGameTime);
                ///anim.SetInteger("attack", animTracker);
                if (pac.InIdle == true)
                {
                    pac.SetState(1, true, false, false, false);
                }
                else
                {
                    pac.NextAttack();
                }
                // increase hit count and combo count if combo is enabled
                hitCount++;
                if (comboEnabled)
                {
                    comboCount++;
                }
            }
            // target out of player's range, call missed method
            else
            {
                Missed();
            }
        }
        // there are no enemies on the screen so miss anyway
        else
        {
            Missed();
        }
    }