コード例 #1
0
        //OnCantMove is called if Enemy attempts to move into a space occupied by a Player, it overrides the OnCantMove function of MovingObject
        //and takes a generic parameter T which we use to pass in the component we expect to encounter, in this case Player
        protected override void OnCantMove <T>(T component)
        {
            if (component is Player)
            {
                //Declare hitPlayer and set it to equal the encountered component.
                Player hitPlayer = component as Player;

                hitPlayer.DamagePlayer();
            }

            else if (component is Wall)
            {
                //Set hitWall to equal the component passed in as a parameter.
                Wall hitWall = component as Wall;

                //Call the DamageWall function of the Wall we are hitting.
                hitWall.DamageWall(wallDamage);
                Destroy(gameObject);
            }

            /*else if (component is Ally)
             * {
             *  Ally hitAlly = component as Ally;
             *
             *  hitAlly.DamageAlly(playerDamage);
             *  Destroy(gameObject);
             * }*/
            //Destroy(gameObject);

            //Call the RandomizeSfx function of SoundManager passing in the two audio clips to choose randomly between.
            SoundManager.instance.RandomizeSfx(attackSound1, attackSound2);
        }
コード例 #2
0
ファイル: Enemy.cs プロジェクト: kfilyk/Cryptonaut
        /*
         * public bool vision() {
         *      int a = 45;
         *      int sight = 10;
         *      if (Vector3.Angle(target.position - transform.position, transform.forward) < a)
         *      {
         *              if (Vector3.Distance(target.position, transform.position) < sight)
         *              {
         *                      return true;
         *              }
         *      }
         *      return false;
         * }
         */

        //OnCantMove is called if Enemy attempts to move into a space occupied by a Player, it overrides the OnCantMove function of MovingObject
        //and takes a generic parameter T which we use to pass in the component we expect to encounter, in this case Player
        protected override void OnCantMove <T> (T component)
        {
            //Declare hitPlayer and set it to equal the encountered component.
            Player hitPlayer = component as Player;

            //Call the LoseFood function of hitPlayer passing it playerDamage, the amount of foodpoints to be subtracted.
            //hitPlayer.LoseFood (playerDamage);
            hitPlayer.DamagePlayer(playerDamage);

            //Set the attack trigger of animator to trigger Enemy attack animation.
            animator.SetTrigger("enemyAttack");

            //Call the RandomizeSfx function of SoundManager passing in the two audio clips to choose randomly between.
            SoundManager.instance.RandomizeSfx(attackSound1, attackSound2);
        }