// Only gets called if we have IAttack
        private void Hunt()
        {
            float attackRange     = attackComp.AttackRange;
            float halfAttackRange = attackRange / 2;

            Bounds  attackBoundSize = new Bounds(Vector3.zero, new Vector3(halfAttackRange, halfAttackRange, 0f));
            Vector3 huntTargetPos3D = huntTarget.ConstValue.transform.position;
            Vector2 huntTargetPos   = new Vector2(huntTargetPos3D.x, huntTargetPos3D.y);

            Vector3 dirToTarget3D = huntTargetPos3D - transform.position;
            Vector2 dirToTarget   = new Vector2(dirToTarget3D.x, dirToTarget3D.y);

            /*
             * Vector2 lowerPoint = huntTargetPos + Vector2.down * halfAttackRange;
             * Vector2 upperPoint = huntTargetPos + Vector2.up * halfAttackRange;
             * Vector2 leftPoint = huntTargetPos + Vector2.left * halfAttackRange;
             * Vector2 rightPoint = huntTargetPos + Vector2.right * halfAttackRange;
             */


            if ((dirToTarget).magnitude > attackRange)
            {
                walkComp.Walk(dirToTarget);
            }
            else
            {
                walkComp.Walk(Vector2.zero);

                if (Time.time > attackResetTime)
                {
                    attackComp.Attack(dirToTarget);
                    attackResetTime = attackCooldown + Time.time;
                }
            }
        }
        private void Meander()
        {
            if (Time.time > meanderStepEndTime)
            {
                ChooseNewMeanderDirection();
            }

            walkComp?.Walk(meanderDirection);
        }
        private void Update()
        {
            Vector2 inputDir = new Vector2(Input.GetAxis(hAxisName), Input.GetAxis(vAxisName));

            walkComp?.Walk(inputDir);

            if (Input.GetButtonDown(attackButtonName))
            {
                attackComp?.Attack();
            }
        }
Exemple #4
0
    void Act(GameObject animal)
    {
        switch (input)
        {
        case InputType.LMB:
        {
            ISpeak speak = animal.GetComponent <ISpeak>();
            if (speak != null)
            {
                speak.Speak();
                speakCount++;
            }
            break;
        }

        case InputType.RMB:
        {
            IWalk walk = animal.GetComponent <IWalk>();
            if (walk != null)
            {
                walk.Walk();
                walkCount++;
            }
            break;
        }

        case InputType.Space:
        {
            ISwim swim = animal.GetComponent <ISwim>();
            if (swim != null)
            {
                swim.Swim();
                swimCount++;
            }
            break;
        }

        case InputType.I:
        {
            IID id = animal.GetComponent <IID>();

            if (id != null)
            {
                id.Identify();
            }

            break;
        }

        default: break;
        }
    }
Exemple #5
0
 static void InterfaceTest()
 {
     Animal[] anims = new Animal[] { new Cat(), new Fish(), new Bird() };
     foreach (var item in anims)
     {
         //让会走路的走路
         IWalk iWalk = item as IWalk;
         if (iWalk != null)
         {
             item.Print();
             iWalk.Walk();
         }
     }
 }
Exemple #6
0
 public void MakeWalk()
 {
     _walk.Walk();
 }
Exemple #7
0
 virtual public void WatchW(IWalk an)
 {
     Console.Write($"{this.GetType().Name} is watching how ");
     an.Walk();
 }
Exemple #8
0
        // public void Show(MyDog a)
        // {
        //     a.Walk();
        // }
        //
        // public void Show(MyCat b)
        // {
        //     b.Walk();
        // }

        public void Show(IWalk w)
        {
            w.Walk();
        }
Exemple #9
0
 public virtual void WPropFunc()
 {
     _walk.Walk();
 }
Exemple #10
0
 public virtual void MakeWalk()
 {
     _walk.Walk();
 }
Exemple #11
0
 public void Walk()
 {
     Console.WriteLine("What about Walking?");
     _walkBehaviour.Walk();
     Console.WriteLine();
 }
Exemple #12
0
 public void Walk()
 {
     _walk.Walk();
 }