Beispiel #1
0
    private void Update()
    {
        switch (foxState)
        {
        case FoxState.GoingToCave:
            // Exit goint to cave state
            if (Vector3.Distance(caveTransform.position, transform.position) < inRange)
            {
                seek.target = null;

                // Start staying in cave state
                foxState          = FoxState.StayingInCave;
                stayedInCaveTimer = stayInCaveTime;
            }
            break;

        case FoxState.StayingInCave:
            stayedInCaveTimer -= Time.deltaTime;
            // Exit staying in cave
            if (stayedInCaveTimer <= 0)
            {
                // Start chasing state
                foxState          = FoxState.ChasingChicken;
                seek.target       = chickenController.GetRandomChicken().transform;
                eatenChickenCount = chickenCount;
            }
            break;
        }
    }
Beispiel #2
0
 private void OnTriggerEnter(Collider collider)
 {
     switch (foxState)
     {
     case FoxState.ChasingChicken:
         Chicken chicken = collider.gameObject.GetComponent <Chicken>();
         if (seek.target != null && chicken != null)
         {
             if (chicken.gameObject == seek.target.gameObject)
             {
                 chicken.GetEaten();
                 eatenChickenCount--;
                 // Exit chasing chicken state
                 if (eatenChickenCount == 0)
                 {
                     // Start cave seeking state
                     foxState    = FoxState.GoingToCave;
                     seek.target = caveTransform;
                 }
                 else
                 {
                     chicken = chickenController.GetRandomChicken();
                     if (chicken == null)
                     {
                         foxState    = FoxState.GoingToCave;
                         seek.target = caveTransform;
                         break;
                     }
                     seek.target = chicken.transform;
                 }
             }
         }
         break;
     }
 }
Beispiel #3
0
 void Update()
 {
     state = FoxState.Idle;
     if (Input.GetAxis("Horizontal") != 0)
     {
         state = FoxState.Run;
     }
     if (IsGrounded == false)
     {
         state = FoxState.Jump;
     }
     PlayerMove();
     if (Input.GetKeyDown(KeyCode.LeftShift))
     {
         speed++;
     }
     if (Input.GetKeyUp(KeyCode.LeftShift))
     {
         speed = 1;
     }
     if (Input.GetKeyDown(KeyCode.F))
     {
         if (mana_count > 0)
         {
             if (fireball_count > 0)
             {
                 Instantiate(fireball, new Vector3(transform.position.x, transform.position.y, transform.position.z), Quaternion.identity);
                 fireball_count--;
                 mana_count = mana_count - 2;
             }
         }
     }
 }