Exemple #1
0
 private void Update()
 {
     switch (brain.OrgState)
     {
     case OrganismState.ATTACKING_FOOD: {
         if (target != null)
         {
             if ((transform.position - target.transform.position).sqrMagnitude < (attackRange * attackRange))
             {
                 // Attack logic working
                 //if (attackCoroutine == null) attackCoroutine = StartCoroutine(DealDamage());
                 //Destroy(target);
                 timeSinceLastAttacked += Time.deltaTime;
                 if (timeSinceLastAttacked > attackGap)
                 {
                     target.GetComponent <Damageable>().ReceiveDamage(attack);
                     timeSinceLastAttacked = 0f;
                 }
             }
             else
             {
                 //if (attackCoroutine != null) StopCoroutine(attackCoroutine);
                 brain.OnTargetLeftAttackRange(target);
             }
         }
         else
         {
             Debug.Log("got here");
             brain.OrgState = OrganismState.IDLE;
         }
         break;
     }
     }
 }